Source File
rematch.go
Belonging Package
github.com/google/licensecheck/internal/match
package match
import (
)
func ( reProg) ( *Dict) string {
var strings.Builder
:= .Words()
for , := range {
fmt.Fprintf(&, "%d\t", )
switch .op {
case instWord:
fmt.Fprintf(&, "word %s\n", [.arg])
case instAny:
fmt.Fprintf(&, "any\n")
case instAlt:
fmt.Fprintf(&, "alt %d\n", +1+int(.arg))
case instJump:
fmt.Fprintf(&, "jump %d\n", +1+int(.arg))
case instMatch:
fmt.Fprintf(&, "match %d\n", int(.arg))
case opWords:
for , := range .w {
.prog = append(.prog, reInst{op: instWord, arg: int32()})
.reduceCut()
}
if .endPattern {
.compileCuts()
}
case opConcat:
:= len(.sub)
if .endPattern {
for > 0 && canMatchEmpty(.sub[-1]) {
--
}
}
for , := range .sub {
.endPattern = >=
.()
}
case opQuest:
:= len(.prog)
.prog = append(.prog, reInst{op: instAlt})
:= .cut
:= .endPattern
.(.sub[0])
if {
.compileCuts()
}
.cut = .mergeCut(, .cut)
.prog[].arg = int32(len(.prog) - ( + 1))
case opAlternate:
:= .cut
:= .endPattern
var []reCut
var , []int
for , := range .sub {
if +1 < len(.sub) {
= append(, len(.prog))
.prog = append(.prog, reInst{op: instAlt})
}
.cut =
.endPattern =
.()
= .mergeCut(, .cut)
if +1 < len(.sub) {
= append(, len(.prog))
.prog = append(.prog, reInst{op: instJump})
}
}
.cut =
.compileCuts()
if .endPattern && .err == nil {
.err = fmt.Errorf("__%d__ wildcard with no required text following", .n)
}
:= len(.prog)
:= len(.prog) + int(.n)*2
for := int32(0); < .n; ++ {
.prog = append(.prog, reInst{op: instAlt, arg: int32( - (len(.prog) + 1))})
.prog = append(.prog, reInst{op: instAny})
}
if .n > 3 {
.cut = []reCut{{start: , trigger: 3}}
}
}
}
func ( *reCompile) () {
for , := range .cut {
.compileCut()
}
.cut = nil
}
func ( *reCompile) (, []reCut) []reCut {
if len() == 0 {
return
}
if len() == 0 {
return
}
var []reCut
= append(, ...)
= append(, ...)
sort.Slice(, func(, int) bool {
if [].start != [].start {
return [].start < [].start
}
return [].trigger > [].trigger
})
:= 0
for , := range {
if == 0 || [-1].start != .start {
[] =
++
}
}
return [:]
}
func ( reDFA) ( *Dict) string {
var strings.Builder
for := 0; < len(); {
fmt.Fprintf(&, "%d", )
:= []
++
if &1 != 0 {
fmt.Fprintf(&, " m%d", [])
++
}
:= >> 1
for ; > 0; -- {
:= WordID([])
:= [+1]
+= 2
var string
if == AnyWord {
= "*"
} else {
= .Words()[]
}
fmt.Fprintf(&, " %s:%d", , )
}
fmt.Fprintf(&, "\n")
}
return .String()
}
, := .stateAt()
if >= 0 {
=
=
}
if canMisspellJoin(, , ) {
=
++ // for have; loop will i++ again for have2
continue
}
if >= 0 {
=
=
}
=
continue
}
}
if canMisspell(, ) {
=
continue
}
}
return ,
}
=
}
if , := .stateAt(); >= 0 {
=
= len()
}
if := len(); TraceDFA > 0 && - >= TraceDFA {
:= - 10
if < 0 {
= 0
}
println("DFA ran out of input at «", [[-10].Lo:], "|", "EOF", "»\n")
}
return ,
}
func ( []int32) {
sort.Slice(, func(, int) bool {
return [] < []
})
}
func ( []WordID) {
sort.Slice(, func(, int) bool {
return [] < []
})
}
![]() |
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. |