Skip to content

Commit

Permalink
Add review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
lochana-chathura committed Mar 21, 2022
1 parent c30d2bd commit 191a024
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18653,7 +18653,7 @@ private STNode getExpression(STNode ambiguousNode) {
return getExpression(ambiguousNode, false);
}

private STNode getExpression(STNode ambiguousNode, boolean isMappingConstructor) {
private STNode getExpression(STNode ambiguousNode, boolean isInMappingConstructor) {
if (isEmpty(ambiguousNode) ||
(isDefiniteExpr(ambiguousNode.kind) && ambiguousNode.kind != SyntaxKind.INDEXED_EXPRESSION) ||
isDefiniteAction(ambiguousNode.kind) || ambiguousNode.kind == SyntaxKind.COMMA_TOKEN) {
Expand Down Expand Up @@ -18692,13 +18692,12 @@ private STNode getExpression(STNode ambiguousNode, boolean isMappingConstructor)
innerList.collectionEndToken);
case REST_BINDING_PATTERN:
STRestBindingPatternNode restBindingPattern = (STRestBindingPatternNode) ambiguousNode;
if (isMappingConstructor) {
if (isInMappingConstructor) {
return STNodeFactory.createSpreadFieldNode(restBindingPattern.ellipsisToken,
restBindingPattern.variableName);
} else {
return STNodeFactory.createSpreadMemberNode(restBindingPattern.ellipsisToken,
restBindingPattern.variableName);
}
return STNodeFactory.createSpreadMemberNode(restBindingPattern.ellipsisToken,
restBindingPattern.variableName);
case SPECIFIC_FIELD:
// Specific field is used to represent ambiguous scenarios. Hence it needs to be re-written.
STSpecificFieldNode field = (STSpecificFieldNode) ambiguousNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,11 @@ public class BallerinaParserErrorHandler extends AbstractParserErrorHandler {
{ ParserRuleContext.BASIC_LITERAL, ParserRuleContext.VARIABLE_REF, ParserRuleContext.PLUS_TOKEN,
ParserRuleContext.MINUS_TOKEN, ParserRuleContext.NIL_LITERAL };

private static final ParserRuleContext[] LIST_CONSTRUCTOR_RHS =
{ ParserRuleContext.CLOSE_BRACKET, ParserRuleContext.EXPRESSION, ParserRuleContext.ELLIPSIS };
private static final ParserRuleContext[] LIST_CONSTRUCTOR_FIRST_MEMBER =
{ ParserRuleContext.CLOSE_BRACKET, ParserRuleContext.LIST_CONSTRUCTOR_MEMBER };

private static final ParserRuleContext[] LIST_CONSTRUCTOR_MEMBER =
{ ParserRuleContext.EXPRESSION, ParserRuleContext.ELLIPSIS };

private static final ParserRuleContext[] TYPE_CAST_PARAM =
{ ParserRuleContext.TYPE_DESC_IN_ANGLE_BRACKETS, ParserRuleContext.ANNOTATIONS };
Expand Down Expand Up @@ -1392,6 +1395,7 @@ protected boolean hasAlternativePaths(ParserRuleContext currentCtx) {
case CONSTANT_EXPRESSION_START:
case TYPE_DESC_RHS:
case LIST_CONSTRUCTOR_FIRST_MEMBER:
case LIST_CONSTRUCTOR_MEMBER:
case TYPE_CAST_PARAM:
case TYPE_CAST_PARAM_RHS:
case TABLE_KEYWORD_RHS:
Expand Down Expand Up @@ -1697,6 +1701,8 @@ protected ParserRuleContext getShortestAlternative(ParserRuleContext currentCtx)
return ParserRuleContext.END_OF_TYPE_DESC;
case LIST_CONSTRUCTOR_FIRST_MEMBER:
return ParserRuleContext.CLOSE_BRACKET;
case LIST_CONSTRUCTOR_MEMBER:
return ParserRuleContext.EXPRESSION;
case TYPE_CAST_PARAM:
case TYPE_CAST_PARAM_RHS:
return ParserRuleContext.TYPE_DESC_IN_ANGLE_BRACKETS;
Expand Down Expand Up @@ -2646,7 +2652,10 @@ private Result seekMatchInExprRelatedAlternativePaths(ParserRuleContext currentC
alternativeRules = CONSTANT_EXPRESSION;
break;
case LIST_CONSTRUCTOR_FIRST_MEMBER:
alternativeRules = LIST_CONSTRUCTOR_RHS;
alternativeRules = LIST_CONSTRUCTOR_FIRST_MEMBER;
break;
case LIST_CONSTRUCTOR_MEMBER:
alternativeRules = LIST_CONSTRUCTOR_MEMBER;
break;
case TYPE_CAST_PARAM:
alternativeRules = TYPE_CAST_PARAM;
Expand Down Expand Up @@ -4330,8 +4339,9 @@ private ParserRuleContext getNextRuleForComma() {
return ParserRuleContext.ARG_START;
case MAPPING_CONSTRUCTOR:
return ParserRuleContext.MAPPING_FIELD;
case LISTENERS_LIST:
case LIST_CONSTRUCTOR:
return ParserRuleContext.LIST_CONSTRUCTOR_MEMBER;
case LISTENERS_LIST:
case ORDER_KEY_LIST:
return ParserRuleContext.EXPRESSION;
case ANNOT_ATTACH_POINTS_LIST:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ public enum ParserRuleContext {
HEX_FLOATING_POINT_LITERAL_TOKEN("hex-floating-point-literal-token"),
LIST_CONSTRUCTOR("list-constructor"),
LIST_CONSTRUCTOR_FIRST_MEMBER("list-constructor-first-member"),
LIST_CONSTRUCTOR_MEMBER("list-constructor-member"),
TYPE_CAST("type-cast"),
TYPE_CAST_PARAM("type-cast-param"),
TYPE_CAST_PARAM_RHS("type-cast-param-rhs"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4785,37 +4785,31 @@
"hasDiagnostics": true,
"children": [
{
"kind": "MAPPING_BINDING_PATTERN",
"kind": "LIST_BINDING_PATTERN",
"hasDiagnostics": true,
"children": [
{
"kind": "OPEN_BRACE_TOKEN",
"kind": "OPEN_BRACKET_TOKEN",
"isMissing": true,
"hasDiagnostics": true,
"diagnostics": [
"ERROR_MISSING_OPEN_BRACE_TOKEN"
"ERROR_MISSING_OPEN_BRACKET_TOKEN"
]
},
{
"kind": "LIST",
"hasDiagnostics": true,
"children": [
{
"kind": "FIELD_BINDING_PATTERN",
"kind": "CAPTURE_BINDING_PATTERN",
"hasDiagnostics": true,
"children": [
{
"kind": "SIMPLE_NAME_REFERENCE",
"kind": "IDENTIFIER_TOKEN",
"isMissing": true,
"hasDiagnostics": true,
"children": [
{
"kind": "IDENTIFIER_TOKEN",
"isMissing": true,
"hasDiagnostics": true,
"diagnostics": [
"ERROR_MISSING_IDENTIFIER"
]
}
"diagnostics": [
"ERROR_MISSING_TYPE_DESC"
]
}
]
Expand Down Expand Up @@ -4876,15 +4870,39 @@
]
}
]
},
{
"kind": "COMMA_TOKEN",
"trailingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
}
]
},
{
"kind": "CAPTURE_BINDING_PATTERN",
"children": [
{
"kind": "IDENTIFIER_TOKEN",
"value": "a",
"trailingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
}
]
}
]
}
]
},
{
"kind": "CLOSE_BRACE_TOKEN",
"kind": "CLOSE_BRACKET_TOKEN",
"isMissing": true,
"hasDiagnostics": true,
"diagnostics": [
"ERROR_MISSING_CLOSE_BRACE_TOKEN"
"ERROR_MISSING_CLOSE_BRACKET_TOKEN"
]
}
]
Expand Down

0 comments on commit 191a024

Please sign in to comment.