Exemplo n.º 1
0
        private static VarAttribute ReadAttributeOrThrow(this TokFlow flow)
        {
            var start = flow.Current.Start;

            flow.MoveNext();
            if (!flow.MoveIf(TokType.Id, out var id))
            {
                throw ErrorFactory.ItIsNotAnAttribute(start, flow.Current);
            }
            object val = null;

            if (flow.MoveIf(TokType.Obr))
            {
                var next = flow.Current;
                switch (next.Type)
                {
                case TokType.False:
                    val = false;
                    break;

                case TokType.True:
                    val = true;
                    break;

                case TokType.RealNumber:
                case TokType.HexOrBinaryNumber:
                case TokType.IntNumber:
                    val = TokenHelper.ToConstant(next.Value).Item1;
                    break;

                case TokType.Text:
                    val = next.Value;
                    break;

                default:
                    throw ErrorFactory.ItIsNotCorrectAttributeValue(next);
                }
                flow.MoveNext();
                if (!flow.MoveIf(TokType.Cbr))
                {
                    throw ErrorFactory.AttributeCbrMissed(start, flow);
                }
            }
            if (!flow.MoveIf(TokType.NewLine))
            {
                throw ErrorFactory.NowNewLineAfterAttribute(start, flow);
            }

            return(new VarAttribute(id.Value, val));
        }
Exemplo n.º 2
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);
        }