public LookupNode(SourcePosition pos, VariableNode variableNode, Node keyNode) : base(pos) { this.variableNode = variableNode; this.keyNode = keyNode; }
private Node Variable() { // VARIABLE_DEF VARIABLE ASSIGN Token variable = Match(TokenType.VARIABLE); VariableNode varNode = new VariableNode(variable.Position, variable.Text); TokenType next = LookAhead(1); if (next == TokenType.LBRACKET) { SourcePosition pos = Match(TokenType.LBRACKET).Position; Node key = Expression(); Match(TokenType.RBRACKET); return new LookupNode(pos, varNode, key); } else if (LookAhead(1) == TokenType.PERIOD) { Match(TokenType.PERIOD); PropertyTreeNode propertyTree = new PropertyTreeNode(varNode.Position, varNode, Property()); if (LookAhead(1) == TokenType.END_STATEMENT) { Match(TokenType.END_STATEMENT); } return propertyTree; } else if (LookAhead(1) == TokenType.COLON) { PropertyNode property = new PropertyNode(variable.Position, variable.Text); Match(TokenType.COLON); Node value = Expression(); if (LookAhead(1) == TokenType.COMMA) Match(TokenType.COMMA); return new AssignNode(property.Position, property, value, true); } else { return varNode; } }
private Node Parameter() { // variable (ASSIGN^ expression)? Token t = Match(TokenType.VARIABLE); VariableNode variable = new VariableNode(t.Position, t.Text); if (LookAhead(1) == TokenType.ASSIGN) { SourcePosition pos = Match(TokenType.ASSIGN).Position; Node e = Expression(); return new AssignNode(pos, variable, e, true); } return variable; }
private CatchNode Catch() { SourcePosition pos = Match(TokenType.CATCH).Position; VariableNode errorVariable = null; if (LookAhead(1) == TokenType.LPAREN) { Match(TokenType.LPAREN); Token variable = Match(TokenType.VARIABLE); errorVariable = new VariableNode(variable.Position, variable.Text); Match(TokenType.RPAREN); } BlockNode catchBlock = Block(); return new CatchNode(pos, errorVariable, catchBlock); }
public CatchNode(SourcePosition pos, VariableNode errorVariable, BlockNode catchBlock) : base(pos) { this.errorVariable = errorVariable; this.catchBlock = catchBlock; }