Skip to content

Commit 5b3f1b7

Browse files
authored
[dart2] Add ports, readme.md, clean up testing (#3740)
* Fix for #3587 Add in changes from #3587 . The desc.xml has been changed to use globstar patterns for test files in latest version of Trash. * Add readme.md, update desc.xml to do quick sanity check for all but Java port. * Fix indentation. * Add Cpp port. * Add JavaScript port. * Add Python3 port. * Fix desc.xml. * Add Go port. Renamed "expression" to "expr" to avoid symbol conflict with Go target.
1 parent 661937c commit 5b3f1b7

16 files changed

+259
-52
lines changed

dart2/CSharp/Dart2LexerBase.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
public abstract class Dart2LexerBase : Lexer
77
{
8-
protected Dart2LexerBase(ICharStream input)
9-
: base(input)
10-
{
11-
}
8+
protected Dart2LexerBase(ICharStream input)
9+
: base(input)
10+
{
11+
}
1212

13-
public Dart2LexerBase(ICharStream input, TextWriter output, TextWriter errorOutput)
14-
: base(input, output, errorOutput) { }
13+
public Dart2LexerBase(ICharStream input, TextWriter output, TextWriter errorOutput)
14+
: base(input, output, errorOutput) { }
1515

16-
protected bool CheckNotOpenBrace()
17-
{
18-
return this.InputStream.LA(1) != '{';
19-
}
16+
protected bool CheckNotOpenBrace()
17+
{
18+
return this.InputStream.LA(1) != '{';
19+
}
2020
}

dart2/Cpp/Dart2LexerBase.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "antlr4-runtime.h"
2+
#include "Dart2LexerBase.h"
3+
#include "Dart2Lexer.h"
4+
5+
Dart2LexerBase::Dart2LexerBase(antlr4::CharStream * input) : antlr4::Lexer(input)
6+
{
7+
_input = input;
8+
}
9+
10+
bool Dart2LexerBase::CheckNotOpenBrace()
11+
{
12+
return this->_input->LA(1) != '{';
13+
}

dart2/Cpp/Dart2LexerBase.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
#include "antlr4-runtime.h"
3+
4+
class Dart2LexerBase : public antlr4::Lexer
5+
{
6+
public:
7+
Dart2LexerBase(antlr4::CharStream * input);
8+
bool CheckNotOpenBrace();
9+
};

dart2/Cpp/transformGrammar.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import sys, os, re, shutil
2+
from glob import glob
3+
from pathlib import Path
4+
5+
def main(argv):
6+
for file in glob("./*.g4"):
7+
fix(file)
8+
9+
def fix(file_path):
10+
print("Altering " + file_path)
11+
if not os.path.exists(file_path):
12+
print(f"Could not find file: {file_path}")
13+
sys.exit(1)
14+
parts = os.path.split(file_path)
15+
file_name = parts[-1]
16+
shutil.move(file_path, file_path + ".bak")
17+
input_file = open(file_path + ".bak",'r')
18+
output_file = open(file_path, 'w')
19+
for x in input_file:
20+
if '// Insert here @header for C++ lexer.' in x:
21+
x = x.replace('// Insert here @header for C++ lexer.', '@header {#include "Dart2LexerBase.h"}')
22+
if '// Insert here @header for C++ parser.' in x:
23+
x = x.replace('// Insert here @header for C++ parser.', '@header {#include "Dart2ParserBase.h"}')
24+
if 'this.' in x:
25+
x = x.replace('this.', 'this->')
26+
output_file.write(x)
27+
output_file.flush()
28+
29+
print("Writing ...")
30+
input_file.close()
31+
output_file.close()
32+
33+
if __name__ == '__main__':
34+
main(sys.argv)

dart2/Dart/Dart2LexerBase.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import 'package:antlr4/antlr4.dart';
44

55
abstract class Dart2LexerBase extends Lexer {
6-
Dart2LexerBase(CharStream input) : super(input);
7-
8-
bool CheckNotOpenBrace() => inputStream.LA(1) != "{".codeUnitAt(0);
6+
Dart2LexerBase(CharStream input) : super(input);
7+
bool CheckNotOpenBrace() => inputStream.LA(1) != "{".codeUnitAt(0);
98
}

dart2/Dart2Lexer.g4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ lexer grammar Dart2Lexer;
2727

2828
options { superClass=Dart2LexerBase; }
2929

30+
// Insert here @header for C++ lexer.
31+
3032
A: '&';
3133
AA: '&&';
3234
AE: '&=';
@@ -158,9 +160,9 @@ MULTI_LINE_COMMENT : '/*' ( MULTI_LINE_COMMENT | . )*? '*/' -> skip ;
158160
fragment EXPONENT : ( 'e' | 'E' ) ( '+' | '-' )? DIGIT+ ;
159161
fragment HEX_DIGIT : 'a' .. 'f' | 'A' .. 'F' | DIGIT ;
160162
fragment StringDQ : '"' StringContentDQ*? '"' ;
161-
fragment StringContentDQ : ~('\\' | '"' | '\n' | '\r' | '$') | '\\' ~('\n' | '\r') | StringDQ | '${' StringContentDQ*? '}' | '$' { CheckNotOpenBrace() }? ;
163+
fragment StringContentDQ : ~('\\' | '"' | '\n' | '\r' | '$') | '\\' ~('\n' | '\r') | StringDQ | '${' StringContentDQ*? '}' | '$' { this.CheckNotOpenBrace() }? ;
162164
fragment StringSQ : '\'' StringContentSQ*? '\'' ;
163-
fragment StringContentSQ : ~('\\' | '\'' | '\n' | '\r' | '$') | '\\' ~('\n' | '\r') | StringSQ | '${' StringContentSQ*? '}' | '$' { CheckNotOpenBrace() }? ;
165+
fragment StringContentSQ : ~('\\' | '\'' | '\n' | '\r' | '$') | '\\' ~('\n' | '\r') | StringSQ | '${' StringContentSQ*? '}' | '$' { this.CheckNotOpenBrace() }? ;
164166
fragment StringContentTDQ : ~('\\' | '"') | '"' ~'"' | '""' ~'"' ;
165167
fragment StringContentTSQ : '\'' ~'\'' | '\'\'' ~'\'' | . ;
166168
fragment ESCAPE_SEQUENCE : '\n' | '\r' | '\\f' | '\\b' | '\t' | '\\v' | '\\x' HEX_DIGIT HEX_DIGIT | '\\u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT | '\\u{' HEX_DIGIT_SEQUENCE '}' ;

dart2/Dart2Parser.g4

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ argumentList : namedArgument ( C namedArgument )* | expressionList ( C namedArgu
3333
argumentPart : typeArguments? arguments ;
3434
arguments : OP ( argumentList C? )? CP ;
3535
asOperator : AS_ ;
36-
assertion : ASSERT_ OP expression ( C expression )? C? CP ;
36+
assertion : ASSERT_ OP expr ( C expr )? C? CP ;
3737
assertStatement : assertion SC ;
3838
assignableExpression : primary assignableSelectorPart | SUPER_ unconditionalAssignableSelector | identifier ;
39-
assignableSelector : unconditionalAssignableSelector | QUD identifier | QU OB expression CB ;
39+
assignableSelector : unconditionalAssignableSelector | QUD identifier | QU OB expr CB ;
4040
assignableSelectorPart : selector* assignableSelector ;
4141
assignmentOperator : EQ | compoundAssignmentOperator ;
4242
awaitExpression : AWAIT_ unaryExpression ;
@@ -52,12 +52,12 @@ cascade : cascade DD cascadeSection | conditionalExpression ( QUDD | DD ) cascad
5252
cascadeAssignment : assignmentOperator expressionWithoutCascade ;
5353
cascadeSection : cascadeSelector cascadeSectionTail ;
5454
cascadeSectionTail : cascadeAssignment | selector* ( assignableSelector cascadeAssignment )? ;
55-
cascadeSelector : OB expression CB | identifier ;
55+
cascadeSelector : OB expr CB | identifier ;
5656
catchPart : CATCH_ OP identifier ( C identifier )? CP ;
5757
classDeclaration : ABSTRACT_? CLASS_ typeIdentifier typeParameters? superclass? interfaces? OBC ( metadata classMemberDeclaration )* CBC | ABSTRACT_? CLASS_ mixinApplicationClass ;
5858
classMemberDeclaration : declaration SC | methodSignature functionBody ;
5959
combinator : SHOW_ identifierList | HIDE_ identifierList ;
60-
compilationUnit: (libraryDeclaration | partDeclaration | expression | statement) EOF ;
60+
compilationUnit: (libraryDeclaration | partDeclaration | expr | statement) EOF ;
6161
compoundAssignmentOperator : STE | SE | SQSE | PE | PLE | ME | LTLTE | GT GT GT EQ | GT GT EQ | AE | CIRE | POE | QUQUEQ ;
6262
conditionalExpression : ifNullExpression ( QU expressionWithoutCascade CO expressionWithoutCascade )? ;
6363
configurableUri : uri configurationUri* ;
@@ -72,20 +72,20 @@ continueStatement : CONTINUE_ identifier? SC ;
7272
declaration :ABSTRACT_? ( EXTERNAL_ factoryConstructorSignature | EXTERNAL_ constantConstructorSignature | EXTERNAL_ constructorSignature | ( EXTERNAL_ STATIC_? )? getterSignature | ( EXTERNAL_ STATIC_? )? setterSignature | ( EXTERNAL_ STATIC_? )? functionSignature | EXTERNAL_? operatorSignature | STATIC_ CONST_ type? staticFinalDeclarationList | STATIC_ FINAL_ type? staticFinalDeclarationList | STATIC_ LATE_ FINAL_ type? initializedIdentifierList | STATIC_ LATE_? varOrType initializedIdentifierList | COVARIANT_ LATE_ FINAL_ type? identifierList | COVARIANT_ LATE_? varOrType initializedIdentifierList | LATE_? FINAL_ type? initializedIdentifierList | LATE_? varOrType initializedIdentifierList | redirectingFactoryConstructorSignature | constantConstructorSignature ( redirection | initializers )? | constructorSignature ( redirection | initializers )? );
7373
declaredIdentifier : COVARIANT_? finalConstVarOrType identifier ;
7474
defaultCase : label* DEFAULT_ CO statements ;
75-
defaultFormalParameter : normalFormalParameter ( EQ expression )? ;
76-
defaultNamedParameter : metadata REQUIRED_? normalFormalParameterNoMetadata ( ( EQ | CO ) expression )? ;
77-
doStatement : DO_ statement WHILE_ OP expression CP SC ;
75+
defaultFormalParameter : normalFormalParameter ( EQ expr )? ;
76+
defaultNamedParameter : metadata REQUIRED_? normalFormalParameterNoMetadata ( ( EQ | CO ) expr )? ;
77+
doStatement : DO_ statement WHILE_ OP expr CP SC ;
7878
dottedIdentifierList : identifier ( D identifier )* ;
7979
element : expressionElement | mapElement | spreadElement | ifElement | forElement ;
8080
elements : element ( C element )* C? ;
8181
enumEntry : metadata identifier ;
8282
enumType : ENUM_ identifier OBC enumEntry ( C enumEntry )* C? CBC ;
8383
equalityExpression : relationalExpression ( equalityOperator relationalExpression )? | SUPER_ equalityOperator relationalExpression ;
8484
equalityOperator : EE | NE ;
85-
expression : assignableExpression assignmentOperator expression | conditionalExpression | cascade | throwExpression ;
86-
expressionElement : expression ;
87-
expressionList : expression ( C expression )* ;
88-
expressionStatement : expression? SC ;
85+
expr : assignableExpression assignmentOperator expr | conditionalExpression | cascade | throwExpression ;
86+
expressionElement : expr ;
87+
expressionList : expr ( C expr )* ;
88+
expressionStatement : expr? SC ;
8989
expressionWithoutCascade : assignableExpression assignmentOperator expressionWithoutCascade | conditionalExpression | throwExpressionWithoutCascade ;
9090
extensionDeclaration : EXTENSION_ identifier? typeParameters? ON_ type OBC ( metadata classMemberDeclaration )* CBC ;
9191
factoryConstructorSignature : CONST_? FACTORY_ constructorName formalParameterList ;
@@ -94,14 +94,14 @@ fieldInitializer : ( THIS_ D )? identifier EQ initializerExpression ;
9494
finalConstVarOrType : LATE_? FINAL_ type? | CONST_ type? | LATE_? varOrType ;
9595
finallyPart : FINALLY_ block ;
9696
forElement : AWAIT_? FOR_ OP forLoopParts CP element ;
97-
forInitializerStatement : localVariableDeclaration | expression? SC ;
98-
forLoopParts : forInitializerStatement expression? SC expressionList? | metadata declaredIdentifier IN_ expression | identifier IN_ expression ;
97+
forInitializerStatement : localVariableDeclaration | expr? SC ;
98+
forLoopParts : forInitializerStatement expr? SC expressionList? | metadata declaredIdentifier IN_ expr | identifier IN_ expr ;
9999
formalParameterList : OP CP | OP normalFormalParameters C? CP | OP normalFormalParameters C optionalOrNamedFormalParameters CP | OP optionalOrNamedFormalParameters CP ;
100100
formalParameterPart : typeParameters? formalParameterList ;
101101
forStatement : AWAIT_? FOR_ OP forLoopParts CP statement ;
102-
functionBody :NATIVE_ stringLiteral? SC | ASYNC_? EG expression SC | ( ASYNC_ ST? | SYNC_ ST )? block ;
102+
functionBody :NATIVE_ stringLiteral? SC | ASYNC_? EG expr SC | ( ASYNC_ ST? | SYNC_ ST )? block ;
103103
functionExpression : formalParameterPart functionExpressionBody ;
104-
functionExpressionBody : ASYNC_? EG expression | ( ASYNC_ ST? | SYNC_ ST )? block ;
104+
functionExpressionBody : ASYNC_? EG expr | ( ASYNC_ ST? | SYNC_ ST )? block ;
105105
functionFormalParameter : COVARIANT_? type? identifier formalParameterPart QU? ;
106106
functionPrefix : type? identifier ;
107107
functionSignature : type? identifier formalParameterPart ;
@@ -112,22 +112,22 @@ functionTypeTails : functionTypeTail QU? functionTypeTails | functionTypeTail ;
112112
getterSignature : type? GET_ identifier ;
113113
identifier : IDENTIFIER | ABSTRACT_ | AS_ | COVARIANT_ | DEFERRED_ | DYNAMIC_ | EXPORT_ | EXTERNAL_ | EXTENSION_ | FACTORY_ | FUNCTION_ | GET_ | IMPLEMENTS_ | IMPORT_ | INTERFACE_ | LATE_ | LIBRARY_ | MIXIN_ | OPERATOR_ | PART_ | REQUIRED_ | SET_ | STATIC_ | TYPEDEF_ | FUNCTION_ | ASYNC_ | HIDE_ | OF_ | ON_ | SHOW_ | SYNC_ | AWAIT_ | YIELD_ | DYNAMIC_ | NATIVE_ ;
114114
identifierList : identifier ( C identifier )* ;
115-
ifElement : IF_ OP expression CP element ( ELSE_ element )? ;
115+
ifElement : IF_ OP expr CP element ( ELSE_ element )? ;
116116
ifNullExpression : logicalOrExpression ( QUQU logicalOrExpression )* ;
117-
ifStatement : IF_ OP expression CP statement ( ELSE_ statement )? ;
117+
ifStatement : IF_ OP expr CP statement ( ELSE_ statement )? ;
118118
importOrExport : libraryImport | libraryExport ;
119119
importSpecification : IMPORT_ configurableUri ( DEFERRED_? AS_ identifier )? combinator* SC ;
120120
incrementOperator : PLPL | MM ;
121-
initializedIdentifier : identifier ( EQ expression )? ;
121+
initializedIdentifier : identifier ( EQ expr )? ;
122122
initializedIdentifierList : initializedIdentifier ( C initializedIdentifier )* ;
123-
initializedVariableDeclaration : declaredIdentifier ( EQ expression )? ( C initializedIdentifier )* ;
123+
initializedVariableDeclaration : declaredIdentifier ( EQ expr )? ( C initializedIdentifier )* ;
124124
initializerExpression : conditionalExpression | cascade ;
125125
initializerListEntry : SUPER_ arguments | SUPER_ D identifier arguments | fieldInitializer | assertion ;
126126
initializers : CO initializerListEntry ( C initializerListEntry )* ;
127127
interfaces : IMPLEMENTS_ typeNotVoidList ;
128128
isOperator : IS_ NOT? ;
129129
label : identifier CO ;
130-
letExpression : LET_ staticFinalDeclarationList IN_ expression ;
130+
letExpression : LET_ staticFinalDeclarationList IN_ expr ;
131131
libraryDeclaration : libraryName? importOrExport* partDirective* ( metadata topLevelDeclaration )* ;
132132

133133
libraryExport : metadata EXPORT_ configurableUri combinator* SC ;
@@ -139,7 +139,7 @@ localFunctionDeclaration : metadata functionSignature functionBody ;
139139
localVariableDeclaration : metadata initializedVariableDeclaration SC ;
140140
logicalAndExpression : equalityExpression ( AA equalityExpression )* ;
141141
logicalOrExpression : logicalAndExpression ( PP logicalAndExpression )* ;
142-
mapElement : expression CO expression ;
142+
mapElement : expr CO expr ;
143143
metadata : ( AT metadatum )* ;
144144
metadatum : identifier | qualifiedName | constructorDesignation arguments ;
145145
methodSignature : constructorSignature initializers? | factoryConstructorSignature | STATIC_? functionSignature | STATIC_? getterSignature | STATIC_? setterSignature | operatorSignature ;
@@ -151,7 +151,7 @@ mixins : WITH_ typeNotVoidList ;
151151
multilineString : MultiLineString;
152152
multiplicativeExpression : unaryExpression ( multiplicativeOperator unaryExpression )* | SUPER_ ( multiplicativeOperator unaryExpression )+ ;
153153
multiplicativeOperator : ST | SL | PC | SQS ;
154-
namedArgument : label expression ;
154+
namedArgument : label expr ;
155155
namedFormalParameters : OBC defaultNamedParameter ( C defaultNamedParameter )* C? CBC ;
156156
namedParameterType : metadata REQUIRED_? typedIdentifier ;
157157
namedParameterTypes : OBC namedParameterType ( C namedParameterType )* C? CBC ;
@@ -179,34 +179,34 @@ partHeader : metadata PART_ OF_ ( dottedIdentifierList | uri ) SC ;
179179
postfixExpression : assignableExpression postfixOperator | primary selector* ;
180180
postfixOperator : incrementOperator ;
181181
prefixOperator : minusOperator | negationOperator | tildeOperator ;
182-
primary : thisExpression | SUPER_ unconditionalAssignableSelector | SUPER_ argumentPart | functionExpression | literal | identifier | newExpression | constObjectExpression | constructorInvocation | OP expression CP ;
182+
primary : thisExpression | SUPER_ unconditionalAssignableSelector | SUPER_ argumentPart | functionExpression | literal | identifier | newExpression | constObjectExpression | constructorInvocation | OP expr CP ;
183183
qualifiedName : typeIdentifier D identifier | typeIdentifier D typeIdentifier D identifier ;
184184
redirectingFactoryConstructorSignature : CONST_? FACTORY_ constructorName formalParameterList EQ constructorDesignation ;
185185
redirection : CO THIS_ ( D identifier )? arguments ;
186186
relationalExpression : bitwiseOrExpression ( typeTest | typeCast | relationalOperator bitwiseOrExpression )? | SUPER_ relationalOperator bitwiseOrExpression ;
187187
relationalOperator : GT EQ | GT | LTE | LT ;
188188
reserved_word : ASSERT_ | BREAK_ | CASE_ | CATCH_ | CLASS_ | CONST_ | CONTINUE_ | DEFAULT_ | DO_ | ELSE_ | ENUM_ | EXTENDS_ | FALSE_ | FINAL_ | FINALLY_ | FOR_ | IF_ | IN_ | IS_ | NEW_ | NULL_ | RETHROW_ | RETURN_ | SUPER_ | SWITCH_ | THIS_ | THROW_ | TRUE_ | TRY_ | VAR_ | VOID_ | WHILE_ | WITH_ ;
189189
rethrowStatement : RETHROW_ SC ;
190-
returnStatement : RETURN_ expression? SC ;
190+
returnStatement : RETURN_ expr? SC ;
191191
selector : NOT | assignableSelector | argumentPart ;
192192
setOrMapLiteral : CONST_? typeArguments? OBC elements? CBC ;
193193
setterSignature : type? SET_ identifier formalParameterList ;
194194
shiftExpression : additiveExpression ( shiftOperator additiveExpression )* | SUPER_ ( shiftOperator additiveExpression )+ ;
195195
shiftOperator : LTLT | GT GT GT | GT GT ;
196196
simpleFormalParameter : declaredIdentifier | COVARIANT_? identifier ;
197197
singleLineString : SingleLineString;
198-
spreadElement : ( DDD | DDDQ ) expression ;
198+
spreadElement : ( DDD | DDDQ ) expr ;
199199
statement : label* nonLabelledStatement ;
200200
statements : statement* ;
201-
staticFinalDeclaration : identifier EQ expression ;
201+
staticFinalDeclaration : identifier EQ expr ;
202202
staticFinalDeclarationList : staticFinalDeclaration ( C staticFinalDeclaration )* ;
203203
stringLiteral : ( multilineString | singleLineString )+ ;
204204
superclass : EXTENDS_ typeNotVoid mixins? | mixins ;
205-
switchCase : label* CASE_ expression CO statements ;
206-
switchStatement : SWITCH_ OP expression CP OBC switchCase* defaultCase? CBC ;
205+
switchCase : label* CASE_ expr CO statements ;
206+
switchStatement : SWITCH_ OP expr CP OBC switchCase* defaultCase? CBC ;
207207
symbolLiteral : PO ( identifier ( D identifier )* | operator | VOID_ ) ;
208208
thisExpression : THIS_ ;
209-
throwExpression : THROW_ expression ;
209+
throwExpression : THROW_ expr ;
210210
throwExpressionWithoutCascade : THROW_ expressionWithoutCascade ;
211211
tildeOperator : SQUIG ;
212212
topLevelDeclaration : classDeclaration | mixinDeclaration | extensionDeclaration | enumType | typeAlias | EXTERNAL_ functionSignature SC | EXTERNAL_ getterSignature SC | EXTERNAL_ setterSignature SC | functionSignature functionBody | getterSignature functionBody | setterSignature functionBody | ( FINAL_ | CONST_ ) type? staticFinalDeclarationList SC | LATE_ FINAL_ type? initializedIdentifierList SC | LATE_? varOrType initializedIdentifierList SC ;
@@ -228,10 +228,10 @@ typeParameter : metadata identifier ( EXTENDS_ typeNotVoid )? ;
228228
typeParameters : LT typeParameter ( C typeParameter )* GT ;
229229
typeTest : isOperator typeNotVoid ;
230230
unaryExpression : prefixOperator unaryExpression | awaitExpression | postfixExpression | ( minusOperator | tildeOperator ) SUPER_ | incrementOperator assignableExpression ;
231-
unconditionalAssignableSelector : OB expression CB | D identifier ;
231+
unconditionalAssignableSelector : OB expr CB | D identifier ;
232232
uri : stringLiteral ;
233233
uriTest : dottedIdentifierList ( EE stringLiteral )? ;
234234
varOrType : VAR_ | type ;
235-
whileStatement : WHILE_ OP expression CP statement ;
236-
yieldEachStatement : YIELD_ ST expression SC ;
237-
yieldStatement : YIELD_ expression SC ;
235+
whileStatement : WHILE_ OP expr CP statement ;
236+
yieldEachStatement : YIELD_ ST expr SC ;
237+
yieldStatement : YIELD_ expr SC ;

dart2/Go/dart2_lexer_base.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package parser
2+
3+
import (
4+
"github.com/antlr4-go/antlr/v4"
5+
)
6+
7+
type Dart2LexerBase struct {
8+
*antlr.BaseLexer
9+
}
10+
11+
func (l *Dart2LexerBase) CheckNotOpenBrace() bool {
12+
return l.GetInputStream().(antlr.CharStream).LA(1) != '{';
13+
}

dart2/Go/transformGrammar.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import sys, os, re, shutil
2+
from glob import glob
3+
from pathlib import Path
4+
5+
def main(argv):
6+
for file in glob("./parser/*Lexer.g4"):
7+
fix_lexer(file)
8+
for file in glob("./parser/*Parser.g4"):
9+
fix_parser(file)
10+
11+
def fix_lexer(file_path):
12+
print("Altering " + file_path)
13+
if not os.path.exists(file_path):
14+
print(f"Could not find file: {file_path}")
15+
sys.exit(1)
16+
parts = os.path.split(file_path)
17+
file_name = parts[-1]
18+
19+
shutil.move(file_path, file_path + ".bak")
20+
input_file = open(file_path + ".bak",'r')
21+
output_file = open(file_path, 'w')
22+
for x in input_file:
23+
if 'this.' in x and '}?' in x:
24+
x = x.replace('this.', 'p.')
25+
elif 'this.' in x:
26+
x = x.replace('this.', 'l.')
27+
output_file.write(x)
28+
output_file.flush()
29+
30+
print("Writing ...")
31+
input_file.close()
32+
output_file.close()
33+
34+
def fix_parser(file_path):
35+
print("Altering " + file_path)
36+
if not os.path.exists(file_path):
37+
print(f"Could not find file: {file_path}")
38+
sys.exit(1)
39+
parts = os.path.split(file_path)
40+
file_name = parts[-1]
41+
42+
shutil.move(file_path, file_path + ".bak")
43+
input_file = open(file_path + ".bak",'r')
44+
output_file = open(file_path, 'w')
45+
for x in input_file:
46+
if 'this.' in x:
47+
x = x.replace('this.', 'p.')
48+
output_file.write(x)
49+
output_file.flush()
50+
51+
print("Writing ...")
52+
input_file.close()
53+
output_file.close()
54+
55+
if __name__ == '__main__':
56+
main(sys.argv)

dart2/Java/Dart2LexerBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
public abstract class Dart2LexerBase extends Lexer
55
{
66
protected Dart2LexerBase(CharStream input) {
7-
super(input);
7+
super(input);
88
}
99

1010
protected boolean CheckNotOpenBrace()
1111
{
12-
return _input.LA(1) != '{';
12+
return _input.LA(1) != '{';
1313
}
1414
}

0 commit comments

Comments
 (0)