Example #1
0
        public static new FORMAL_GENERIC parse(iSCOPE context)
        {
            Debug.Indent();
            Debug.WriteLine("Entering FORMAL_GENERIC.parse");

            Token id = expect(TokenCode.Identifier);

            if (id == null)
            {
                return(null);            // error
            }
            FORMAL_GENERIC result = null;

            Token token = get();

            if (token.code == TokenCode.Colon)
            {
                forget();
                result = FORMAL_NONTYPE.parse(id, context);
            }
            else
            {
                result = FORMAL_TYPE.parse(id, context);
            }

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

            return(result);
        }
Example #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);
        }