Пример #1
0
        public static FunnyType ReadType(this TokFlow flow)
        {
            var cur      = flow.Current;
            var readType = ToFunnyType(cur);

            flow.MoveNext();
            var lastPosition = cur.Finish;

            while (flow.IsCurrent(TokType.ArrOBr))
            {
                if (flow.Current.Start != lastPosition)
                {
                    throw FunParseException.ErrorStubToDo("unexpected space before []");
                }

                flow.MoveNext();
                lastPosition = flow.Current.Finish;
                if (!flow.MoveIf(TokType.ArrCBr))
                {
                    throw ErrorFactory.ArrTypeCbrMissed(new Interval(cur.Start, flow.Current.Start));
                }
                readType = FunnyType.ArrayOf(readType);
            }

            return(readType);
        }
Пример #2
0
 public static bool MoveIf(this TokFlow flow, TokType tokType)
 {
     if (flow.IsCurrent(tokType))
     {
         flow.MoveNext();
         return(true);
     }
     return(false);
 }
Пример #3
0
        public static bool MoveIf(this TokFlow flow, TokType tokType, out Tok tok)
        {
            if (flow.IsCurrent(tokType))
            {
                tok = flow.Current;
                flow.MoveNext();
                return(true);
            }

            tok = null;
            return(false);
        }
Пример #4
0
        public static VarAttribute[] ReadAttributes(this TokFlow flow)
        {
            var attributes = new VarAttribute[0];

            if (!flow.IsCurrent(TokType.MetaInfo))
            {
                return(attributes);
            }

            bool newLine = flow.IsStart || flow.Previous.Is(TokType.NewLine);
            var  ans     = new List <VarAttribute>();

            while (flow.IsCurrent(TokType.MetaInfo))
            {
                if (!newLine)
                {
                    throw ErrorFactory.NowNewLineBeforeAttribute(flow);
                }

                ans.Add(ReadAttributeOrThrow(flow));
                flow.SkipNewLines();
            }
            return(ans.ToArray());
        }
Пример #5
0
 public static bool IsDoneOrEof(this TokFlow flow)
 => flow.IsDone || flow.IsCurrent(TokType.Eof);