Parse command-line syntax
This commit is contained in:
parent
215e0b52ed
commit
3d31b2c04b
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user