Esempio n. 1
0
        public static FunctionDef ParseFunctionTail(ParserState s, NamespaceDef parent, Token name)
        {
            var func = new FunctionDef {
                Name = name, Unit = s.Unit, Parent = parent, Params = new List <Param>()
            };

            func.TypeParams = TryParseTypeParams(s);
            ParseTokenWithType(s, TokenType.OpenParen);
            while (s.Token.Type != TokenType.CloseParen)
            {
                func.Params.Add(ParseParam(s));
                if (s.Token.Type == TokenType.CloseParen)
                {
                    break;
                }
                ParseTokenWithType(s, TokenType.Comma);
            }
            ParseTokenWithType(s, TokenType.CloseParen);
            if (s.Token.Type == TokenType.Identifier || (s.Token.Type == TokenType.Operator && (s.Token.Value == "*" || s.Token.Value == "$" || s.Token.Value == "::")))
            {
                func.ReturnType = ParseType(s);
            }
            s.ForeignAttribute = false;
            func.Attributes    = TryParseAttributes(s);
            if (!s.ForeignAttribute)
            {
                func.Body = ParseBlockStatement(s);
            }
            return(func);
        }
Esempio n. 2
0
 public static void CheckFunctionDef(RangeFinderState s, FunctionDef a)
 {
     CheckToken(s, a.Name);
     foreach (var p in a.Params)
     {
         CheckToken(s, p.Name);
         CheckAny(s, p.Type);
     }
     CheckAny(s, a.ReturnType);
     CheckList(s, a.Attributes);
     CheckAny(s, a.Body);
 }
Esempio n. 3
0
 public static void PrintFunctionDef(PrintState s, FunctionDef a)
 {
     PrintDescWithToken(s, "FunctionDef", a.Name);
     Indent(s);
     PrintLine(s, "Params:");
     Indent(s);
     foreach (var p in a.Params)
     {
         PrintToken(s, p.Name);
         Indent(s);
         PrintAny(s, p.Type);
         UnIndent(s);
     }
     UnIndent(s);
     PrintDescWithAny(s, "ReturnType", a.ReturnType);
     PrintDescWithList(s, "Attributes", a.Attributes);
     PrintDescWithAny(s, "Body", a.Body);
     UnIndent(s);
 }