Source File
prog.go
Belonging Package
regexp/syntax
package syntax
import (
)
type InstOp uint8
const (
InstAlt InstOp = iota
InstAltMatch
InstCapture
InstEmptyWidth
InstMatch
InstFail
InstNop
InstRune
InstRune1
InstRuneAny
InstRuneAnyNotNL
)
var instOpNames = []string{
"InstAlt",
"InstAltMatch",
"InstCapture",
"InstEmptyWidth",
"InstMatch",
"InstFail",
"InstNop",
"InstRune",
"InstRune1",
"InstRuneAny",
"InstRuneAnyNotNL",
}
func ( InstOp) () string {
if uint() >= uint(len(instOpNames)) {
return ""
}
return instOpNames[]
}
type EmptyOp uint8
const (
EmptyBeginLine EmptyOp = 1 << iota
EmptyEndLine
EmptyBeginText
EmptyEndText
EmptyWordBoundary
EmptyNoWordBoundary
)
func (, rune) EmptyOp {
var EmptyOp = EmptyNoWordBoundary
var byte
switch {
case IsWordChar():
= 1
case == '\n':
|= EmptyBeginLine
case < 0:
|= EmptyBeginText | EmptyBeginLine
}
switch {
case IsWordChar():
^= 1
case == '\n':
|= EmptyEndLine
case < 0:
|= EmptyEndText | EmptyEndLine
}
if != 0 { // IsWordChar(r1) != IsWordChar(r2)
^= (EmptyWordBoundary | EmptyNoWordBoundary)
}
return
}
func ( *Inst) () InstOp {
:= .Op
switch {
case InstRune1, InstRuneAny, InstRuneAnyNotNL:
= InstRune
}
return
}
func ( *Inst) ( rune) bool {
return .MatchRunePos() != noMatch
}
:= [0]
if == {
return 0
}
if Flags(.Arg)&FoldCase != 0 {
for := unicode.SimpleFold(); != ; = unicode.SimpleFold() {
if == {
return 0
}
}
}
return noMatch
case 2:
if >= [0] && <= [1] {
return 0
}
return noMatch
func ( *Inst) ( rune, rune) bool {
switch EmptyOp(.Arg) {
case EmptyBeginLine:
return == '\n' || == -1
case EmptyEndLine:
return == '\n' || == -1
case EmptyBeginText:
return == -1
case EmptyEndText:
return == -1
case EmptyWordBoundary:
return IsWordChar() != IsWordChar()
case EmptyNoWordBoundary:
return IsWordChar() == IsWordChar()
}
panic("unknown empty width arg")
}
func ( *Inst) () string {
var strings.Builder
dumpInst(&, )
return .String()
}
func ( *strings.Builder, ...string) {
for , := range {
.WriteString()
}
}
func ( *strings.Builder, *Prog) {
for := range .Inst {
:= &.Inst[]
:= strconv.Itoa()
if len() < 3 {
.WriteString(" "[len():])
}
if == .Start {
+= "*"
}
bw(, , "\t")
dumpInst(, )
bw(, "\n")
}
}
func ( uint32) string {
return strconv.FormatUint(uint64(), 10)
}
func ( *strings.Builder, *Inst) {
switch .Op {
case InstAlt:
bw(, "alt -> ", u32(.Out), ", ", u32(.Arg))
case InstAltMatch:
bw(, "altmatch -> ", u32(.Out), ", ", u32(.Arg))
case InstCapture:
bw(, "cap ", u32(.Arg), " -> ", u32(.Out))
case InstEmptyWidth:
bw(, "empty ", u32(.Arg), " -> ", u32(.Out))
case InstMatch:
bw(, "match")
case InstFail:
bw(, "fail")
case InstNop:
bw(, "nop -> ", u32(.Out))
case InstRune:
bw(, "rune <nil>")
}
bw(, "rune ", strconv.QuoteToASCII(string(.Rune)))
if Flags(.Arg)&FoldCase != 0 {
bw(, "/i")
}
bw(, " -> ", u32(.Out))
case InstRune1:
bw(, "rune1 ", strconv.QuoteToASCII(string(.Rune)), " -> ", u32(.Out))
case InstRuneAny:
bw(, "any -> ", u32(.Out))
case InstRuneAnyNotNL:
bw(, "anynotnl -> ", u32(.Out))
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |