func t_match(program inst.InstSlice, text string, t *testing.T) { expected := []machines.Match{machines.Match{len(program) - 1, 0, 1, 1, 1, len(text), []byte(text)}} if expected[0].EndColumn == 0 { expected[0].EndColumn = 1 } i := 0 scan := machines.LexerEngine(program, []byte(text)) for tc, m, err, scan := scan(0); scan != nil; tc, m, err, scan = scan(tc) { t.Log("match", m) if err != nil { t.Error("error", err) } else if !m.Equals(&expected[i]) { t.Error(m, expected[i]) } i++ } if i != len(expected) { t.Error("unconsumed matches", expected[i:]) } }
func (self *Lexer) Scanner(text []byte) (*Scanner, error) { if self.program == nil || len(self.patterns) != len(self.matches) { err := self.Compile() if err != nil { return nil, err } } scan := machines.LexerEngine(self.program, text) // prevent the user from modifying the text under scan text_copy := make([]byte, len(text)) copy(text_copy, text) return &Scanner{ lexer: self, scan: scan, Text: text_copy, TC: 0, }, nil }