Beispiel #1
0
        Token ContinuatorKeyword()
        {
            Token result = default(Token);

            Check(Continuators.ContainsKey(LT(0).Value), "Expected Continuators.ContainsKey(LT($LI).Value)");
            result = Match((int)TT.Id);
            return(result);
        }
Beispiel #2
0
 protected override LesColorCode ColorCodeForId(UString name)
 {
     if (LNode.IsSpecialName(name.ToString()) || Continuators.ContainsKey((Symbol)name.ToString()))
     {
         return(LesColorCode.SpecialId);
     }
     else
     {
         return(LesColorCode.Id);
     }
 }
Beispiel #3
0
 protected override LesColorCode ColorCodeForId(Symbol name)
 {
     if (LNode.IsSpecialName(name.Name) || Continuators.ContainsKey(name))
     {
         return(LesColorCode.SpecialId);
     }
     else
     {
         return(LesColorCode.Id);
     }
 }
Beispiel #4
0
 public bool IsContinuator(object ltv) => ltv != null && Continuators.ContainsKey(ltv);
Beispiel #5
0
        LNode KeywordExpression()
        {
            TT    la0, la1;
            Token kw     = default(Token);
            LNode result = default(LNode);
            var   args   = new VList <LNode>();

            kw = MatchAny();
            // line 300
            var keyword = kw.Value as Symbol;

            // Line 302: ((EOF|TT.Newline|TT.RBrace|TT.RBrack|TT.RParen|TT.Semicolon) =>  / Expr)
            switch ((TT)LA0)
            {
            case EOF:
            case TT.Newline:
            case TT.RBrace:
            case TT.RBrack:
            case TT.RParen:
            case TT.Semicolon:
            { }
            break;

            default:
                args.Add(Expr(Precedence.MinValue));
                break;
            }
            // Line 304: greedy((TT.Newline)? BracedBlock)?
            do
            {
                la0 = (TT)LA0;
                if (la0 == TT.Newline)
                {
                    la1 = (TT)LA(1);
                    if (la1 == TT.LBrace)
                    {
                        goto matchBracedBlock;
                    }
                }
                else if (la0 == TT.LBrace)
                {
                    goto matchBracedBlock;
                }
                break;
matchBracedBlock:
                {
                    // Line 304: (TT.Newline)?
                    la0 = (TT)LA0;
                    if (la0 == TT.Newline)
                    {
                        Skip();
                    }
                    args.Add(BracedBlock());
                }
            } while (false);
            // Line 305: greedy(Continuator)*
            for (;;)
            {
                la0 = (TT)LA0;
                if (la0 == TT.Newline)
                {
                    la1 = (TT)LA(1);
                    if (la1 == TT.Id)
                    {
                        if (Continuators.ContainsKey(LT(1).Value))
                        {
                            args.Add(Continuator());
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else if (la0 == TT.Id)
                {
                    if (Continuators.ContainsKey(LT(0).Value))
                    {
                        args.Add(Continuator());
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            // line 307
            int endIndex = args.IsEmpty ? kw.EndIndex : args.Last.Range.EndIndex;

            result = MarkSpecial(F.Call(keyword, args, kw.StartIndex, endIndex, kw.StartIndex, kw.EndIndex));
            return(result);
        }
Beispiel #6
0
        Symbol InfixOperatorName(out Token op)
        {
            TT     la0;
            Token  op2    = default(Token);
            Symbol result = default(Symbol);

            // Line 187: ( (TT.Assignment|TT.Dot|TT.NormalOp) (TT.Newline)* | &{(TT) LA($LI + 1) != TT.Newline} TT.Colon | &!{Continuators.ContainsKey(LT($LI).Value)} TT.Id (&{op.EndIndex == LT0.StartIndex} (TT.Assignment|TT.Dot|TT.NormalOp) / ) (TT.Newline (TT.Newline)* / ) )
            switch ((TT)LA0)
            {
            case TT.Assignment:
            case TT.Dot:
            case TT.NormalOp:
            {
                op = MatchAny();
                // Line 187: (TT.Newline)*
                for (;;)
                {
                    la0 = (TT)LA0;
                    if (la0 == TT.Newline)
                    {
                        Skip();
                    }
                    else
                    {
                        break;
                    }
                }
                // line 187
                result = (Symbol)op.Value;
            }
            break;

            case TT.Colon:
            {
                Check((TT)LA(0 + 1) != TT.Newline, "Expected (TT) LA($LI + 1) != TT.Newline");
                op = MatchAny();
                // line 188
                result = (Symbol)op.Value;
            }
            break;

            default:
            {
                Check(!Continuators.ContainsKey(LT(0).Value), "Did not expect Continuators.ContainsKey(LT($LI).Value)");
                op = Match((int)TT.Id);
                // Line 192: (&{op.EndIndex == LT0.StartIndex} (TT.Assignment|TT.Dot|TT.NormalOp) / )
                do
                {
                    la0 = (TT)LA0;
                    if (la0 == TT.Assignment || la0 == TT.NormalOp)
                    {
                        if (op.EndIndex == LT0.StartIndex)
                        {
                            goto match1;
                        }
                        else
                        {
                            goto match2;
                        }
                    }
                    else if (la0 == TT.Dot)
                    {
                        goto match1;
                    }
                    else
                    {
                        goto match2;
                    }
match1:
                    {
                        Check(op.EndIndex == LT0.StartIndex, "Expected op.EndIndex == LT0.StartIndex");
                        op2 = MatchAny();
                        // line 194
                        result = GSymbol.Get("'" + op.Value.ToString() + op2.Value.ToString().Substring(1));
                    }
                    break;
match2:
                    {
                        // line 197
                        result = GSymbol.Get("'" + op.Value.ToString());
                        if ((TT)LA0 == TT.Newline)
                        {
                            Error(0, "Syntax error. {0}' is used like an operator but is followed by a newline, which is not allowed unless the expression is placed in parentheses.".Localized(result));
                        }
                    }
                } while (false);
                // Line 202: (TT.Newline (TT.Newline)* / )
                la0 = (TT)LA0;
                if (la0 == TT.Newline)
                {
                    Skip();
                    // Line 202: (TT.Newline)*
                    for (;;)
                    {
                        la0 = (TT)LA0;
                        if (la0 == TT.Newline)
                        {
                            Skip();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else                          // line 204
                if (LT(-1).EndIndex == LT0.StartIndex)
                {
                    Error(0, "Syntax error. {0}' is used like an operator but is not followed by a space.".Localized(result));
                }
            }
            break;
            }
            return(result);
        }
Beispiel #7
0
        LNode Expr(Precedence context)
        {
            TT    la0;
            LNode e        = default(LNode);
            Token lit_excl = default(Token);
            Token t        = default(Token);

            // Line 156: (KeywordExpression | PrefixExpr greedy( &{CanParse(context, $LI, out prec)} InfixOperatorName Expr | &{context.CanParse(P.Add)} TT.NegativeLiteral | &{context.CanParse(_prec.Find(OperatorShape.Suffix, LT($LI).Value))} TT.PreOrSufOp | &{context.CanParse(P.Primary)} FinishPrimaryExpr | &{context.CanParse(P.Of)} TT.Not (TT.LParen ExprList TT.RParen / Expr) )*)
            la0 = (TT)LA0;
            if (la0 == TT.Keyword)
            {
                e = KeywordExpression();
            }
            else
            {
                // line 157
                Precedence prec;
                e = PrefixExpr(context);
                // Line 161: greedy( &{CanParse(context, $LI, out prec)} InfixOperatorName Expr | &{context.CanParse(P.Add)} TT.NegativeLiteral | &{context.CanParse(_prec.Find(OperatorShape.Suffix, LT($LI).Value))} TT.PreOrSufOp | &{context.CanParse(P.Primary)} FinishPrimaryExpr | &{context.CanParse(P.Of)} TT.Not (TT.LParen ExprList TT.RParen / Expr) )*
                for (;;)
                {
                    switch ((TT)LA0)
                    {
                    case TT.Assignment:
                    case TT.Dot:
                    case TT.NormalOp:
                    {
                        if (CanParse(context, 0, out prec))
                        {
                            goto match1;
                        }
                        else
                        {
                            goto stop;
                        }
                    }

                    case TT.Colon:
                    {
                        if ((TT)LA(0 + 1) != TT.Newline)
                        {
                            if (CanParse(context, 0, out prec))
                            {
                                goto match1;
                            }
                            else
                            {
                                goto stop;
                            }
                        }
                        else
                        {
                            goto stop;
                        }
                    }

                    case TT.Id:
                    {
                        if (CanParse(context, 0, out prec))
                        {
                            if (!Continuators.ContainsKey(LT(0).Value))
                            {
                                goto match1;
                            }
                            else
                            {
                                goto stop;
                            }
                        }
                        else
                        {
                            goto stop;
                        }
                    }

                    case TT.NegativeLiteral:
                    {
                        if (context.CanParse(P.Add))
                        {
                            var rhs = MatchAny();
                            // line 167
                            e = F.Call(S.Sub, e, ToPositiveLiteral(rhs), e.Range.StartIndex, rhs.EndIndex, rhs.StartIndex, rhs.StartIndex + 1, NodeStyle.Operator);
                        }
                        else
                        {
                            goto stop;
                        }
                    }
                    break;

                    case TT.PreOrSufOp:
                    {
                        if (context.CanParse(_prec.Find(OperatorShape.Suffix, LT(0).Value)))
                        {
                            t = MatchAny();
                            // line 171
                            e = F.Call(_prec.ToSuffixOpName((Symbol)t.Value), e, e.Range.StartIndex, t.EndIndex, t.StartIndex, t.EndIndex, NodeStyle.Operator);
                        }
                        else
                        {
                            goto stop;
                        }
                    }
                    break;

                    case TT.LBrack:
                    case TT.LParen:
                    {
                        if (context.CanParse(P.Primary))
                        {
                            e = FinishPrimaryExpr(e);
                        }
                        else
                        {
                            goto stop;
                        }
                    }
                    break;

                    case TT.Not:
                    {
                        if (context.CanParse(P.Of))
                        {
                            lit_excl = MatchAny();
                            // line 178
                            var args = new VList <LNode> {
                                e
                            };
                            int endIndex;
                            // Line 179: (TT.LParen ExprList TT.RParen / Expr)
                            la0 = (TT)LA0;
                            if (la0 == TT.LParen)
                            {
                                Skip();
                                args = ExprList(args);
                                var c = Match((int)TT.RParen);
                                // line 179
                                endIndex = c.EndIndex;
                            }
                            else
                            {
                                var T = Expr(P.Of);
                                // line 180
                                args.Add(T);
                                endIndex = T.Range.EndIndex;
                            }
                            // line 182
                            e = F.Call(S.Of, args, e.Range.StartIndex, endIndex, lit_excl.StartIndex, lit_excl.EndIndex, NodeStyle.Operator);
                        }
                        else
                        {
                            goto stop;
                        }
                    }
                    break;

                    default:
                        goto stop;
                    }
                    continue;
match1:
                    {
                        Token op;
                        var   opName = InfixOperatorName(out op);
                        var   rhs    = Expr(prec);
                        // line 164
                        e = F.Call(opName, e, rhs, e.Range.StartIndex, rhs.Range.EndIndex, op.StartIndex, op.EndIndex, NodeStyle.Operator);
                    }
                }
                stop :;
            }
            // line 184
            return(e);
        }