简体   繁体   中英

ANTLR4 Golang grammar file

I'm getting a warning while trying to create AST tree from golang code line 6:1 no viable alternative at input 'sMap, lMap map[int32]string\r\n\tif' The code I tried,

package dum
func mergeIntStrMap(map1 map[int32]string, map2 map[int32]string) string {

    var sMap, lMap map[int32]string
    return lMap
}

Grammar file I downloaded from [github] https://github.com/antlr/grammars-v4/blob/master/golang/ . Is there any issue in the grammar file or any fix for this. Used code to generate AST(python code),

from antlr4 import *
from GoParser import GoParser
from GoLexer import GoLexer
file = FileStream(f,encoding = 'utf-8')
lexer = GoLexer(file)
token = CommonTokenStream(lexer)
parse = GoParser(token)
trees = parse.sourceFile()

here GoParser and GoLexer files are generated from grammar file.

Thanks in Advance

You either changed something in the grammar file(s), or you did not implement GoParserBase.py correctly, because without changing anything, your example Go code is correctly parsed:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM