本文整理汇总了C#中Parser.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.Peek方法的具体用法?C# Parser.Peek怎么用?C# Parser.Peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.Peek方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public override Statement Parse(Parser parser, Lexer.Token current)
{
string name = null;
if (parser.Peek().Type == "IDENTIFIER")
{
name = parser.Current.Lexeme;
parser.Consume("IDENTIFIER");
}
parser.Consume("LEFTPAREN");
var parameters = ParseParameterList(parser).ToArray();
parser.Consume("RIGHTPAREN");
var token = parser.Peek();
if (token.Type == "LEFTBRACE")
{
var body = parser.ParseNext();
return new FunctionDefinitionExpr(new IdentifierExpr(name), parameters, (Statement)body,
new IdentifierExpr("UNKNOWN"));
}
else if (token.Type == "RIGHTARROW")
{
parser.Consume("RIGHTARROW");
var body = parser.ParseExpression(0);
parser.Consume("SEMICOLON");
return new LambdaDefinitionExpr(new IdentifierExpr(name), parameters, body,
new IdentifierExpr("UNKNOWN"));
}
throw new ParseException("Malformed function defintion");
}
示例2: ParseArguments
private IEnumerable<Expression> ParseArguments(Parser parser)
{
if (parser.Peek().Type == "RIGHTPAREN")
yield break;
while (true)
{
yield return parser.ParseExpression(0);
if (parser.Peek().Type == "RIGHTPAREN")
yield break;
parser.Consume("COMMA");
}
}
示例3: 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);
}
示例4: ParseParameterList
private List<VarDefinitionStmt> ParseParameterList(Parser parser)
{
var parameters = new List<VarDefinitionStmt>();
if (parser.Peek().Type == "RIGHTPAREN")
return parameters;
while (true)
{
var name = parser.ParseExpression(0);
if(!(name is IdentifierExpr))
throw new ParseException("Expected parameter name");
Expression type = null;
if (parser.ConsumeOptional("COLON"))
{
type = parser.ParseExpression(0);
if (!(type is IdentifierExpr))
throw new ParseException("Expected parameter type");
}
else
{
type = new IdentifierExpr("dynamic");
}
parameters.Add(new VarDefinitionStmt((IdentifierExpr)name, (IdentifierExpr)type, false, null));
if (parser.Peek().Type == "RIGHTPAREN")
break;
parser.Consume("COMMA");
}
return parameters;
}
示例5: Parse
public override Statement Parse(Parser parser, Lexer.Token current)
{
var name = parser.Current.Lexeme;
parser.Consume("IDENTIFIER");
string type = null;
if (parser.Peek().Type == "COLON")
type = ParseTypeSpecified(parser);
Expression initialValue = null;
if (parser.ConsumeOptional("ASSIGNMENT"))
initialValue = parser.ParseExpression(0);
else if(_constVariables)
throw new ParseException("Const variable declarations must have an initialiser.");
parser.Consume("SEMICOLON");
return new VarDefinitionStmt(new IdentifierExpr(name), new IdentifierExpr(type), _constVariables, initialValue);
}