Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // test.g4 file;
- grammar milestone_2;
- INDENT: (' ')+;
- SKIP1:(' ')+->skip;
- NEWLINE2: (' ')-> skip;
- NEWLINE : [\r\n]-> skip;
- MULTICOMMENT:' '* '#'+'[' (SINGLECOMMENT|.)*? ']' '#' ' '* ->skip;
- SINGLECOMMENT: ' '* '#' + '[' .*? ']' '#' ' '*[\n|\r]* -> skip;
- COMMENT : ' '* '#'+ .*? [\n\r] ' '* -> skip;
- VAR : 'var' ;
- AND : 'and';
- ADDR : 'addr';
- AS: 'as';
- ASM: 'asm';
- BIND: 'bind';
- BLOCK: 'block';
- BREAK: 'break';
- CASE: 'case';
- CAST: 'cast';
- CONCEPT: 'concept';
- CONST: 'const';
- CONTINUE: 'continue';
- CONVERTER: 'converter';
- DEFER: 'defer';
- DISCARD:'discard';
- DISTINCT:'distinct';
- DIV:'div';
- DO:'do';
- ELIF: 'elif';
- ELSE:'else';
- ENUM:'enum';
- END:'end';
- EXCEPT:'except';
- EXPORT:'export';
- FINALLY:'finally';
- FOR:'for';
- FUNC:'func';
- IF:'if';
- IMPORT:'import';
- IN:'in';
- INCLUDE:'include';
- INTERFACE:'interface';
- IS:'is';
- ISNOT:'isnot';
- ITERATOR:'iterator';
- LET:'let';
- MACRO:'macro';
- METHOD:'method';
- MIXIN:'mixin';
- MOD:'mod';
- NIL:'nil';
- NOT:'not';
- NOTIN:'notin';
- OBJECT:'object';
- OF:'of';
- OR:'or';
- OUT:'out';
- PROC:'proc';
- PTR:'ptr';
- RAISE:'raise';
- REF:'ref';
- RETURN:'return';
- SHL:'shl';
- SHR:'shr';
- STATIC:'static';
- TEMPLATE:'template';
- TRY:'try';
- TUPLE:'tuple';
- TYPE:'type';
- USING:'using';
- WHEN:'when';
- WHILE:'while';
- XOR:'xor';
- YIELD:'yield';
- OP0:('->'|'=>');
- OP1:('+='|'*=');
- OP2:(AT|COLON|'?');
- OP3:(OR|XOR);
- OP4:AND;
- OP5:('=='|'<='|'<'|'>='|'!='|'>'|IN|NOTIN|IS|ISNOT|NOT|OF|'=');
- OP6:DOT DOT;
- OP7:AND_OPERATOR;
- OP8:ADD_OPERATOR|MINUS_OPERATOR;
- OP9:MUL_OPERATOR|DIV_OPERATOR|DIV|MOD|SHL|SHR|MODULUS;
- OP10:'$'|'^';
- IDENTIFIER: LETTER+ ('_'|(LETTER| DIGIT))*;
- LETTER :([A-Z] | [a-z] ){print('LETTER')};
- FLOAT32_SUFFIX : ('f' | 'F') ('32');
- FLOAT32_LIT : HEX_LIT '\'' FLOAT32_SUFFIX
- | (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ('\'') FLOAT32_SUFFIX;
- FLOAT64_SUFFIX: ( ('f' | 'F') '64' ) | 'd' | 'D';
- FLOAT64_LIT : HEX_LIT '\'' FLOAT64_SUFFIX
- | (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ('\'') FLOAT64_SUFFIX;
- FLOAT_LIT : DIGIT ('_' DIGIT)* (('.' DIGIT ('_' DIGIT|DIGIT)* (EXP)*) |EXP);
- DIGIT:[0-9];
- HEXDIGIT : DIGIT | [A-F] | [a-f];
- OCTDIGIT : [0-7];
- BINDIGIT : [0-1];
- INT_LIT : HEX_LIT
- | DEC_LIT
- | OCT_LIT
- | BIN_LIT;
- HEX_LIT : '0' ('x' | 'X' ) HEXDIGIT ('_' HEXDIGIT | HEXDIGIT)*;
- DEC_LIT : DIGIT ( '_' DIGIT|DIGIT )*;
- OCT_LIT : '0' 'o' OCTDIGIT ( '_' OCTDIGIT|OCTDIGIT )*;
- BIN_LIT : '0' ('b' | 'B' ) BINDIGIT ( '_' BINDIGIT | BINDIGIT )*;
- INT8_LIT : INT_LIT ('\'') ('i' | 'I') '8';
- INT16_LIT : INT_LIT ('\'') ('i' | 'I') '16';
- INT32_LIT : INT_LIT ('\'') ('i' | 'I') '32';
- INT64_LIT : INT_LIT ('\'') ('i' | 'I') '64';
- UINT_LIT : INT_LIT ('\'') ('u' | 'U');
- UINT8_LIT : INT_LIT ('\'') ('u' | 'U') '8';
- UINT16_LIT : INT_LIT ('\'') ('u' | 'U') '16';
- UINT32_LIT : INT_LIT ('\'') ('u' | 'U') '32';
- UINT64_LIT : INT_LIT ('\'') ('u' | 'U') '64';
- EXP : ('E' | 'e' ) ('+' | '-') DIGIT ( '_' DIGIT |DIGIT )*;
- EQUALS_OPERATOR: '='+;
- ADD_OPERATOR:'+';
- MUL_OPERATOR:'*';
- MINUS_OPERATOR:'-';
- DIV_OPERATOR:'/';
- BITWISE_NOT_OPERATOR:'~';
- AND_OPERATOR:'&';
- OR_OPERATOR:'|';
- LESS_THAN:'<';
- GREATER_THAN:'>';
- AT:'@';
- MODULUS:'%';
- NOT_OPERATOR:'!';
- XOR_OPERATOR:'^';
- DOT:'.';
- COLON:':';
- FROM:'from';
- OPEN_PAREN:'(';
- CLOSE_PAREN:')';
- OPEN_BRACE:'{';
- CLOSE_BRACE:'}';
- OPEN_BRACK:'[';
- CLOSE_BRACK:']';
- COMMA:',';
- SEMI_COLON:';';
- STR_LIT: '"'(.*?) '"';
- CHAR_LIT: '\'' .*? '\'';
- TRIPLESTR_LIT: '"""' .*? '"""';
- RSTR_LIT: ('R'|'r') '"' .*? '"';
- module : (stmt ((';' | INDENT) stmt)*)?;
- start: module;
- comma : ',' COMMENT?;
- semicolon : ';' COMMENT?;
- colon : ':' COMMENT?;
- colcom : ':' COMMENT?;
- operator : OP0 | OP1 | OP2 | OP3 | OP4 | OP5 | OP6 | OP7 | OP8 | OP9
- | 'or' | 'xor' | 'and'
- | 'is' | 'isnot' | 'in' | 'notin' | 'of'
- | 'div' | 'mod' | 'shl' | 'shr' | 'not' | 'static' | '..';
- opr: OP0 | OP1 | OP2 | OP3 | OP4 | OP5 | OP6 | OP7 | OP8 | OP9
- | 'or' | 'xor' | 'and'
- | 'is' | 'isnot' | 'in' | 'notin' | 'of'
- | 'div' | 'mod' | 'shl' | 'shr' | 'not' | 'static' | '..';
- prefixOperator : operator;
- optInd : COMMENT? INDENT?;
- optPar : (INDENT | INDENT)?;
- simpleExpr : arrowExpr (OP0 optInd arrowExpr)* pragma?;
- arrowExpr : assignExpr (OP1 optInd assignExpr)*;
- assignExpr : orExpr (OP2 optInd orExpr)*;
- orExpr : andExpr (OP3 optInd andExpr)*;
- andExpr : cmpExpr (OP4 optInd cmpExpr)*;
- cmpExpr : sliceExpr (OP5 optInd sliceExpr)*;
- sliceExpr : ampExpr (OP6 optInd ampExpr)*;
- ampExpr : plusExpr (OP7 optInd plusExpr)*;
- plusExpr : mulExpr (OP8 optInd mulExpr)*;
- mulExpr : dollarExpr (OP9 optInd dollarExpr)*;
- dollarExpr : primary (OP10 optInd primary)*;
- keyw:parKeyw|typeKeyw|'int'|'string';
- symbol : ('\'' (keyw|IDENTIFIER|literal|(operator|'('|')'|'['|']'|'{'|'}'|'='))+ '\'')
- | IDENTIFIER | keyw|literal|STR_LIT;
- exprColonEqExpr : expr (':'|'=' expr)?;
- exprList : expr (comma expr)*;
- exprColonEqExprList : exprColonEqExpr (comma exprColonEqExpr)* (comma)?;
- dotExpr : expr '.' optInd (symbol | '[:' exprList ']');
- explicitGenericInstantiation : '[:' exprList ']' ( '(' exprColonEqExpr ')' )?;
- qualifiedIdent : symbol ('.' optInd symbol)?;
- setOrTableConstr : '{' ((exprColonEqExpr comma)* | ':' ) '}';
- castExpr : 'cast' '[' optInd typeDesc optPar ']' '(' optInd expr optPar ')';
- parKeyw : 'discard' | 'include' | 'if' | 'while' | 'case' | 'try'
- | 'finally' | 'except' | 'for' | 'block' | 'const' | 'let'
- | 'when' | 'var' | 'mixin';
- par : '(' optInd
- ( parKeyw complexOrSimpleStmt ( ';' complexOrSimpleStmt)*
- | ';' complexOrSimpleStmt( ';' complexOrSimpleStmt)*
- | pragmaStmt
- | simpleExpr ( ('=' expr (';' complexOrSimpleStmt (';' complexOrSimpleStmt)* )? )
- | (':' expr (',' exprColonEqExpr ( ',' exprColonEqExpr)* )? ) ) )
- optPar ')';
- literal : STR_LIT|INT_LIT | INT8_LIT | INT16_LIT | INT32_LIT | INT64_LIT
- | UINT_LIT | UINT8_LIT | UINT16_LIT | UINT32_LIT | UINT64_LIT
- | FLOAT_LIT | FLOAT32_LIT | FLOAT64_LIT
- | STR_LIT | RSTR_LIT | TRIPLESTR_LIT
- | CHAR_LIT
- | NIL;
- generalizedLit : GENERALIZED_STR_LIT | GENERALIZED_TRIPLESTR_LIT;
- identOrLiteral : generalizedLit | symbol | literal
- | par | arrayConstr | setOrTableConstr
- | castExpr;
- tupleConstr : '(' optInd (exprColonEqExpr comma+)* optPar ')';
- arrayConstr : '[' optInd (exprColonEqExpr comma+)* optPar ']';
- primarySuffix : '(' (exprColonEqExpr comma+)* ')' doBlocks?
- | doBlocks
- | '.' optInd symbol generalizedLit?
- | '[' optInd exprList optPar ']'
- | '{' optInd exprList optPar '}'
- | ( '`'|IDENTIFIER|literal|'cast'|'addr'|'type') expr ;
- condExpr : expr colcom expr optInd
- ('elif' expr colcom expr optInd)*
- 'else' colcom expr;
- ifExpr : 'if' condExpr;
- moduleName:IDENTIFIER;
- whenExpr : 'when' condExpr;
- pragma : '{.' optInd (exprColonEqExpr comma?)* optPar ('.}' | '}');
- identVis : symbol opr?;
- identVisDot : symbol '.' optInd symbol opr?;
- identWithPragma : identVis pragma?;
- identWithPragmaDot : identVisDot pragma?;
- declColonEquals : identWithPragma (comma identWithPragma)* comma? firstPart secondPart;
- identColonEquals : IDENTIFIER (comma IDENTIFIER)* comma? firstPart secondPart;
- firstPart: ':'?( optInd typeDesc)?;
- secondPart:'='?( optInd expr)?;
- inlTupleDecl : 'tuple'
- '[' optInd (identColonEquals (comma|semicolon)?)* optPar ']';
- extTupleDecl : 'tuple'
- COMMENT? (INDENT identColonEquals (INDENT identColonEquals)*)?;
- tupleClass : 'tuple';
- paramList : '(' (declColonEquals ((comma|semicolon)? declColonEquals)*)? ')';
- paramListWithoutParan:(declColonEquals ((comma|semicolon)? declColonEquals)*)?;
- paramListArrow : paramList? ('->' optInd typeDesc)?;
- paramListColon : paramList? (':' optInd typeDesc)?;
- procExpr : 'proc' paramListColon pragmas? ('=' COMMENT? stmt)?;
- distinct : 'distinct' optInd typeDesc;
- forStmt : 'for' (identWithPragma (comma identWithPragma)*) 'in' expr colcom stmt;
- forExpr : forStmt;
- expr : (blockExpr
- | ifExpr
- | whenExpr
- //removed caseExpr
- | forExpr
- | tryExpr)
- | simpleExpr;
- typeKeyw : 'var' | 'out' | 'ref' | 'ptr' | 'shared' | 'tuple'
- | 'proc' | 'iterator' | 'distinct' | 'object' | 'enum';
- primary : typeKeyw typeDesc
- | prefixOperator* identOrLiteral primarySuffix*
- | 'bind' primary;
- typeDesc : simpleExpr;
- typeDefAux : simpleExpr
- | 'concept' typeClass;
- postExprBlocks : ':' stmt? ( INDENT doBlock
- | INDENT 'of' exprList ':' stmt
- | INDENT 'elif' expr ':' stmt
- | INDENT 'except' exprList ':' stmt
- | INDENT 'else' ':' stmt )*;
- exprStmt : simpleExpr
- (( '=' optInd expr colonBody? )
- | ( expr (comma expr)*
- doBlocks
- //removed Macro
- ))?;
- importStmt : 'import' optInd expr
- ((comma expr)*
- | 'except' optInd (expr (comma expr))*);
- includeStmt : 'include' optInd expr (comma expr)*;
- fromStmt : 'from' moduleName 'import' optInd expr (comma expr)*;
- returnStmt : 'return' optInd expr?;
- raiseStmt : 'raise' optInd expr?;
- yieldStmt : 'yield' optInd expr?;
- discardStmt : 'discard' optInd expr?;
- breakStmt : 'break' optInd expr?;
- continueStmt : 'continue' optInd expr?;
- condStmt : expr colcom stmt COMMENT?
- (INDENT 'elif' expr colcom stmt)*
- (INDENT'else' colcom stmt)?;
- ifStmt : 'if' condStmt;
- whenStmt : 'when' condStmt;
- whileStmt : 'while' expr colcom stmt;
- ofBranch : 'of' exprList colcom stmt;
- ofBranches : ofBranch (INDENT ofBranch)*
- (INDENT 'elif' expr colcom stmt)*
- (INDENT 'else' colcom stmt)?;
- caseStmt : 'case' expr ':'? COMMENT?
- (INDENT ofBranches
- |INDENT ofBranches);
- tryStmt : 'try' colcom stmt (INDENT? 'except'|'finally')
- (INDENT? 'except' exprList colcom stmt)*
- (INDENT? 'finally' colcom stmt)?;
- tryExpr : 'try' colcom stmt (optInd 'except'|'finally')
- (optInd 'except' exprList colcom stmt)*
- (optInd 'finally' colcom stmt)?;
- exceptBlock : 'except' colcom stmt;
- blockStmt : 'block' symbol? colcom stmt;
- blockExpr : 'block' symbol? colcom stmt;
- staticStmt : 'static' colcom stmt;
- deferStmt : 'defer' colcom stmt;
- asmStmt : 'asm' pragma? (STR_LIT | RSTR_LIT | TRIPLESTR_LIT);
- genericParam : symbol (comma symbol)* (colon expr)? ('=' optInd expr)?;
- genericParamList : '[' optInd
- (genericParam ((comma|semicolon) genericParam)*)? optPar ']';
- pattern : '{' stmt '}';
- indAndComment : (INDENT COMMENT)? | COMMENT?;
- routine : optInd identVis pattern? genericParamList?
- paramListColon pragma? ('=' COMMENT? stmt)? indAndComment;
- commentStmt : COMMENT;
- section1 : COMMENT? typeDef | (INDENT (typeDef | COMMENT)(INDENT (typeDef | COMMENT))* );
- section2 : COMMENT? constant | (INDENT(constant | COMMENT)(INDENT (constant | COMMENT))* );
- section3 : COMMENT? variable | (INDENT (variable | COMMENT)(INDENT (variable | COMMENT))* );
- doBlock : 'do' paramListArrow pragmas? colcom stmt;
- doBlocks: (doBlock)+;
- constant : identWithPragma (colon typeDesc)? '=' optInd expr indAndComment;
- enum : 'enum' optInd (symbol optInd ('=' optInd expr COMMENT?)? comma?)+;
- objectWhen : 'when' expr colcom objectPart COMMENT?
- ('elif' expr colcom objectPart COMMENT?)*
- ('else' colcom objectPart COMMENT?)?;
- objectBranch : 'of' exprList colcom objectPart;
- objectBranches : objectBranch (INDENT objectBranch)*
- (INDENT'elif' expr colcom objectPart)*
- (INDENT 'else' colcom objectPart)?;
- objectCase : 'case' identWithPragma ':' typeDesc ':'? COMMENT?
- (INDENT objectBranches
- | INDENT objectBranches);
- objectPart : INDENT objectPart(INDENT objectPart)* //DED
- | objectWhen | objectCase | 'nil' | 'discard' | declColonEquals;
- object1 : 'object' pragma? ('of' typeDesc)? COMMENT? objectPart;
- typeClassParam : ('var' | 'out')? symbol;
- typeClass : (typeClassParam (',' typeClassParam)*)? (pragma)? ('of' (typeDesc (',' typeDesc)*)?)?
- INDENT stmt;
- typeDef : identWithPragmaDot genericParamList? '=' optInd typeDefAux
- indAndComment;
- varTuple : '(' optInd identWithPragma ( comma identWithPragma)* optPar ')' '=' optInd expr;
- colonBody : colcom stmt doBlocks?;
- variable : (varTuple | identColonEquals) colonBody? indAndComment;
- bindStmt : 'bind' optInd qualifiedIdent (comma qualifiedIdent)*;
- mixinStmt : 'mixin' optInd qualifiedIdent ( comma qualifiedIdent)*;
- pragmaStmt : pragma (':' COMMENT? stmt)?;
- simpleStmt : ((returnStmt | raiseStmt | yieldStmt | discardStmt | breakStmt
- | continueStmt | pragmaStmt | importStmt | fromStmt //removed exportstmt
- | includeStmt | commentStmt) | exprStmt) COMMENT?;
- complexOrSimpleStmt : (ifStmt | whenStmt | whileStmt
- | tryStmt | forStmt
- | blockStmt | staticStmt | deferStmt | asmStmt
- | 'proc' routine
- | 'method' routine
- | 'iterator' routine
- | 'macro' routine
- | echoStatement
- | 'template' routine
- | 'converter' routine
- | 'type' section1(typeDef)
- | 'const' section2(constant)
- | ('let' | 'var' | 'using') section3(variable)
- | bindStmt | mixinStmt)
- | simpleStmt;
- stmt : (INDENT? complexOrSimpleStmt((INDENT? | ';') complexOrSimpleStmt)* )
- | simpleStmt (';' simpleStmt)*;
- pragmas:(pragma)+;
- echoParamList: paramList|paramListWithoutParan;
- echoStatement: 'echo' echoParamList stmt?;
- exprColonExpr: expr ':' expr;
- GENERALIZED_STR_LIT:IDENTIFIER STR_LIT;
- GENERALIZED_TRIPLESTR_LIT: IDENTIFIER TRIPLESTR_LIT;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement