Skip to content

Error "undefined: GetInvokingContext" for Go target #2826

@dmlambea

Description

@dmlambea

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions