Example #1
0
        private LNode AttachTriviaTo(LNode node, IListSource <Trivia> trivia, TriviaLocation loc, LNode parent, int indexInParent)
        {
            var newAttrs = GetTriviaToAttach(node, trivia, loc, parent, indexInParent);

            if (loc == TriviaLocation.Leading)
            {
                return(node.PlusAttrsBefore(newAttrs));
            }
            else
            {
                return(node.PlusTrailingTrivia(newAttrs));
            }
        }
Example #2
0
        protected LNode TopExpr()
        {
            TT        la0, la1;
            Token     at    = default(Token);
            LNodeList attrs = default(LNodeList);
            LNode     e     = default(LNode);
            Token     t     = default(Token);
            // line 93
            var attrStart = int.MaxValue;

            // Line 95: greedy(TT.At TT.LBrack ExprList TT.RBrack)*
            for (;;)
            {
                la0 = (TT)LA0;
                if (la0 == TT.At)
                {
                    la1 = (TT)LA(1);
                    if (la1 == TT.LBrack)
                    {
                        at = MatchAny();
                        // line 96
                        if (at.Type() == default(TT))
                        {
                            ErrorSink.Write(Severity.Warning, LaIndexToMsgContext(0), "Attribute: expected '@['");
                        }
                        else
                        {
                            attrStart = System.Math.Min(attrStart, at.StartIndex);
                        }
                        t     = MatchAny();
                        attrs = ExprList(attrs);
                        Match((int)TT.RBrack);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            // Line 100: (Expr / TT.Id Expr (Particle)*)
            switch ((TT)LA0)
            {
            case TT.Assignment:
            case TT.BQOperator:
            case TT.Dot:
            case TT.NormalOp:
            case TT.Not:
            case TT.PrefixOp:
            case TT.PreOrSufOp:
                e = Expr(StartStmt);
                break;

            case TT.Id:
            {
                switch ((TT)LA(1))
                {
                case EOF:
                case TT.Assignment:
                case TT.BQOperator:
                case TT.Comma:
                case TT.Dot:
                case TT.LBrack:
                case TT.LParen:
                case TT.NormalOp:
                case TT.Not:
                case TT.PreOrSufOp:
                case TT.RBrace:
                case TT.RBrack:
                case TT.RParen:
                case TT.Semicolon:
                    e = Expr(StartStmt);
                    break;

                default:
                {
                    var id = MatchAny();
                    // line 103
                    var args = LNodeList.Empty;
                    args.Add(Expr(P.SuperExpr));
                    // Line 105: (Particle)*
                    for (;;)
                    {
                        switch ((TT)LA0)
                        {
                        case TT.At:
                        case TT.Id:
                        case TT.LBrace:
                        case TT.LBrack:
                        case TT.Literal:
                        case TT.LParen:
                        case TT.SpaceLParen:
                        {
                            // line 106
                            if ((((TT)LA0) == TT.LParen))
                            {
                                var loc = args[args.Count - 2, args.Last].Range.End;
                                Error(0, "Expected a space before '(' (possibly missing ';' or ',' at {0})", loc);
                            }
                            args.Add(Particle());
                        }
                        break;

                        default:
                            goto stop;
                        }
                    }
                    stop :;
                    // line 113
                    e = MarkSpecial(F.Call(id, args, id.StartIndex, args.Last.Range.EndIndex));
                }
                break;
                }
            }
            break;

            default:
                e = Expr(StartStmt);
                break;
            }
            // line 115
            if ((attrStart < e.Range.StartIndex))
            {
                e = e.WithRange(attrStart, e.Range.EndIndex);
            }
            // line 116
            return(e.PlusAttrsBefore(attrs));
        }
Example #3
0
        protected LNode TopExpr()
        {
            TT    la0;
            LNode e         = default(LNode);
            Token lit_colon = default(Token);
            LNode result    = default(LNode);
            // line 120
            int startIndex = LT0.StartIndex;
            // line 121
            var attrs = new VList <LNode>();

            // Line 123: (TT.At (TT.At | Particle) greedy(~(EOF|TT.LBrace|TT.Newline) => {..})? NewlinesOpt)*
            for (;;)
            {
                la0 = (TT)LA0;
                if (la0 == TT.At)
                {
                    Skip();
                    // Line 123: (TT.At | Particle)
                    la0 = (TT)LA0;
                    if (la0 == TT.At)
                    {
                        Skip();
                    }
                    else
                    {
                        attrs.Add(Particle(isAttribute: true));
                    }
                    // Line 124: greedy(~(EOF|TT.LBrace|TT.Newline) => {..})?
                    la0 = (TT)LA0;
                    if (!(la0 == (TT)EOF || la0 == TT.LBrace || la0 == TT.Newline))
                    {
                        // line 124
                        CheckForSpaceAtEndOfAttribute();
                    }
                    NewlinesOpt();
                }
                else
                {
                    break;
                }
            }
            // Line 127: (Expr greedy(TT.Colon (EOF|TT.Newline|TT.RBrace|TT.RBrack|TT.RParen) => )?)
            switch ((TT)LA0)
            {
            case TT.Assignment:
            case TT.BQId:
            case TT.BQOperator:
            case TT.Id:
            case TT.Keyword:
            case TT.LBrace:
            case TT.LBrack:
            case TT.Literal:
            case TT.LParen:
            case TT.NormalOp:
            case TT.Not:
            case TT.PrefixOp:
            case TT.PreOrSufOp:
            case TT.SingleQuoteOp:
            {
                e = Expr(Precedence.MinValue);
                // Line 129: greedy(TT.Colon (EOF|TT.Newline|TT.RBrace|TT.RBrack|TT.RParen) => )?
                la0 = (TT)LA0;
                if (la0 == TT.Colon)
                {
                    lit_colon = MatchAny();
                    // line 130
                    e = F.Call(sy__apos_colonsuf, e, e.Range.StartIndex, lit_colon.EndIndex, lit_colon.StartIndex, lit_colon.EndIndex);
                }
            }
            break;

            default:
            {
                // line 132
                Error(0, "Expected an expression here");
                MatchExcept();
                // Line 133: nongreedy(~(EOF))*
                for (;;)
                {
                    switch ((TT)LA0)
                    {
                    case EOF:
                    case TT.Assignment:
                    case TT.At:
                    case TT.BQId:
                    case TT.BQOperator:
                    case TT.Comma:
                    case TT.Id:
                    case TT.Keyword:
                    case TT.LBrace:
                    case TT.LBrack:
                    case TT.Literal:
                    case TT.LParen:
                    case TT.Newline:
                    case TT.NormalOp:
                    case TT.Not:
                    case TT.PrefixOp:
                    case TT.PreOrSufOp:
                    case TT.RBrace:
                    case TT.RBrack:
                    case TT.RParen:
                    case TT.Semicolon:
                    case TT.SingleQuoteOp:
                        goto stop;

                    default:
                        Skip();
                        break;
                    }
                }
                stop :;
                // Line 134: (TopExpr | (EOF|TT.Comma|TT.Newline|TT.RBrace|TT.RBrack|TT.RParen|TT.Semicolon) => {..})
                switch ((TT)LA0)
                {
                case TT.Assignment : case TT.At : case TT.BQId : case TT.BQOperator :
                case TT.Id         : case TT.Keyword : case TT.LBrace : case TT.LBrack :
                case TT.Literal    : case TT.LParen : case TT.NormalOp : case TT.Not :
                case TT.PrefixOp   : case TT.PreOrSufOp : case TT.SingleQuoteOp :
                    e = TopExpr();
                    break;

                default:
                    // line 134
                    e = MissingExpr(LT0);
                    break;
                }
            }
            break;
            }
            // line 136
            if (!attrs.IsEmpty)
            {
                e = e.PlusAttrsBefore(attrs).WithRange(startIndex, e.Range.EndIndex);
            }
            // line 137
            result = e;
            return(result);
        }