Parse command-line syntax

This commit is contained in:
Alexander Luzgarev 2018-04-05 09:32:53 +02:00
parent 215e0b52ed
commit 3d31b2c04b
3 changed files with 54 additions and 0 deletions

View File

@ -347,6 +347,21 @@ namespace Parser
var operation = Factory.Token(EatToken()); var operation = Factory.Token(EatToken());
expression = Factory.UnaryPostfixOperationExpression(expression, operation); expression = Factory.UnaryPostfixOperationExpression(expression, operation);
break; break;
case TokenKind.UnquotedStringLiteral:
if (expression is IdentifierNameNode idNameNode)
{
var arguments = new List<UnquotedStringLiteralNode>();
while (CurrentToken.Kind == TokenKind.UnquotedStringLiteral)
{
arguments.Add(Factory.UnquotedStringLiteral(EatToken()));
}
return Factory.CommandExpression(idNameNode, arguments);
}
else
{
throw new ParsingException($"Unexpected token \"{CurrentToken.PureToken.LiteralText}\" during parsing expression \"{expression.FullText}\" at {CurrentToken.PureToken.Position}.");
}
default: default:
return expression; return expression;
} }

View File

@ -256,6 +256,12 @@ namespace Parser
return new DoubleQuotedStringLiteralNode(stringLiteral); return new DoubleQuotedStringLiteralNode(stringLiteral);
} }
public UnquotedStringLiteralNode UnquotedStringLiteral(
Token stringLiteral)
{
return new UnquotedStringLiteralNode(stringLiteral);
}
public ExpressionStatementNode ExpressionStatement(ExpressionNode expression) public ExpressionStatementNode ExpressionStatement(ExpressionNode expression)
{ {
var children = new List<SyntaxNode> {expression}; var children = new List<SyntaxNode> {expression};
@ -648,5 +654,22 @@ namespace Parser
SetParent(result); SetParent(result);
return result; return result;
} }
public CommandExpressionNode CommandExpression(
IdentifierNameNode identifierName,
List<UnquotedStringLiteralNode> arguments)
{
var children = new List<SyntaxNode>
{
identifierName
};
children.AddRange(arguments);
var result = new CommandExpressionNode(
children,
identifierName,
arguments);
SetParent(result);
return result;
}
} }
} }

View File

@ -704,4 +704,20 @@ namespace Parser
EndKeyword = endKeyword; EndKeyword = endKeyword;
} }
} }
public class CommandExpressionNode : ExpressionNode
{
public IdentifierNameNode CommandName { get; }
public List<UnquotedStringLiteralNode> Arguments { get; }
public CommandExpressionNode(
List<SyntaxNode> children,
IdentifierNameNode commandName,
List<UnquotedStringLiteralNode> arguments
) : base(children)
{
CommandName = commandName;
Arguments = arguments;
}
}
} }