📄 java.g
字号:
: annotationMethodRest | annotationConstantRest ; annotationMethodRest : '(' ')' (defaultValue)? ; annotationConstantRest : variableDeclarators ; defaultValue : 'default' elementValue ;// STATEMENTS / BLOCKSblock : '{' blockStatement* '}' ; blockStatement : localVariableDeclaration | classOrInterfaceDeclaration | statement ; localVariableDeclaration : ('final')? type variableDeclarators ';' ; statement : block | 'assert' expression (':' expression)? ';' | 'if' parExpression statement ('else' statement)? | 'for' '(' forControl ')' statement | 'while' parExpression statement | 'do' statement 'while' parExpression ';' | 'try' block ( catches 'finally' block | catches | 'finally' block ) | 'switch' parExpression '{' switchBlockStatementGroups '}' | 'synchronized' parExpression block | 'return' expression? ';' | 'throw' expression ';' | 'break' Identifier? ';' | 'continue' Identifier? ';' | ';' | statementExpression ';' | Identifier ':' statement ; catches : catchClause (catchClause)* ; catchClause : 'catch' '(' formalParameter ')' block ;formalParameter : variableModifier* type variableDeclaratorId ; switchBlockStatementGroups : (switchBlockStatementGroup)* ; switchBlockStatementGroup : switchLabel blockStatement* ; switchLabel : 'case' constantExpression ':' | 'case' enumConstantName ':' | 'default' ':' ; moreStatementExpressions : (',' statementExpression)* ;forControloptions {k=3;} // be efficient for common case: for (ID ID : ID) ... : forVarControl | forInit? ';' expression? ';' forUpdate? ;forInit : 'final'? (annotation)? type variableDeclarators | expressionList ; forVarControl : 'final'? type Identifier ':' expression ;forUpdate : expressionList ;// EXPRESSIONSparExpression : '(' expression ')' ; expressionList : expression (',' expression)* ;statementExpression : expression ; constantExpression : expression ; expression : conditionalExpression (assignmentOperator expression)? ; assignmentOperator : '=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' | '%=' | '<' '<' '=' | '>' '>' '=' | '>' '>' '>' '=' ;conditionalExpression : conditionalOrExpression ( '?' expression ':' expression )? ;conditionalOrExpression : conditionalAndExpression ( '||' conditionalAndExpression )* ;conditionalAndExpression : inclusiveOrExpression ( '&&' inclusiveOrExpression )* ;inclusiveOrExpression : exclusiveOrExpression ( '|' exclusiveOrExpression )* ;exclusiveOrExpression : andExpression ( '^' andExpression )* ;andExpression : equalityExpression ( '&' equalityExpression )* ;equalityExpression : instanceOfExpression ( ('==' | '!=') instanceOfExpression )* ;instanceOfExpression : relationalExpression ('instanceof' type)? ;relationalExpression : shiftExpression ( relationalOp shiftExpression )* ; relationalOp : ('<' '=' | '>' '=' | '<' | '>') ;shiftExpression : additiveExpression ( shiftOp additiveExpression )* ; // TODO: need a sem pred to check column on these >>>shiftOp : ('<' '<' | '>' '>' '>' | '>' '>') ;additiveExpression : multiplicativeExpression ( ('+' | '-') multiplicativeExpression )* ;multiplicativeExpression : unaryExpression ( ( '*' | '/' | '%' ) unaryExpression )* ; unaryExpression : '+' unaryExpression | '-' unaryExpression | '++' primary | '--' primary | unaryExpressionNotPlusMinus ;unaryExpressionNotPlusMinus : '~' unaryExpression | '!' unaryExpression | castExpression | primary selector* ('++'|'--')? ;castExpression : '(' primitiveType ')' unaryExpression | '(' (expression | type) ')' unaryExpressionNotPlusMinus ;primary : parExpression | nonWildcardTypeArguments (explicitGenericInvocationSuffix | 'this' arguments) | 'this' (arguments)? | 'super' superSuffix | literal | 'new' creator | Identifier ('.' Identifier)* (identifierSuffix)? | primitiveType ('[' ']')* '.' 'class' | 'void' '.' 'class' ;identifierSuffix : ('[' ']')+ '.' 'class' | ('[' expression ']')+ // can also be matched by selector, but do here | arguments | '.' 'class' | '.' explicitGenericInvocation | '.' 'this' | '.' 'super' arguments | '.' 'new' (nonWildcardTypeArguments)? innerCreator ; creator : nonWildcardTypeArguments? createdName (arrayCreatorRest | classCreatorRest) ;createdName : Identifier nonWildcardTypeArguments? ('.' Identifier nonWildcardTypeArguments?)* | primitiveType ; innerCreator : Identifier classCreatorRest ;arrayCreatorRest : '[' ( ']' ('[' ']')* arrayInitializer | expression ']' ('[' expression ']')* ('[' ']')* ) ;classCreatorRest : arguments classBody? ; explicitGenericInvocation : nonWildcardTypeArguments explicitGenericInvocationSuffix ; nonWildcardTypeArguments : '<' typeList '>' ; explicitGenericInvocationSuffix : 'super' superSuffix | Identifier arguments ; selector : '.' Identifier (arguments)? | '.' 'this' | '.' 'super' superSuffix | '.' 'new' (nonWildcardTypeArguments)? innerCreator | '[' expression ']' ; superSuffix : arguments | '.' Identifier (arguments)? ;arguments : '(' expressionList? ')' ;// LEXERHexLiteral : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;DecimalLiteral : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;OctalLiteral : '0' ('0'..'7')+ IntegerTypeSuffix? ;fragmentHexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;fragmentIntegerTypeSuffix : ('l'|'L') ;FloatingPointLiteral : ('0'..'9')+ '.' ('0'..'9')* Exponent? FloatTypeSuffix? | '.' ('0'..'9')+ Exponent? FloatTypeSuffix? | ('0'..'9')+ Exponent FloatTypeSuffix? | ('0'..'9')+ Exponent? FloatTypeSuffix ;fragmentExponent : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;fragmentFloatTypeSuffix : ('f'|'F'|'d'|'D') ;CharacterLiteral : '\'' ( EscapeSequence | ~('\''|'\\') ) '\'' ;StringLiteral : '"' ( EscapeSequence | ~('\\'|'"') )* '"' ;fragmentEscapeSequence : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | UnicodeEscape | OctalEscape ;fragmentOctalEscape : '\\' ('0'..'3') ('0'..'7') ('0'..'7') | '\\' ('0'..'7') ('0'..'7') | '\\' ('0'..'7') ;fragmentUnicodeEscape : '\\' 'u' HexDigit HexDigit HexDigit HexDigit ;ENUM: 'enum' { if not self.enumIsKeyword: $type = Identifier } ; Identifier : Letter (Letter|JavaIDDigit)* ;/**I found this char range in JavaCC's grammar, but Letter and Digit overlap. Still works, but... */fragmentLetter : '\u0024' | '\u0041'..'\u005a' | '\u005f' | '\u0061'..'\u007a' | '\u00c0'..'\u00d6' | '\u00d8'..'\u00f6' | '\u00f8'..'\u00ff' | '\u0100'..'\u1fff' | '\u3040'..'\u318f' | '\u3300'..'\u337f' | '\u3400'..'\u3d2d' | '\u4e00'..'\u9fff' | '\uf900'..'\ufaff' ;fragmentJavaIDDigit : '\u0030'..'\u0039' | '\u0660'..'\u0669' | '\u06f0'..'\u06f9' | '\u0966'..'\u096f' | '\u09e6'..'\u09ef' | '\u0a66'..'\u0a6f' | '\u0ae6'..'\u0aef' | '\u0b66'..'\u0b6f' | '\u0be7'..'\u0bef' | '\u0c66'..'\u0c6f' | '\u0ce6'..'\u0cef' | '\u0d66'..'\u0d6f' | '\u0e50'..'\u0e59' | '\u0ed0'..'\u0ed9' | '\u1040'..'\u1049' ;WS : (' '|'\r'|'\t'|'\u000C'|'\n') { $channel=HIDDEN } ;COMMENT : '/*' ( options {greedy=false;} : . )* '*/' { $channel=HIDDEN } ;LINE_COMMENT : '//' ~('\n'|'\r')* '\r'? '\n' { $channel=HIDDEN } ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -