Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart2Paperr.g4 cannot parse the syntax tree of Dart language #4394

Open
sunpan1101 opened this issue Jan 24, 2025 · 1 comment
Open

Dart2Paperr.g4 cannot parse the syntax tree of Dart language #4394

sunpan1101 opened this issue Jan 24, 2025 · 1 comment

Comments

@sunpan1101
Copy link

I use https://github.com/antlr/grammars-v4/tree/master/dart2/Dart2Parser.g4 This file cannot obtain the parsed syntax tree. The following dart code cannot parse any syntax tree information. How can I solve this problem?
import 'dart:convert';
import 'dart:typed_data';
import 'package:pointycastle/export.dart';
class AESEncryption {
//The AES key must be 16, 24, or 32 bytes long (corresponding to AES-128, AES-192, or AES-256)
static final key = utf8.encode('your-32-byte-key-here'); // For example, a 32 byte key
}

@kaby76
Copy link
Contributor

kaby76 commented Jan 24, 2025

I have no idea what the problem is. It works fine for the CSharp target.

$ trgen -t CSharp
C:\msys64\home\Kenne\issues\g4-current\dart2
CSharp  Dart2Parser.g4 success 0.0488913
CSharp  Dart2Lexer.g4 success 0.0121311
Rendering template file from CSharp/MyParserInterpreter.cs to ./Generated-CSharp-quick/MyParserInterpreter.cs
Rendering template file from CSharp/Other.csproj to ./Generated-CSharp-quick/Other.csproj
Rendering template file from CSharp/st.build.ps1 to ./Generated-CSharp-quick/st.build.ps1
Rendering template file from CSharp/st.build.sh to ./Generated-CSharp-quick/st.build.sh
Rendering template file from CSharp/st.clean.ps1 to ./Generated-CSharp-quick/st.clean.ps1
Rendering template file from CSharp/st.clean.sh to ./Generated-CSharp-quick/st.clean.sh
Rendering template file from CSharp/st.Encodings.cs to ./Generated-CSharp-quick/st.Encodings.cs
Rendering template file from CSharp/st.ErrorListener.cs to ./Generated-CSharp-quick/st.ErrorListener.cs
Rendering template file from CSharp/st.makefile to ./Generated-CSharp-quick/st.makefile
Rendering template file from CSharp/st.MyParser.cs to ./Generated-CSharp-quick/st.MyParser.cs
Rendering template file from CSharp/st.perf.sh to ./Generated-CSharp-quick/st.perf.sh
Rendering template file from CSharp/st.ProfilingCommonTokenStream.cs to ./Generated-CSharp-quick/st.ProfilingCommonTokenStream.cs
Rendering template file from CSharp/st.run.ps1 to ./Generated-CSharp-quick/st.run.ps1
Rendering template file from CSharp/st.run.sh to ./Generated-CSharp-quick/st.run.sh
Rendering template file from CSharp/st.test-ambiguity.sh to ./Generated-CSharp-quick/st.test-ambiguity.sh
Rendering template file from CSharp/st.test-cover.sh to ./Generated-CSharp-quick/st.test-cover.sh
Rendering template file from CSharp/st.Test.cs to ./Generated-CSharp-quick/st.Test.cs
Rendering template file from CSharp/st.test.ps1 to ./Generated-CSharp-quick/st.test.ps1
Rendering template file from CSharp/st.test.sh to ./Generated-CSharp-quick/st.test.sh
Rendering template file from CSharp/Test.csproj.st to ./Generated-CSharp-quick/Test.csproj.st
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/x to ./Generated-CSharp-quick/x
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/readme.md to ./Generated-CSharp-quick/readme.md
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/desc.xml to ./Generated-CSharp-quick/desc.xml
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/Dart2Parser.g4 to ./Generated-CSharp-quick/Dart2Parser.g4
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/Dart2Lexer.g4 to ./Generated-CSharp-quick/Dart2Lexer.g4
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/CSharp/Dart2LexerBase.cs to ./Generated-CSharp-quick/Dart2LexerBase.cs
01/24-07:04:52 ~/issues/g4-current/dart2
$ cd Generated-CSharp-quick/
01/24-07:04:53 ~/issues/g4-current/dart2/Generated-CSharp-quick
$ make
bash build.sh
Restore complete (1.1s)

Build succeeded in 1.6s
Restore complete (1.2s)
  Test succeeded (4.7s) → bin\Debug\net8.0\Test.dll

Build succeeded in 6.8s

Workload updates are available. Run `dotnet workload list` for more information.
01/24-07:05:06 ~/issues/g4-current/dart2/Generated-CSharp-quick
$ ls
bin/               Dart2Lexer.tokens           desc.xml                perf.sh                        test.sh
build.ps1          Dart2LexerBase.cs           Encodings.cs            ProfilingCommonTokenStream.cs  test-ambiguity.sh
build.sh           Dart2Parser.cs              ErrorListener.cs        readme.md                      test-cover.sh
clean.ps1          Dart2Parser.g4              makefile                run.ps1                        x
clean.sh           Dart2Parser.interp          MyParser.cs             run.sh
Dart2Lexer.cs      Dart2Parser.tokens          MyParserInterpreter.cs  Test.cs
Dart2Lexer.g4      Dart2ParserBaseListener.cs  obj/                    Test.csproj
Dart2Lexer.interp  Dart2ParserListener.cs      Other.csproj            test.ps1
01/24-07:05:08 ~/issues/g4-current/dart2/Generated-CSharp-quick
$ ./bin/Debug/net8.0/Test.exe x
CSharp 0 x success 0.0767068
Total Time: 0.1428459
01/24-07:05:18 ~/issues/g4-current/dart2/Generated-CSharp-quick
$ trparse x | trtree
CSharp 0 x success 0.0800697
compilationUnit
├── libraryDeclaration
│   ├── importOrExport
│   │   └── libraryImport
│   │       ├── metadata
│   │       └── importSpecification
│   │           ├── IMPORT_
│   │           │   └── "import"
│   │           ├── configurableUri
│   │           │   └── uri
│   │           │       └── stringLiteral
│   │           │           └── singleLineString
│   │           │               ├── Attribute Skip Value ' '
│   │           │               └── SingleLineString
│   │           │                   └── "'dart:convert'"
│   │           └── SC
│   │               └── ";"
│   ├── importOrExport
│   │   └── libraryImport
│   │       ├── metadata
│   │       └── importSpecification
│   │           ├── Attribute Skip Value '\r\n'
│   │           ├── IMPORT_
│   │           │   └── "import"
│   │           ├── configurableUri
│   │           │   └── uri
│   │           │       └── stringLiteral
│   │           │           └── singleLineString
│   │           │               ├── Attribute Skip Value ' '
│   │           │               └── SingleLineString
│   │           │                   └── "'dart:typed_data'"
│   │           └── SC
│   │               └── ";"
│   ├── importOrExport
│   │   └── libraryImport
│   │       ├── metadata
│   │       └── importSpecification
│   │           ├── Attribute Skip Value '\r\n'
│   │           ├── IMPORT_
│   │           │   └── "import"
│   │           ├── configurableUri
│   │           │   └── uri
│   │           │       └── stringLiteral
│   │           │           └── singleLineString
│   │           │               ├── Attribute Skip Value ' '
│   │           │               └── SingleLineString
│   │           │                   └── "'package:pointycastle/export.dart'"
│   │           └── SC
│   │               └── ";"
│   ├── metadata
│   └── topLevelDeclaration
│       └── classDeclaration
│           ├── Attribute Skip Value '\r\n'
│           ├── CLASS_
│           │   └── "class"
│           ├── typeIdentifier
│           │   ├── Attribute Skip Value ' '
│           │   └── IDENTIFIER
│           │       └── "AESEncryption"
│           ├── Attribute Skip Value ' '
│           ├── OBC
│           │   └── "{"
│           ├── metadata
│           ├── classMemberDeclaration
│           │   ├── declaration
│           │   │   ├── Attribute Skip Value '\r\n//The AES key must be 16, 24, or 32 bytes long (corresponding to AES-128, AES-192, or AES-256)\r\n'
│           │   │   ├── STATIC_
│           │   │   │   └── "static"
│           │   │   ├── Attribute Skip Value ' '
│           │   │   ├── FINAL_
│           │   │   │   └── "final"
│           │   │   └── staticFinalDeclarationList
│           │   │       └── staticFinalDeclaration
│           │   │           ├── identifier
│           │   │           │   ├── Attribute Skip Value ' '
│           │   │           │   └── IDENTIFIER
│           │   │           │       └── "key"
│           │   │           ├── Attribute Skip Value ' '
│           │   │           ├── EQ
│           │   │           │   └── "="
│           │   │           └── expr
│           │   │               └── conditionalExpression
│           │   │                   └── ifNullExpression
│           │   │                       └── logicalOrExpression
│           │   │                           └── logicalAndExpression
│           │   │                               └── equalityExpression
│           │   │                                   └── relationalExpression
│           │   │                                       └── bitwiseOrExpression
│           │   │                                           └── bitwiseXorExpression
│           │   │                                               └── bitwiseAndExpression
│           │   │                                                   └── shiftExpression
│           │   │                                                       └── additiveExpression
│           │   │                                                           └── multiplicativeExpression
│           │   │                                                               └── unaryExpression
│           │   │                                                                   └── postfixExpression
│           │   │                                                                       ├── primary
│           │   │                                                                       │   └── identifier
│           │   │                                                                       │       ├── Attribute Skip Value ' '
│           │   │                                                                       │       └── IDENTIFIER
│           │   │                                                                       │           └── "utf8"
│           │   │                                                                       ├── selector
│           │   │                                                                       │   └── assignableSelector
│           │   │                                                                       │       └── unconditionalAssignableSelector
│           │   │                                                                       │           ├── D
│           │   │                                                                       │           │   └── "."
│           │   │                                                                       │           └── identifier
│           │   │                                                                       │               └── IDENTIFIER
│           │   │                                                                       │                   └── "encode"
│           │   │                                                                       └── selector
│           │   │                                                                           └── argumentPart
│           │   │                                                                               └── arguments
│           │   │                                                                                   ├── OP
│           │   │                                                                                   │   └── "("
│           │   │                                                                                   ├── argumentList
│           │   │                                                                                   │   └── expressionList
│           │   │                                                                                   │       └── expr
│           │   │                                                                                   │           └── conditionalExpression
│           │   │                                                                                   │               └── ifNullExpression
│           │   │                                                                                   │                   └── logicalOrExpression
│           │   │                                                                                   │                       └── logicalAndExpression
│           │   │                                                                                   │                           └── equalityExpression
│           │   │                                                                                   │                               └── relationalExpression
│           │   │                                                                                   │
   └── bitwiseOrExpression
