-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Description
Test.g4:
grammar Test;
itemList locals [ []string Items ]
: '<' item+ '>' EOF { fmt.Printf("Items in list: %v\n", $Items) }
;
item
: tkn='A' { $itemList::Items = append($itemList::Items, $tkn.GetText()) }
;
// Ignore whitespace in lexer
WhiteSpace: [ \r\n\t]+ -> skip;
Go code for testing:
package main
import (
"github.com/antlr/antlr4/runtime/Go/antlr"
"tester/parser"
)
type testListener struct {
*parser.BaseTestListener
}
func main() {
is := antlr.NewInputStream("< A A A >")
lexer := parser.NewTestLexer(is)
stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
p := parser.NewTestParser(stream)
antlr.ParseTreeWalkerDefault.Walk(&testListener{}, p.Start())
}
Go module descriptor for compiling the code above:
module tester
go 1.12
require github.com/antlr/antlr4 v0.0.0-20200503195918-621b933c7a7f
Generating the parser:
java -jar $PWD/antlr-4.8-complete.jar -Dlanguage=Go -o parser Test.g4
Running the code tester:
$ go run tester.go
# tester/parser
parser/test_parser.go:328:2: undefined: GetInvokingContext
Metadata
Metadata
Assignees
Labels
No labels