Пример #1
0
        public static FORMAL_NONTYPE parse(Token id, iSCOPE context)
        {
            Debug.Indent();
            Debug.WriteLine("Entering FORMAL_NONTYPE.parse");

            // parameter name is passed via 'id'.
            // ':' is already eaten.

            FORMAL_NONTYPE generic_nontype_par = new FORMAL_NONTYPE(id);

            TYPE type = TYPE.parse(context);

            generic_nontype_par.type = type;
            type.parent = generic_nontype_par;

            Debug.WriteLine("Exiting FORMAL_NONTYPE.parse");
            Debug.Unindent();

            generic_nontype_par.setSpan(id.span, type.span);
            return(generic_nontype_par);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static FORMAL_TYPE parse(Token id, iSCOPE context)
        {
            Debug.Indent();
            Debug.WriteLine("Entering FORMAL_TYPE.parse");

            // Identifier was parsed before and is passed via 'id'.
            FORMAL_TYPE generic_type_par = new FORMAL_TYPE(id);

            Token token = get();

            if (token.code != TokenCode.Arrow2)
            {
                goto Finish;
            }

            // ->
            TYPE base_type = null;

            forget(); token = get();
            if (token.code == TokenCode.Identifier)
            {
                forget();
                base_type = UNIT_REF.parse(token, false, context);
            }
            else if (token.code == TokenCode.LParen)   // T->(tuple)
            {
                base_type = TUPLE_TYPE.parse(context);
            }
            else
            {
                // Syntax error
            }
            generic_type_par.base_type = base_type;

            token = get();
            if (token.code != TokenCode.Init)
            {
                goto Finish;
            }
            forget(); token = get();

            // init
            if (token.code != TokenCode.LParen)
            {
                goto Finish;
            }
            forget(); token = get();
            if (token.code == TokenCode.RParen)
            {
                forget(); goto Finish;
            }

            while (true)
            {
                TYPE init_param_type = TYPE.parse(context);
                generic_type_par.add(init_param_type);
                init_param_type.parent = generic_type_par;

                token = get();
                if (token.code == TokenCode.Comma)
                {
                    forget(); continue;
                }
                break;
            }
            token = expect(TokenCode.RParen);

Finish:
            Debug.WriteLine("Exiting FORMAL_TYPE.parse");
            Debug.Unindent();

            generic_type_par.setSpan(id, token);
            return(generic_type_par);
        }