github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/regexp/syntax/prog.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package syntax 6 7 // Progはコンパイルされた正規表現プログラムです。 8 type Prog struct { 9 Inst []Inst 10 Start int 11 NumCap int 12 } 13 14 // InstOpは命令のオペコードです。 15 type InstOp uint8 16 17 const ( 18 InstAlt InstOp = iota 19 InstAltMatch 20 InstCapture 21 InstEmptyWidth 22 InstMatch 23 InstFail 24 InstNop 25 InstRune 26 InstRune1 27 InstRuneAny 28 InstRuneAnyNotNL 29 ) 30 31 func (i InstOp) String() string 32 33 // EmptyOpは、ゼロ幅アサーションの種類または混合を指定します。 34 type EmptyOp uint8 35 36 const ( 37 EmptyBeginLine EmptyOp = 1 << iota 38 EmptyEndLine 39 EmptyBeginText 40 EmptyEndText 41 EmptyWordBoundary 42 EmptyNoWordBoundary 43 ) 44 45 // EmptyOpContextは、r1とr2のルーンの間の位置で満たされる 46 // ゼロ幅のアサーションを返します。 47 // r1 == -1を渡すと、位置がテキストの先頭にあることを示します。 48 // r2 == -1を渡すと、位置がテキストの末尾にあることを示します。 49 func EmptyOpContext(r1, r2 rune) EmptyOp 50 51 // IsWordCharは、\bおよび\Bゼロ幅のアサーションの評価中にrが「単語文字」と見なされるかどうかを報告します。 52 // これらのアサーションはASCIIのみです:単語文字は[A-Za-z0-9_]です。 53 func IsWordChar(r rune) bool 54 55 // Instは正規表現プログラム内の単一の命令です。 56 type Inst struct { 57 Op InstOp 58 Out uint32 59 Arg uint32 60 Rune []rune 61 } 62 63 func (p *Prog) String() string 64 65 // Prefix は正規表現のすべての一致した結果が始まるリテラル文字列を返します。もし Prefix が完全な一致である場合、Complete は true になります。 66 func (p *Prog) Prefix() (prefix string, complete bool) 67 68 // StartCondは、どのマッチにおいても真である必要がある先頭の空幅条件を返します。 69 // マッチが不可能な場合は、^EmptyOp(0)を返します。 70 func (p *Prog) StartCond() EmptyOp 71 72 // MatchRune は指定した r に instruction が一致し、それを消費するかどうかを報告します。 73 // i.Op == [InstRune] の場合にのみ呼び出すべきです。 74 func (i *Inst) MatchRune(r rune) bool 75 76 // MatchRunePosは、命令がrと一致しているかどうか(そして消費するかどうか)を確認します。 77 // そうであれば、MatchRunePosは一致するルーンのペアのインデックスを返します 78 // (または、len(i.Rune) == 1の場合、ルーンの単一要素)。 79 // 一致しない場合、MatchRunePosは-1を返します。 80 // MatchRunePosは、i.Op == [InstRune] の場合のみ呼び出す必要があります。 81 func (i *Inst) MatchRunePos(r rune) int 82 83 // MatchEmptyWidthは、runesの前と後の間に空の文字列が 84 // マッチしているかどうかを報告します。 85 // i.Op == [InstEmptyWidth] の場合にのみ呼び出すべきです。 86 func (i *Inst) MatchEmptyWidth(before rune, after rune) bool 87 88 func (i *Inst) String() string