Skip to content

Commit

Permalink
Fixed bug with parsing named parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysparks committed Feb 3, 2015
1 parent ea87b8e commit 50da310
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/leola/frontend/parsers/ExprParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,21 @@ public class ExprParser extends StmtParser {
private static final EnumSet<LeolaTokenType> CHAINED_OP =
EnumSet.of(DOT, LEFT_PAREN, LEFT_BRACKET/*, IDENTIFIER*/);

private boolean isMapDeclaration;

/**
/**
* @param parser
*/
public ExprParser(LeolaParser parser) {
this(parser, false);
}

/**
* @param parser
*/
public ExprParser(LeolaParser parser, boolean isMapDeclaration) {
super(parser);
this.isMapDeclaration = isMapDeclaration;
}

/**
Expand Down Expand Up @@ -575,8 +584,17 @@ protected ASTNode parseIdentifier(Token token)
break;
}
case ARROW: {
NamedParameterExprParser parser = new NamedParameterExprParser(this);
result = parser.parse(token);

/* if this is a map declaration, then this
* is just a variable, otherwise it is a Named Parameter
*/
if(this.isMapDeclaration) {
result = new VarExpr(token.getText());
}
else {
NamedParameterExprParser parser = new NamedParameterExprParser(this);
result = parser.parse(token);
}
break;
}
case PLUS_EQ:
Expand Down
2 changes: 1 addition & 1 deletion src/leola/frontend/parsers/ParserUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static List<Pair<Expr, Expr>> parseMapParameters(StmtParser parser
, EnumSet<LeolaTokenType> commaDelimeter
, LeolaTokenType endToken) throws Exception
{
ExprParser expressionParser = new ExprParser(parser);
ExprParser expressionParser = new ExprParser(parser, true);

Token token = parser.nextToken(); // consume opening token

Expand Down

0 comments on commit 50da310

Please sign in to comment.