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); }
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)); }
public static Tok MoveIfOrThrow(this TokFlow flow, TokType tokType) { var cur = flow.Current; if (cur == null) { var prev = flow.Previous; if (prev == null) { throw FunParseException.ErrorStubToDo($"\"{tokType}\" is missing at end of stream"); } else { throw FunParseException.ErrorStubToDo($"\"{tokType}\" is missing at end of stream"); } } if (!cur.Is(tokType)) { throw FunParseException.ErrorStubToDo( $"\"{tokType}\" is missing but was \"{cur}\""); } flow.MoveNext(); return(cur); }
public static bool MoveIf(this TokFlow flow, TokType tokType) { if (flow.IsCurrent(tokType)) { flow.MoveNext(); return(true); } return(false); }
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); }