Esempio n. 1
0
        private List <T> CollectRecover <T>(PonyTokenSet recover, System.Func <T?> tryParse) where T : class
        {
            var items = new List <T>();

            while (true)
            {
                try
                {
                    var item = tryParse();
                    if (item != null)
                    {
                        items.Add(item);
                    }
                    else
                    {
                        break;
                    }
                }
                catch (JokeException joke)
                {
                    Errors.Add(joke.Error);
                    SkipUntil(recover);
                }
            }

            return(items);
        }
Esempio n. 2
0
 private void SkipUntil(PonyTokenSet tokens)
 {
     while (next < limit && !tokens[Tokens[next].Kind])
     {
         next += 1;
     }
 }
Esempio n. 3
0
 private void Begin(PonyTokenSet set)
 {
     if (next < limit)
     {
         marks.Push(next);
     }
     Match(set);
 }
Esempio n. 4
0
        private void Match(PonyTokenSet set)
        {
            if (next < limit && set[Tokens[next].Kind])
            {
                next += 1;
                return;
            }

            throw NoParse("expected something (not EOF)");
        }
Esempio n. 5
0
            static First()
            {
                Class = new PonyTokenSet(
                    TK.Class,
                    TK.Type,
                    TK.Interface,
                    TK.Trait,
                    TK.Primitive,
                    TK.Struct,
                    TK.Actor);
                Use = new PonyTokenSet(
                    TK.Use);
                Module = PonyTokenSet.Union(Use, Class);
                Atom   = new PonyTokenSet(
                    TK.Identifier,
                    TK.This,
                    TK.String,
                    TK.DocString,
                    TK.Char,
                    TK.Int,
                    TK.Float,
                    TK.True,
                    TK.False,
                    TK.LParen,
                    TK.LParenNew,
                    TK.LSquare,
                    TK.LSquareNew,
                    TK.Object,
                    TK.LBrace,
                    TK.AtLBrace,
                    TK.At,
                    TK.Location,
                    TK.If,
                    TK.While,
                    TK.For);
                Prefix = new PonyTokenSet(
                    TK.Addressof,
                    TK.DigestOf,
                    TK.Not,
                    TK.Minus,
                    TK.MinusNew,
                    TK.MinusTilde,
                    TK.MinusTildeNew);
                Postfix      = Atom;
                ParamPattern = PonyTokenSet.Union(Prefix, Postfix);
                Local        = new PonyTokenSet(TK.Var, TK.Let, TK.Embed);
                Field        = Local;
                Method       = new PonyTokenSet(TK.Fun, TK.Be, TK.New);
                Pattern      = PonyTokenSet.Union(ParamPattern, Local);
                Term         = new PonyTokenSet(
                    TK.If,
                    TK.Ifdef,
                    TK.Iftype,
                    TK.Match,
                    TK.While,
                    TK.Repeat,
                    TK.For,
                    TK.With,
                    TK.Try,
                    TK.Recover,
                    TK.Consume,
                    TK.Constant)
                               .Union(Pattern);
                Jump = new PonyTokenSet(
                    TK.Return,
                    TK.Break,
                    TK.Continue,
                    TK.Error,
                    TK.CompileIntrinsic,
                    TK.CompileError);
                Infix      = Term;
                Assignment = Infix;
                ExprSeq    = Assignment;
                RawSeq     = PonyTokenSet.Union(Jump, ExprSeq);
                Lambda     = new PonyTokenSet(TK.LBrace, TK.AtLBrace);

                RecoverInModule = Module;
                RecoverInClass  = PonyTokenSet.Union(RecoverInModule, Method, Field);
                RecoverNothing  = new PonyTokenSet();
            }