-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[new-parser] Support LHS pattern annotations #5797
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,7 @@ lhsPattern : xpathPrimary (OVER patternFilter)? | | |
( QUESTION? qualifiedIdentifier LPAREN positionalConstraints? constraints? RPAREN (OVER patternFilter)? (FROM patternSource)? ) ; | ||
*/ | ||
|
||
lhsPattern : QUESTION? objectType=drlQualifiedName LPAREN positionalConstraints? constraints? RPAREN (DRL_OVER patternFilter)? (DRL_FROM patternSource)? ; | ||
lhsPattern : QUESTION? objectType=drlQualifiedName LPAREN positionalConstraints? constraints? RPAREN drlAnnotation* (DRL_OVER patternFilter)? (DRL_FROM patternSource)? ; | ||
positionalConstraints : constraint (COMMA constraint)* SEMI ; | ||
constraints : constraint (COMMA constraint)* ; | ||
constraint : ( nestedConstraint | conditionalOrExpression ) ; | ||
|
@@ -459,7 +459,7 @@ type : (classOrInterfaceType | primitiveType) typeArguments? ( DOT IDENTIFIER ty | |
drlArguments : LPAREN drlArgument (COMMA drlArgument)* RPAREN ; | ||
drlArgument : ( stringId | floatLiteral | BOOL_LITERAL | NULL_LITERAL ) ; | ||
|
||
drlAnnotation : AT name=drlQualifiedName (LPAREN ( drlElementValuePairs | drlElementValue )? RPAREN)? ; | ||
drlAnnotation : AT name=drlQualifiedName ((LPAREN ( drlElementValuePairs | drlElementValue )? RPAREN) | chunk)? ; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allows an annotation value to be something that doesn't fit into the standard Java annotation key-value format, for example, |
||
|
||
drlElementValuePairs : drlElementValuePair (COMMA drlElementValuePair)* ; | ||
drlElementValuePair : key=drlIdentifier ASSIGN value=drlElementValue ; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,31 @@ private ParserStringUtils() { | |
// Private constructor to prevent instantiation. | ||
} | ||
|
||
/** | ||
* Strip string delimiters (e.g. "foo" -> foo) | ||
*/ | ||
public static String safeStripStringDelimiters(String value) { | ||
if (value != null) { | ||
value = value.trim(); | ||
if (value.length() >= 2 && value.startsWith("\"") && value.endsWith("\"")) { | ||
value = value.substring(1, value.length() - 1); | ||
} | ||
} | ||
return value; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is used by both the old parser and the new parser's visitor. |
||
|
||
public static String safeStripDelimiters(String value, String left, String right) { | ||
if (value != null) { | ||
value = value.trim(); | ||
if (value.length() >= left.length() + right.length() && | ||
value.startsWith(left) && value.endsWith(right)) { | ||
value = value.substring(left.length(), | ||
value.length() - right.length()); | ||
} | ||
} | ||
return value; | ||
} | ||
|
||
/** | ||
* Append a prefix to a grouped constraint. | ||
* Even if the constraint contains || and/or &&, append the prefix to each element. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows an annotation to appear after a LHS pattern, for example,
Person() @watch(!age)
.