Exemplo n.º 1
0
        public static new EXPRESSION parse(Token first, iSCOPE context)
        {
            EXPRESSION result = ADDITIVE.parse(first, context);
            Token      token  = get();

            switch (token.code)
            {
            case TokenCode.Less:
            case TokenCode.LessEqual:
            case TokenCode.Greater:
            case TokenCode.GreaterEqual:
            case TokenCode.Equal:
            case TokenCode.NotEqual:
            case TokenCode.EqualEqual:
            case TokenCode.NotEqualDeep:
                forget(); break;

            case TokenCode.In:
                forget();
                EXPRESSION left = EXPRESSION.parse(null, context);
                token = get();
                if (token.code == TokenCode.DotDot)
                {
                    forget();
                    EXPRESSION right = EXPRESSION.parse(null, context);
                    RANGE_TYPE range = new RANGE_TYPE(left, right);
                    range.setSpan(left.span, right.span);
                    Span          start = result.span;
                    IN_EXPRESSION r     = new IN_EXPRESSION(token, result, range);
                    result.parent = r;
                    result        = r;
                    result.setSpan(start, range.span);
                    goto Out;
                }
                else
                {
                    // Something's wrong: right part of the in-expression
                    // should always be a range-type
                    goto Out;
                }

            default:
                goto Out;
            }
            EXPRESSION second = ADDITIVE.parse(null, context);
            Span       start2 = result.span;

            result = new RELATIONAL(token, result, second);
            result.setSpan(start2, second.span);
Out:
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <syntax>
        /// UnitTypeName         : CompoundName [ GenericInstantiation ]
        ///
        /// GenericInstantiation : "[" (Type|Expression) { "," (Type|Expression) } "]"
        /// </syntax>
        /// <returns></returns>
        public static UNIT_REF parse(Token id, bool opt, iSCOPE context)
        {
            Debug.Indent();
            Debug.WriteLine("Entering UNIT_REF.parse");

            Token token = null;

            // We assume that 'id' is 'identifier'.
            if (id == null)
            {
                token = get(); forget();
            }
            else
            {
                token = id;
            }

            token = IDENTIFIER.parseCompoundName(token);
            if (token == null) /* an error was detected earlier */ return {
                (null);
            }
            Token start = token;

            UNIT_REF unit_ref = new UNIT_REF(token.image);

            unit_ref.opt     = opt;
            unit_ref.as_sign = true;
            DECLARATION unit = Context.find(token);

            if (unit != null && (unit is UNIT || unit is FORMAL_TYPE))
            {
                unit_ref.unit_ref = unit;
            }

            token = get();
            if (token.code == TokenCode.LBracket)
            {
                forget();
                while (true)
                {
                    TYPE type = null;
                    token = get();
                    if (token.code == TokenCode.LParen)
                    {
                        type = TUPLE_TYPE.parse(context);
                        unit_ref.add(type);
                        goto Delimiter;
                    }
                    EXPRESSION expr = EXPRESSION.parse(null, context);
                    if (expr is REFERENCE || expr is UNRESOLVED)
                    {
                        string name = null;
                        if (expr is REFERENCE)
                        {
                            if ((expr as REFERENCE).declaration is UNIT)
                            {
                                name = (expr as REFERENCE).declaration.name.identifier;
                            }
                            else
                            {
                                goto NonType;
                            }
                        }
                        else // UNRESOLVED
                        {
                            name = (expr as UNRESOLVED).name.identifier;
                        }

                        id   = new Token(expr.span, TokenCode.Identifier, name, new Category(CategoryCode.identifier));
                        type = UNIT_REF.parse(id, false, context); // Recursive call

                        unit_ref.add(type);
                        type.parent = unit_ref;
                        goto Delimiter;
                    }
                    // else -- expr is perhaps a non-type argument
NonType:
                    token = get();
                    if (token.code == TokenCode.DotDot)
                    {
                        // This is actually a range _type_
                        forget();
                        EXPRESSION right = EXPRESSION.parse(null, context);
                        RANGE_TYPE range = new RANGE_TYPE(expr, right);
                        range.setSpan(expr.span, right.span);
                        unit_ref.add(range);
                        range.parent = unit_ref;
                    }
                    else // Definitely a non-type argument
                    {
                        unit_ref.add(expr);
                        expr.parent = unit_ref;
                    }
Delimiter:
                    token = get();
                    switch (token.code)
                    {
                    case TokenCode.Comma:    forget(); continue;

                    case TokenCode.RBracket: forget(); goto Finish;

                    default: { /* Syntax error in generic actuals */ break; }
                    }
                }
Finish:
                unit_ref.setSpan(start.span, token.span);
            }
            else
            {
                unit_ref.setSpan(start);
            }

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

            return(unit_ref);
        }