本文整理汇总了C#中Parser.Match方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.Match方法的具体用法?C# Parser.Match怎么用?C# Parser.Match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.Match方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public Expression Parse(Parser parser, Token token)
{
var values = new List<KeyValuePair<string, Expression>>();
while (!parser.Match(TokenType.RightBrace))
{
var identifier = parser.Take(TokenType.Identifier);
Expression value;
if (parser.Match(TokenType.Comma) || parser.Match(TokenType.RightBrace))
{
value = new IdentifierExpression(identifier);
}
else
{
parser.Take(TokenType.Colon);
value = parser.ParseExpession();
}
values.Add(new KeyValuePair<string, Expression>(identifier.Contents, value));
if (!parser.Match(TokenType.Comma))
break;
parser.Take(TokenType.Comma);
}
parser.Take(TokenType.RightBrace);
return new ObjectExpression(token, values);
}
示例2: ParseBlock
private static BlockExpression ParseBlock(Parser parser)
{
var statements = new List<Expression>();
while (!parser.Match(TokenType.Case) &&
!parser.Match(TokenType.Default) &&
!parser.Match(TokenType.RightBrace))
{
statements.Add(parser.ParseStatement());
}
return new ScopeExpression(statements);
}
示例3: Parse
public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
{
trailingSemicolon = false;
string name = null;
var arguments = new List<string>();
BlockExpression body;
// optional name
if (parser.Match(TokenType.Identifier))
{
name = parser.Take(TokenType.Identifier).Contents;
}
// parse argument list
parser.Take(TokenType.LeftParen);
if (!parser.Match(TokenType.RightParen))
{
while (true)
{
var identifier = parser.Take(TokenType.Identifier);
arguments.Add(identifier.Contents);
if (parser.Match(TokenType.RightParen))
break;
parser.Take(TokenType.Comma);
}
}
parser.Take(TokenType.RightParen);
// parse body
if (parser.MatchAndTake(TokenType.Pointy))
{
body = new BlockExpression(new List<Expression>
{
new ReturnExpression(token, parser.ParseExpession())
});
}
else
{
body = parser.ParseBlock(false);
}
return new FunctionExpression(token, name, arguments, body);
}
示例4: Parse
public override Expression Parse(Parser p, Expression left, Token t)
{
var exp = new CallExpr();
exp.CallTargetExpr = left;
exp.Position = left.Position;
if (p.Match(TokenType.RParen))
return exp;
do
{
exp.ArgumentExprs.Add(p.ParseExpression());
} while (p.Match(TokenType.Comma));
p.Consume(TokenType.RParen);
return exp;
}
示例5: Parse
public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
{
trailingSemicolon = false;
parser.Take(TokenType.LeftParen);
Expression initializer = null;
if (!parser.Match(TokenType.Semicolon))
initializer = parser.ParseStatement(false);
if (initializer is IBlockStatementExpression)
throw new MondCompilerException(token.FileName, token.Line, "For loop initializer can not be block statement");
parser.Take(TokenType.Semicolon);
Expression condition = null;
if (!parser.Match(TokenType.Semicolon))
condition = parser.ParseExpession();
parser.Take(TokenType.Semicolon);
BlockExpression increment = null;
if (!parser.Match(TokenType.RightParen))
{
var statements = new List<Expression>();
do
{
statements.Add(parser.ParseStatement(false));
if (!parser.Match(TokenType.Comma))
break;
parser.Take(TokenType.Comma);
} while (true);
increment = new BlockExpression(token, statements);
}
parser.Take(TokenType.RightParen);
var block = new ScopeExpression(parser.ParseBlock());
return new ForExpression(token, initializer, condition, increment, block);
}
示例6: Parse
public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
{
trailingSemicolon = true;
Expression value = null;
if (!parser.Match(TokenType.Semicolon))
value = parser.ParseExpession();
return new ReturnExpression(token, value);
}
示例7: Parse
public IExpression Parse(Parser parser, IExpression left, Token token)
{
// Parse the comma-separated arguments until we hit, ")".
var args = new List<IExpression>();
// There may be no arguments at all.
if (!parser.Match(TokenType.RightParen))
{
do
{
args.Add(parser.ParseExpression());
}
while (parser.Match(TokenType.Comma));
parser.Consume(TokenType.RightParen);
}
return new CallExpression(left, args);
}
示例8: Parse
public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
{
trailingSemicolon = false;
parser.Take(TokenType.LeftParen);
var expression = parser.ParseExpession();
parser.Take(TokenType.RightParen);
parser.Take(TokenType.LeftBrace);
var branches = new List<SwitchExpression.Branch>();
BlockExpression defaultBlock = null;
while (!parser.Match(TokenType.RightBrace))
{
var conditions = new List<Expression>();
while (parser.MatchAndTake(TokenType.Case))
{
var condition = parser.ParseExpession();
conditions.Add(condition);
parser.Take(TokenType.Colon);
}
if (conditions.Count > 0)
{
var block = ParseBlock(parser);
var branch = new SwitchExpression.Branch(conditions, block);
branches.Add(branch);
continue;
}
if (parser.MatchAndTake(TokenType.Default))
{
parser.Take(TokenType.Colon);
var block = ParseBlock(parser);
defaultBlock = block;
break;
}
var errorToken = parser.Peek();
throw new MondCompilerException(errorToken.FileName, errorToken.Line, "Expected Case or Default but got {0}", errorToken.Type);
}
parser.Take(TokenType.RightBrace);
return new SwitchExpression(token, expression, branches, defaultBlock);
}
示例9: Parse
public Expression Parse(Parser parser, Token token, out bool trailingSemicolon)
{
trailingSemicolon = false;
var statements = new List<Expression>();
while (!parser.Match(TokenType.RightBrace))
{
statements.Add(parser.ParseStatement());
}
parser.Take(TokenType.RightBrace);
return new ScopeExpression(statements);
}