func ExampleParseString() { tokens := lexer.ParseString("int main (void) { ; }") for i, tok := range tokens { fmt.Printf("token %d: %v\n", i, tok) } // Output: // token 0: token.Token{Kind: token.Ident, Val: "int", Pos: 0} // token 1: token.Token{Kind: token.Ident, Val: "main", Pos: 4} // token 2: token.Token{Kind: token.Lparen, Val: "(", Pos: 9} // token 3: token.Token{Kind: token.Ident, Val: "void", Pos: 10} // token 4: token.Token{Kind: token.Rparen, Val: ")", Pos: 14} // token 5: token.Token{Kind: token.Lbrace, Val: "{", Pos: 16} // token 6: token.Token{Kind: token.Semicolon, Val: ";", Pos: 18} // token 7: token.Token{Kind: token.Rbrace, Val: "}", Pos: 20} // token 8: token.Token{Kind: token.EOF, Val: "", Pos: 21} }
// NewFromBytes returns a new scanner lexing from input. func NewFromBytes(input []byte) Scanner { toks := lexer.ParseString(string(input)) return &scanner{toks: toks} }
// NewFromString returns a new scanner lexing from input. func NewFromString(input string) Scanner { toks := lexer.ParseString(input) return &scanner{toks: toks} }