public Declaration Parse(LoonyParser parser, LoonyToken token) { var start = token; var name = parser.Take(LoonyTokenType.Identifier); var parameters = new List <FuncDeclaration.Parameter>(); TypeBase returnType = null; parser.Take(LoonyTokenType.LeftParen); if (!parser.MatchAndTake(LoonyTokenType.RightParen)) { do { var paramName = parser.Take(LoonyTokenType.Identifier); parser.Take(LoonyTokenType.Colon); var paramType = parser.ParseType(); parameters.Add(new FuncDeclaration.Parameter(paramName, paramType)); } while (parser.MatchAndTake(LoonyTokenType.Comma)); parser.Take(LoonyTokenType.RightParen); } if (parser.MatchAndTake(LoonyTokenType.Colon)) { returnType = parser.ParseType(); } var body = parser.ParseBlock(false); var end = parser.Previous; return(new FuncDeclaration(start, end, name, parameters, returnType, body)); }
public Declaration Parse(LoonyParser parser, LoonyToken token) { var start = token; var name = parser.Take(LoonyTokenType.Identifier); var parameters = new List<FuncDeclaration.Parameter>(); TypeBase returnType = null; parser.Take(LoonyTokenType.LeftParen); if (!parser.MatchAndTake(LoonyTokenType.RightParen)) { do { var paramName = parser.Take(LoonyTokenType.Identifier); parser.Take(LoonyTokenType.Colon); var paramType = parser.ParseType(); parameters.Add(new FuncDeclaration.Parameter(paramName, paramType)); } while (parser.MatchAndTake(LoonyTokenType.Comma)); parser.Take(LoonyTokenType.RightParen); } if (parser.MatchAndTake(LoonyTokenType.Colon)) returnType = parser.ParseType(); var body = parser.ParseBlock(false); var end = parser.Previous; return new FuncDeclaration(start, end, name, parameters, returnType, body); }
public Statement Parse(LoonyParser parser, LoonyToken token, out bool trailingSemicolon) { trailingSemicolon = true; var name = parser.Take(LoonyTokenType.Identifier).Contents; TypeBase type = null; Expression initializer = null; if (parser.MatchAndTake(LoonyTokenType.Colon)) { type = parser.ParseType(); } if (type == null) { parser.Take(LoonyTokenType.Assign); initializer = parser.ParseExpression(); } else if (parser.MatchAndTake(LoonyTokenType.Assign)) { initializer = parser.ParseExpression(); } return(new VariableStatement(token, parser.Previous, name, type, initializer)); }
public Expression Parse(LoonyParser parser, LoonyToken token) { var expression = parser.ParseExpression(); parser.Take(LoonyTokenType.RightParen); return(expression); }
public Statement Parse(LoonyParser parser, LoonyToken token, out bool trailingSemicolon) { trailingSemicolon = true; var name = parser.Take(LoonyTokenType.Identifier).Contents; TypeBase type = null; Expression initializer = null; if (parser.MatchAndTake(LoonyTokenType.Colon)) type = parser.ParseType(); if (type == null) { parser.Take(LoonyTokenType.Assign); initializer = parser.ParseExpression(); } else if (parser.MatchAndTake(LoonyTokenType.Assign)) { initializer = parser.ParseExpression(); } return new VariableStatement(token, parser.Previous, name, type, initializer); }
public Expression Parse(LoonyParser parser, LoonyToken token) { var expression = parser.ParseExpression(); parser.Take(LoonyTokenType.RightParen); return expression; }