│           │   │                                                                                   │
       └── bitwiseXorExpression
│           │   │                                                                                   │
           └── bitwiseAndExpression
│           │   │                                                                                   │
               └── shiftExpression
│           │   │                                                                                   │
                   └── additiveExpression
│           │   │                                                                                   │
                       └── multiplicativeExpression
│           │   │                                                                                   │
                           └── unaryExpression
│           │   │                                                                                   │
                               └── postfixExpression
│           │   │                                                                                   │
                                   └── primary
│           │   │                                                                                   │
                                       └── literal
│           │   │                                                                                   │
                                           └── stringLiteral
│           │   │                                                                                   │
                                               └── singleLineString
│           │   │                                                                                   │
                                                   └── SingleLineString
│           │   │                                                                                   │
                                                       └── "'your-32-byte-key-here'"
│           │   │                                                                                   └── CP
│           │   │                                                                                       └── ")"
│           │   └── SC
│           │       └── ";"
│           ├── Attribute Skip Value ' // For example, a 32 byte key\r\n'
│           └── CBC
│               └── "}"
└── EOF
    └── ""


01/24-07:05:31 ~/issues/g4-current/dart2/Generated-CSharp-quick
$

For the Dart target, the grammar also works perfectly fine in generating a tree.

01/24-07:06:55 ~/issues/g4-current/dart2
$ trgen -t Dart
C:\msys64\home\Kenne\issues\g4-current\dart2
CSharp  Dart2Parser.g4 success 0.0466475
CSharp  Dart2Lexer.g4 success 0.0116998
Rendering template file from Dart/pubspec.yaml to ./Generated-Dart-quick/pubspec.yaml
Rendering template file from Dart/st.analysis_options.yaml to ./Generated-Dart-quick/st.analysis_options.yaml
Rendering template file from Dart/st.build.ps1 to ./Generated-Dart-quick/st.build.ps1
Rendering template file from Dart/st.build.sh to ./Generated-Dart-quick/st.build.sh
Rendering template file from Dart/st.clean.ps1 to ./Generated-Dart-quick/st.clean.ps1
Rendering template file from Dart/st.clean.sh to ./Generated-Dart-quick/st.clean.sh
Rendering template file from Dart/st.makefile to ./Generated-Dart-quick/st.makefile
Rendering template file from Dart/st.MyErrorListener.dart to ./Generated-Dart-quick/st.MyErrorListener.dart
Rendering template file from Dart/st.perf.sh to ./Generated-Dart-quick/st.perf.sh
Rendering template file from Dart/st.run.ps1 to ./Generated-Dart-quick/st.run.ps1
Rendering template file from Dart/st.run.sh to ./Generated-Dart-quick/st.run.sh
Rendering template file from Dart/st.Test.dart to ./Generated-Dart-quick/st.Test.dart
Rendering template file from Dart/st.test.ps1 to ./Generated-Dart-quick/st.test.ps1
Rendering template file from Dart/st.test.sh to ./Generated-Dart-quick/st.test.sh
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/x to ./Generated-Dart-quick/x
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/readme.md to ./Generated-Dart-quick/readme.md
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/desc.xml to ./Generated-Dart-quick/desc.xml
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/Dart2Parser.g4 to ./Generated-Dart-quick/Dart2Parser.g4
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/Dart2Lexer.g4 to ./Generated-Dart-quick/Dart2Lexer.g4
Rendering template file from C:/msys64/home/Kenne/issues/g4-current/dart2/Dart/Dart2LexerBase.dart to ./Generated-Dart-quick/Dart2LexerBase.dart
01/24-07:07:09 ~/issues/g4-current/dart2
$ cd Generated-Dart-quick/
01/24-07:07:13 ~/issues/g4-current/dart2/Generated-Dart-quick
$ make
bash build.sh
Resolving dependencies... (2.4s)
+ _fe_analyzer_shared 67.0.0 (79.0.0 available)
+ analyzer 6.4.1 (7.2.0 available)
+ antlr4 4.13.2
+ args 2.5.0 (2.6.0 available)
+ async 2.11.0 (2.12.0 available)
+ boolean_selector 2.1.2
+ collection 1.18.0 (1.19.1 available)
+ convert 3.1.1 (3.1.2 available)
+ coverage 1.8.0 (1.11.1 available)
+ crypto 3.0.3 (3.0.6 available)
+ file 7.0.1
+ frontend_server_client 4.0.0
+ glob 2.1.2 (2.1.3 available)
+ http_multi_server 3.2.2
+ http_parser 4.0.2 (4.1.2 available)
+ io 1.0.4 (1.0.5 available)
+ js 0.7.1
+ logging 1.2.0 (1.3.0 available)
+ matcher 0.12.16+1 (0.12.17 available)
+ meta 1.16.0
+ mime 1.0.6 (2.0.0 available)
+ node_preamble 2.0.2
+ package_config 2.1.0 (2.1.1 available)
+ path 1.9.0 (1.9.1 available)
+ pedantic 1.11.1 (discontinued replaced by lints)
+ pool 1.5.1
+ pub_semver 2.1.4 (2.1.5 available)
+ shelf 1.4.1 (1.4.2 available)
+ shelf_packages_handler 3.0.2
+ shelf_static 1.1.2 (1.1.3 available)
+ shelf_web_socket 2.0.0 (2.0.1 available)
+ source_map_stack_trace 2.1.1 (2.1.2 available)
+ source_maps 0.10.12 (0.10.13 available)
+ source_span 1.10.1
+ stack_trace 1.11.1 (1.12.1 available)
+ stream_channel 2.1.2 (2.1.4 available)
+ string_scanner 1.4.1
+ term_glyph 1.2.2
+ test 1.25.7 (1.25.14 available)
+ test_api 0.7.2 (0.7.4 available)
+ test_core 0.6.4 (0.6.8 available)
+ typed_data 1.3.2 (1.4.0 available)
+ vm_service 14.0.0 (15.0.0 available)
+ watcher 1.1.1
+ web 0.4.2 (1.1.0 available)
+ web_socket_channel 2.4.3 (3.0.2 available)
+ webkit_inspection_protocol 1.2.1
+ yaml 3.1.2 (3.1.3 available)
Changed 48 dependencies!
1 package is discontinued.
32 packages have newer versions incompatible with dependency constraints.
Try `dart pub outdated` for more information.
Generated: c:\msys64\home\kenne\issues\g4-current\dart2\generated-dart-quick\test.exe
01/24-07:07:28 ~/issues/g4-current/dart2/Generated-Dart-quick
$ ./
.dart_tool/ test.exe
01/24-07:07:28 ~/issues/g4-current/dart2/Generated-Dart-quick
$ ./test.exe x
Dart 0 x success 0.017
Total Time: 0.019
01/24-07:07:37 ~/issues/g4-current/dart2/Generated-Dart-quick
$ ./test.exe x -tree
(compilationUnit (libraryDeclaration (importOrExport (libraryImport metadata (importSpecification import (configurableUri (uri (stringLiteral (singleLineString 'dart:convert')))) ;))) (importOrExport (libraryImport metadata (importSpecification import (configurableUri (uri (stringLiteral (singleLineString 'dart:typed_data')))) ;))) (importOrExport (libraryImport metadata (importSpecification import (configurableUri (uri (stringLiteral (singleLineString 'package:pointycastle/export.dart')))) ;))) metadata (topLevelDeclaration (classDeclaration class (typeIdentifier AESEncryption) { metadata (classMemberDeclaration (declaration static final (staticFinalDeclarationList (staticFinalDeclaration (identifier key) = (expr (conditionalExpression (ifNullExpression (logicalOrExpression (logicalAndExpression (equalityExpression (relationalExpression (bitwiseOrExpression (bitwiseXorExpression (bitwiseAndExpression (shiftExpression (additiveExpression (multiplicativeExpression (unaryExpression (postfixExpression (primary (identifier utf8)) (selector (assignableSelector (unconditionalAssignableSelector . (identifier encode)))) (selector (argumentPart (arguments ( (argumentList (expressionList (expr (conditionalExpression (ifNullExpression (logicalOrExpression (logicalAndExpression (equalityExpression (relationalExpression (bitwiseOrExpression (bitwiseXorExpression (bitwiseAndExpression (shiftExpression (additiveExpression (multiplicativeExpression (unaryExpression (postfixExpression (primary (literal (stringLiteral (singleLineString 'your-32-byte-key-here'))))))))))))))))))))) )))))))))))))))))))))) ;) }))) <EOF>)
Dart 0 x success 0.017
Total Time: 0.019
01/24-07:07:41 ~/issues/g4-current/dart2/Generated-Dart-quick
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants