Merge branch '7.0.x' into text-utils-comments
This commit is contained in:
@ -1,4 +1,12 @@
|
||||
/**
|
||||
* Support "JEP 427: Pattern Matching for switch (Third Preview)" for Java 19 Preview
|
||||
* Note: GuardedPattern is deprecated and only valid for 17-preview and 18-preview
|
||||
* New AST node: ASTSwitchGuard (production "Guard") - used within switch case labels for refining a pattern
|
||||
* Support "JEP 405: Record Patterns (Preview)" for Java 19 Preview
|
||||
* New AST node: ASTRecordPattern and ASTComponentPatternList (production "RecordStructurePattern")
|
||||
* Remove support for Java 17 preview language features
|
||||
* Andreas Dangel 07/2022
|
||||
*====================================================================
|
||||
* Improve module grammar.
|
||||
* Type names in "provides" directives are disambiguated like any other type name.
|
||||
* ASTName is made redundant and removed for good.
|
||||
@ -322,7 +330,6 @@ class JavaParserImpl {
|
||||
*/
|
||||
private boolean inSwitchLabel = false;
|
||||
|
||||
|
||||
// This is a semantic LOOKAHEAD to determine if we're dealing with an assert
|
||||
// Note that this can't be replaced with a syntactic lookahead
|
||||
// since "assert" isn't a string literal token
|
||||
@ -796,7 +803,7 @@ TOKEN :
|
||||
"\u1310","\u1312"-"\u1315","\u1318"-"\u131e","\u1320"-"\u1346","\u1348"-"\u135a",
|
||||
"\u13a0"-"\u13f4","\u1401"-"\u166c","\u166f"-"\u1676","\u1681"-"\u169a","\u16a0"-"\u16ea",
|
||||
"\u1780"-"\u17b3","\u17db","\u1820"-"\u1877","\u1880"-"\u18a8","\u1e00"-"\u1e9b",
|
||||
"\u1ea0"-"\u1ef9","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d",
|
||||
"\u1ea0"-"\u1ef9","\u1d00"-"\u1eef","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d",
|
||||
"\u1f50"-"\u1f57","\u1f59","\u1f5b","\u1f5d","\u1f5f"-"\u1f7d","\u1f80"-"\u1fb4",
|
||||
"\u1fb6"-"\u1fbc","\u1fbe","\u1fc2"-"\u1fc4","\u1fc6"-"\u1fcc","\u1fd0"-"\u1fd3",
|
||||
"\u1fd6"-"\u1fdb","\u1fe0"-"\u1fec","\u1ff2"-"\u1ff4","\u1ff6"-"\u1ffc","\u203f"-"\u2040",
|
||||
@ -804,7 +811,7 @@ TOKEN :
|
||||
"\u2124","\u2126","\u2128","\u212a"-"\u212d","\u212f"-"\u2131","\u2133"-"\u2139",
|
||||
"\u2160"-"\u2183","\u3005"-"\u3007","\u3021"-"\u3029","\u3031"-"\u3035","\u3038"-"\u303a",
|
||||
"\u3041"-"\u3094","\u309d"-"\u309e","\u30a1"-"\u30fe","\u3105"-"\u312c","\u3131"-"\u318e",
|
||||
"\u31a0"-"\u31b7","\u3400"-"\u4db5","\u4e00"-"\u9fa5","\ua000"-"\ua48c","\uac00"-"\ud7a3",
|
||||
"\u31a0"-"\u31b7","\u3400"-"\u4db5","\u4e00"-"\u9fa5","\ua000"-"\ua48c","\ua490"-"\uabff","\uac00"-"\ud7a3",
|
||||
"\uf900"-"\ufa2d","\ufb00"-"\ufb06","\ufb13"-"\ufb17","\ufb1d","\ufb1f"-"\ufb28",
|
||||
"\ufb2a"-"\ufb36","\ufb38"-"\ufb3c","\ufb3e","\ufb40"-"\ufb41","\ufb43"-"\ufb44",
|
||||
"\ufb46"-"\ufbb1","\ufbd3"-"\ufd3d","\ufd50"-"\ufd8f","\ufd92"-"\ufdc7","\ufdf0"-"\ufdfb",
|
||||
@ -865,7 +872,7 @@ TOKEN :
|
||||
"\u12f0"-"\u130e","\u1310","\u1312"-"\u1315","\u1318"-"\u131e","\u1320"-"\u1346",
|
||||
"\u1348"-"\u135a","\u1369"-"\u1371","\u13a0"-"\u13f4","\u1401"-"\u166c","\u166f"-"\u1676",
|
||||
"\u1681"-"\u169a","\u16a0"-"\u16ea","\u1780"-"\u17d3","\u17db","\u17e0"-"\u17e9",
|
||||
"\u180b"-"\u180e","\u1810"-"\u1819","\u1820"-"\u1877","\u1880"-"\u18a9","\u1e00"-"\u1e9b",
|
||||
"\u180b"-"\u180e","\u1810"-"\u1819","\u1820"-"\u1877","\u1880"-"\u18a9","\u1d00"-"\u1d7f","\u1e00"-"\u1e9b",
|
||||
"\u1ea0"-"\u1ef9","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d",
|
||||
"\u1f50"-"\u1f57","\u1f59","\u1f5b","\u1f5d","\u1f5f"-"\u1f7d","\u1f80"-"\u1fb4",
|
||||
"\u1fb6"-"\u1fbc","\u1fbe","\u1fc2"-"\u1fc4","\u1fc6"-"\u1fcc","\u1fd0"-"\u1fd3",
|
||||
@ -876,6 +883,7 @@ TOKEN :
|
||||
"\u2160"-"\u2183","\u3005"-"\u3007","\u3021"-"\u302f","\u3031"-"\u3035","\u3038"-"\u303a",
|
||||
"\u3041"-"\u3094","\u3099"-"\u309a","\u309d"-"\u309e","\u30a1"-"\u30fe","\u3105"-"\u312c",
|
||||
"\u3131"-"\u318e","\u31a0"-"\u31b7","\u3400"-"\u4db5","\u4e00"-"\u9fa5","\ua000"-"\ua48c",
|
||||
"\ua490"-"\uabff",
|
||||
"\uac00"-"\ud7a3","\uf900"-"\ufa2d","\ufb00"-"\ufb06","\ufb13"-"\ufb17","\ufb1d"-"\ufb28",
|
||||
"\ufb2a"-"\ufb36","\ufb38"-"\ufb3c","\ufb3e","\ufb40"-"\ufb41","\ufb43"-"\ufb44",
|
||||
"\ufb46"-"\ufbb1","\ufbd3"-"\ufd3d","\ufd50"-"\ufd8f","\ufd92"-"\ufdc7","\ufdf0"-"\ufdfb",
|
||||
@ -1335,7 +1343,7 @@ private void ConstructorBlock() #Block:
|
||||
}
|
||||
|
||||
void ExplicitConstructorInvocation() :
|
||||
{inExplicitConstructorInvoc = true;}
|
||||
{boolean prev = inExplicitConstructorInvoc; inExplicitConstructorInvoc = true;}
|
||||
{
|
||||
// We may only lookahead one token here, because:
|
||||
// * "this" or "super" can't appear in the primary expression in case of
|
||||
@ -1350,7 +1358,7 @@ void ExplicitConstructorInvocation() :
|
||||
| PrimaryExpression() "." [ TypeArguments() ] "super" {jjtThis.setIsSuper();}
|
||||
)
|
||||
// reset this before parsing the arguments list
|
||||
{inExplicitConstructorInvoc = false;}
|
||||
{inExplicitConstructorInvoc = prev;}
|
||||
ArgumentList() ";"
|
||||
}
|
||||
|
||||
@ -1711,7 +1719,9 @@ void EqualityExpression() #void:
|
||||
void Pattern() #void:
|
||||
{}
|
||||
{
|
||||
PrimaryPattern() [ GuardedPatternCondition() #GuardedPattern(2) ]
|
||||
LOOKAHEAD((Annotation())* ReferenceType() "(") RecordPattern()
|
||||
| LOOKAHEAD("(") ParenthesizedPattern()
|
||||
| TypePattern() [ LOOKAHEAD({getToken(1).kind == SC_AND && jdkVersion < 19}) GuardedPatternCondition() #GuardedPattern(2) ]
|
||||
}
|
||||
|
||||
void GuardedPatternCondition() #void:
|
||||
@ -1720,29 +1730,55 @@ void GuardedPatternCondition() #void:
|
||||
"&&" ConditionalAndExpression()
|
||||
}
|
||||
|
||||
void PrimaryPattern() #void:
|
||||
void ParenthesizedPattern() #void:
|
||||
{}
|
||||
{
|
||||
"(" Pattern() ")" { AstImplUtil.bumpParenDepth((ASTPattern) jjtree.peekNode()); }
|
||||
| LOOKAHEAD({true}) TypePattern()
|
||||
"(" Pattern() ")" { AstImplUtil.bumpParenDepth((ASTPattern) jjtree.peekNode()); }
|
||||
}
|
||||
|
||||
void TypePattern():
|
||||
{}
|
||||
{
|
||||
LocalVarModifierList() ReferenceType() VariableDeclaratorId()
|
||||
LocalVarModifierList() FormalParamType() VariableDeclaratorId()
|
||||
}
|
||||
|
||||
void RecordPattern():
|
||||
{}
|
||||
{
|
||||
(Annotation())* ReferenceType() RecordStructurePattern() [ VariableDeclaratorId() ]
|
||||
}
|
||||
|
||||
void RecordStructurePattern() #ComponentPatternList:
|
||||
{}
|
||||
{
|
||||
"(" [ RecordComponentPatternList() ] ")"
|
||||
}
|
||||
|
||||
void RecordComponentPatternList() #void:
|
||||
{}
|
||||
{
|
||||
Pattern() ( "," Pattern() )*
|
||||
}
|
||||
|
||||
void InstanceOfExpression() #void:
|
||||
{}
|
||||
{
|
||||
RelationalExpression() [
|
||||
LOOKAHEAD(1)
|
||||
("instanceof"
|
||||
(
|
||||
|
||||
AnnotatedRefType() [ VariableDeclaratorId() #TypePattern(2) ]
|
||||
| PrimaryPattern()
|
||||
LOOKAHEAD(ReferenceType() "(") RecordPattern()
|
||||
| AnnotatedRefType() [
|
||||
VariableDeclaratorId() #TypePattern(2)
|
||||
| RecordStructurePattern() #RecordPattern(2)
|
||||
[ VariableDeclaratorId()
|
||||
{
|
||||
AbstractJavaNode id = jjtree.popNode();
|
||||
ASTRecordPattern pat = (ASTRecordPattern) jjtree.peekNode();
|
||||
pat.addChild(id, pat.getNumChildren());
|
||||
}
|
||||
]
|
||||
]
|
||||
| Pattern()
|
||||
)
|
||||
{
|
||||
jjtThis.setOp(BinaryOp.INSTANCEOF);
|
||||
@ -1757,7 +1793,7 @@ void InstanceOfExpression() #void:
|
||||
}
|
||||
jjtree.pushNode(top);
|
||||
}
|
||||
{} // seems to be important?
|
||||
{} // manipulate node before it is closed.
|
||||
) #InfixExpression(2)
|
||||
]
|
||||
}
|
||||
@ -2158,7 +2194,6 @@ void QualifiedAllocationExpr() #ConstructorCall(jjtree.nodeArity() + 1):
|
||||
AnnotatedClassOrInterfaceType()
|
||||
ArgumentList()
|
||||
[ AnonymousClassDeclaration() ]
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -2440,11 +2475,25 @@ void CaseLabelElement(ASTSwitchLabel label) #void:
|
||||
AbstractJavaNode top = jjtree.popNode();
|
||||
top = new ASTPatternExpression((ASTPattern) top);
|
||||
jjtree.pushNode(top);
|
||||
}
|
||||
} ( LOOKAHEAD({isKeyword("when")}) Guard() )*
|
||||
|
|
||||
ConditionalExpression()
|
||||
}
|
||||
|
||||
void Guard() #SwitchGuard:
|
||||
{
|
||||
Token t;
|
||||
}
|
||||
{
|
||||
t = <IDENTIFIER> {
|
||||
if (!"when".equals(t.image)) {
|
||||
throw new ParseException("ERROR: expected 'when'");
|
||||
}
|
||||
}
|
||||
|
||||
Expression()
|
||||
}
|
||||
|
||||
void YieldStatement() :
|
||||
{ }
|
||||
{
|
||||
@ -2675,7 +2724,7 @@ void MemberValue() #void:
|
||||
void MemberValueArrayInitializer():
|
||||
{}
|
||||
{
|
||||
"{" (MemberValue() ( LOOKAHEAD(2) "," MemberValue() )* [ "," ])? "}"
|
||||
"{" (MemberValue() ( LOOKAHEAD(2) "," MemberValue() )*)? [ "," ] "}"
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user