示例#1
0
        public static FunctionHeader Header(MatchIterator iterator)
        {
            iterator.AssertTokenType(TokenType.Type, out Token typeToken);
            iterator.AssertTokenType(TokenType.Name, out Token nameToken);
            iterator.AssertKeySymbol(Symbols.OpenBracket, out _);
            Token open = (Token)iterator.Current;

            CollectedParameters parameters;

            if (iterator.Next(out parameters))
            {
                iterator.MoveNext();
            }
            else
            {
                parameters = new CollectedParameters();
            }

            iterator.AssertKeySymbol(Symbols.CloseBracket, out _);
            Token end = (Token)iterator.Current;

            iterator.AssertEnd();

            FunctionTypeSignature typeSignature = new FunctionTypeSignature(parameters.Types);
            FunctionSignature     signature     = new FunctionSignature(
                FunctionSignature.Local, nameToken.Content, typeSignature);

            FunctionHeader result = new FunctionHeader(
                typeToken, nameToken, open, end, signature, parameters.Names);

            return(result);
        }
示例#2
0
        public static CollectedParameters Parameters(MatchIterator iterator)
        {
            List <SprakType>    parameterTypes = new List <SprakType>();
            List <string>       parameterNames = new List <string>();
            CollectedParameters result
                = new CollectedParameters(parameterTypes, parameterNames);

            if (iterator.AtEnd())
            {
                return(result);
            }

            do
            {
                iterator.AssertType(out SprakType type);
                iterator.AssertName(out string name);
                parameterTypes.Add(type);
                parameterNames.Add(name);
            }while (iterator.NextIsKeySymbol(Symbols.Comma));

            iterator.AssertEnd();

            return(result);
        }