grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

golang parse python3 failed

Open kayguo opened this issue 1 year ago • 1 comments
trafficstars

https://github.com/antlr/grammars-v4/blob/master/python/python3/Go/python3_lexer_base.go

parse fail : we will lost the first token

we can fix it after "next := l.BaseLexer.NextToken()" : add l.tokens ,like this: if len(l.tokens) != 0 && l.tokens[len(l.tokens)-1] != next { l.tokens = append(l.tokens, next) }

kayguo avatar Mar 01 '24 09:03 kayguo

The suggested change would cause a significant deviation from all the other sources, creating a maintenance problem.

The main problems, which are multiple, are described here. https://github.com/antlr/antlr4/issues/4342 OO is not available in Go. Fine. But, one can work around this by implementing it explicitly using structs and pointers to base class objects. I implemented things like this over 30 years ago in C. I know it can be done. The Go target runtime tries to do the same, but it does not implement it correctly.

kaby76 avatar Mar 01 '24 12:03 kaby76