public override IASTNode Parse(IASTNodeFactory nodeFactory, IAParser aParser, ATokens tokens) { tokens.GetNextToken(); while (tokens.CurrentToken != null && !aParser.Acceptable(tokens, ASTEndParenthesesNode.KeyWord)) { IASTNode newNode = aParser.NodeFactory.CreateNode(tokens.CurrentToken.Text, tokens.CurrentToken.AddSpace); newNode.Parse(aParser.NodeFactory, aParser, tokens); SubNodes.Add(newNode); } if (!aParser.Acceptable(tokens, ASTEndParenthesesNode.KeyWord)) { throw new AParserException("Didn't find closing parentheses"); } SubNodes.Add(aParser.Accept(tokens, ASTEndParenthesesNode.KeyWord)); return(this); }
public IASTNode Accept(ATokens tokens, string text) { if (tokens.CurrentToken == null) { throw new AParserException(string.Format("Expected token '{0}' but current token is empty", text)); } if (text != tokens.CurrentToken.Text.ToLower()) { throw new AParserException(string.Format("Expected token '{0}' but found '{1}'", text, tokens.CurrentToken.Text.ToLower())); } IASTNode node = NodeFactory.CreateNode(tokens.CurrentToken.Text, tokens.CurrentToken.AddSpace); node.AddSpace = tokens.CurrentToken.AddSpace; tokens.GetNextToken(); return(node); }