From 440fa337931c152785ee7195df9b46e5d35e5f28 Mon Sep 17 00:00:00 2001 From: Linus K Date: Mon, 24 Oct 2022 01:16:31 +0200 Subject: [PATCH] Small change --- src/main/antlr4/astRefactor/astRefactor.g4 | 65 +++++++++++----------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/src/main/antlr4/astRefactor/astRefactor.g4 b/src/main/antlr4/astRefactor/astRefactor.g4 index 838ddac9..bd24c170 100644 --- a/src/main/antlr4/astRefactor/astRefactor.g4 +++ b/src/main/antlr4/astRefactor/astRefactor.g4 @@ -3,21 +3,20 @@ grammar astRefactor; /* * Parser Rules */ - -class : ACCESSMODIFIER WHITESPACE CLASS WHITESPACE NAME '(' ( MODIFIER| TYPEPLACEHOLDER ) WHITESPACE NAME ')''{'NEWLINE classbody'}'; -classbody : ( method NEWLINE | variable NEWLINE )+; - -variable : ACCESSMODIFIER WHITESPACE ( MODIFIER | TYPEPLACEHOLDER )WHITESPACE NAME WHITESPACE '=' WHITESPACE ( WORD | NUMBER) ';' - | ACCESSMODIFIER WHITESPACE ( MODIFIER | TYPEPLACEHOLDER ) WHITESPACE NAME ';'; - -method : ACCESSMODIFIER WHITESPACE ( MODIFIER | TYPEPLACEHOLDER ) WHITESPACE NAME '(' ( MODIFIER | TYPEPLACEHOLDER ) WHITESPACE WORD ')'; - - syntaxtreenode: typablestatement | reftypeortphorwildcardorgeneric | methodinterface | fieldinterface | formalparameter | parameterlist | generictypevar | sourcefile | genericdecllist | argumentlist | classorinterface; +class : ACCESSMODIFIER WHITESPACE CLASS WHITESPACE CLASSNAME '(' ( formalparameter| typeplaceholder ) WHITESPACE NAME ')''{'(NEWLINE)* classbody'}'; +classbody : ( method NEWLINE | variable NEWLINE )*; + +variable : ACCESSMODIFIER WHITESPACE ( formalparameter | typeplaceholder )WHITESPACE NAME WHITESPACE '=' WHITESPACE ( WORD | NUMBER) ';' + | ACCESSMODIFIER WHITESPACE ( formalparameter | typeplaceholder ) WHITESPACE NAME ';'; + +method : ACCESSMODIFIER WHITESPACE ( formalparameter | typeplaceholder ) WHITESPACE NAME '(' ( formalparameter | typeplaceholder ) WHITESPACE WORD ')'; + + classorinterface: class; -argumentlist: ARGUMENTLIST; +argumentlist: (variable)+; genericdecllist: GENERICDECLLIST; @@ -25,11 +24,15 @@ sourcefile: SOURCEFILE; generictypevar: GENERICTYPEVAR; -parameterlist: PARAMLIST; +parameterlist: (variable)+; -formalparameter: FORMALPARAMETER; +formalparameter: variable; -fieldinterface: FIELDDECLARATION | FIELD; +fieldinterface: fielddeclaration | field; + +fielddeclaration: variable; + +field: NAME; methodinterface: method | constructor; @@ -75,7 +78,7 @@ statement: whileinterface | methodcallinterface | returninterface | javainternal javainternalexpressioninterface: UNARYEXPR; -returninterface: RETURN | RETRUNVOID; +returninterface: RETURN | RETURNVOID; methodcallinterface: METHODCALL | THISCALL | SUPERCALL | NEWCLASS; @@ -95,19 +98,18 @@ fragment UPPERCASE : [A-Z] ; NUMBER : [0-9]+; CLASS : 'class'; ACCESSMODIFIER : ('public' | 'private'); -MODIFIER : ('int' | 'String' | 'char'); WHITESPACE : ' '; NEWLINE : ('\r'? '\n' | '\r')+ ; ARGUMENTLIST : 'argumentlist'; -GENERICDECLLIST : 'genericdecllist'; -SOURCEFILE : 'sourcefile'; +GENERICDECLLIST : 'List'; +SOURCEFILE : (UPPERCASE | LOWERCASE)+'.java'; ASSIGNTOFIELD : 'assigntofield'; ASSIGNLEFTSIDE : 'assignleftside'; -WHILESTMT : 'whilestmt'; -DOSTMT : 'dosstmt'; +WHILESTMT : 'while()'; +DOSTMT : 'do()'; GENERICTYPEVAR : 'generictypevar'; PARAMLIST : 'paramlist'; -FORMALPARAMETER : 'formalparameter'; +FORMALPARAMETER : ('int' | 'String' | 'char'); FIELDDECLARATION : 'fielddeclaration'; FIELD : 'field'; CONSTRUCTOR : 'constructor'; @@ -121,30 +123,31 @@ GENERICREFTYPE : 'genericreftype'; THIS : 'this'; SUPER : 'super'; FIELDVAR : 'fieldvar'; -NEWARRAY : 'newarray'; +NEWARRAY : 'new ArrayList<>()'; LITERAL : 'literal'; CASTEXPR : 'castexpr'; LAMBDAEXPRESSION : 'lambdaexpression'; -INSTANCEOF : 'instanceof'; +INSTANCEOF : 'instanceOf'; BINARYEXPR : 'binaryexpr'; EXPRESSIONRECEIVER : 'expressionreceiver'; STATICCLASSNAME : 'staticclassname'; -FORSMT : 'forstmt'; +FORSMT : 'for()'; BLOCK : 'block'; EMPTYSTMT : 'emptystmt'; LOCALVARDECL : 'localvardecl'; ASSIGN : 'assign'; -IFSTMT : 'ifstmt'; +IFSTMT : 'if()'; LOCALVAR : 'localvar'; RETURN : 'return'; -RETRUNVOID : 'returnvoid'; +RETURNVOID : 'return void'; METHODCALL : 'methodcall'; -THISCALL : 'thiscall'; -SUPERCALL : 'supercall'; +THISCALL : 'this'; +SUPERCALL : 'super'; NEWCLASS : 'newclass'; -UNARYEXPR : 'unaryexpr'; -NAME : (LOWERCASE)( LOWERCASE | UPPERCASE )+; -WORD : (LOWERCASE | UPPERCASE | '_')+ ; +UNARYEXPR : ('+' | '-' | '++' | '--' | '!'); +CLASSNAME : UPPERCASE ( LOWERCASE | UPPERCASE)*; +NAME : LOWERCASE( LOWERCASE | UPPERCASE )*; +WORD : (LOWERCASE | UPPERCASE | '_')+;