antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

Dart code generater generates type errors for dart3 which can easy fixed

Open udiedrichsen opened this issue 2 years ago • 2 comments

I tried to build a dart package to parse Prisma Orm file. But this problems happens also on your hello grammar file:

// Define a grammar called Hello
grammar Hello;
r  : 'hello' ID ;         // match keyword hello followed by an identifier
ID : [a-z]+ ;             // match lower-case identifiers
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
antlr4 -Dlanguage=Dart Hello.g4 -o lib/hello  

Used versions ANTLR Parser Generator Version 4.13.1 Dart SDK version: 3.1.3 (stable) (Tue Sep 26 14:25:13 2023 +0000) on "macos_arm64"

The HelloParser.dart file contains a lot of warnings and an some error: The argument type 'dynamic' can't be assigned to the parameter type 'ParserRuleContext'.

dynamic _localctx = HelloFileContext(context, state);

this can be fixed by generating:

final _localctx = HelloFileContext(context, state);

udiedrichsen avatar Oct 14 '23 12:10 udiedrichsen

I made a quick fix for this: https://github.com/antlr/antlr4/compare/dev...udiedrichsen:antlr4:dev

udiedrichsen avatar Oct 14 '23 12:10 udiedrichsen

I also ran into this. Thanks for the patch @udiedrichsen

ryanhanks-bestow avatar Dec 22 '23 08:12 ryanhanks-bestow