private Decl.Function parseFunction() { ParserState ps = new ParserState(this); Decl.Function rst = new Decl.Function(); if (peek().Type == DeclTokenType.Comment) { rst.Desc = peek().Data; m_pos++; } if (peek().Type == DeclTokenType.KW_Static) { rst.isStatic = true; m_pos++; } if (peek().Type != DeclTokenType.Identifier) { ps.restore(); return(null); } string id1 = peek().Data; m_pos++; if (peek().Type == DeclTokenType.Identifier) { rst.type = id1; rst.name = peek().Data; m_pos++; } else { rst.name = id1; } if (peek().Type != DeclTokenType.OP_LParen) { ps.restore(); return(null); } m_pos++; Decl.Variable var = parseVariable(); if (var != null) { rst.parameters.Add(var); while (peek().Type == DeclTokenType.OP_Comma) { m_pos++; Decl.Variable moreVar = parseVariable(); if (moreVar == null) { throw new System.Exception("Line " + peek().Line + ": variable expected"); } rst.parameters.Add(moreVar); } } if (peek().Type != DeclTokenType.OP_RParen) { throw new System.Exception("')' expected"); } m_pos++; return(rst); }
private Decl.Function parseFunction() { ParserState ps = new ParserState(this); Decl.Function rst = new Decl.Function(); if (peek().Type == DeclTokenType.Comment) { rst.Desc = peek().Data; m_pos++; } if (peek().Type == DeclTokenType.KW_Static) { rst.isStatic = true; m_pos++; } if (peek().Type != DeclTokenType.Identifier) { ps.restore(); return null; } string id1 = peek().Data; m_pos++; if (peek().Type == DeclTokenType.Identifier) { rst.type = id1; rst.name = peek().Data; m_pos++; } else { rst.name = id1; } if (peek().Type != DeclTokenType.OP_LParen) { ps.restore(); return null; } m_pos++; Decl.Variable var = parseVariable(); if (var != null) { rst.parameters.Add(var); while (peek().Type == DeclTokenType.OP_Comma) { m_pos++; Decl.Variable moreVar = parseVariable(); if (moreVar == null) { throw new System.Exception("Line " + peek().Line + ": variable expected"); } rst.parameters.Add(moreVar); } } if (peek().Type != DeclTokenType.OP_RParen) { throw new System.Exception("')' expected"); } m_pos++; return rst; }