antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
16.96k stars 3.26k forks source link

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

Open udiedrichsen opened 11 months ago

udiedrichsen commented 11 months ago

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 commented 11 months ago

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

ryanhanks-bestow commented 8 months ago

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