private string GetValueBase(string expectedType) { AddContext(expectedType); if (!SkipAhead()) { throw ParsingException.LineEnd(currentContext, RealLineIndex); } return(GetSection()); }
protected T GetTypedValue <T>(string expectedTypeName, TryConverter <T> parser, Predicate <T> predicate = null) { var value = GetValueBase(expectedTypeName); if (!parser(value, out var result) || (predicate != null && !predicate(result))) { throw ParsingException.InvalidValue(currentContext, value, RealLineIndex); } RemoveContext(); return(result); }
protected string GetStrValue() { AddContext("string"); if (!SkipAhead()) { var newContext = new List <string>(currentContext); RemoveContext(); throw ParsingException.LineEnd(newContext, RealLineIndex); } RemoveContext(); return(GetStrValueUnderhood()); }
private void EndCommand() { while (LineIsUnfinished) { if (!seperatorPredicate(Current)) { Debug.Log($"{CurrentLine} @ {charIdx}; {Current}"); throw ParsingException.UnexpectedContinuation(currentContext, RealLineIndex); } charIdx++; } NextLine(); RemoveContext(addedContextCount); }
private string GetStrValueUnderhood() { if (Current == openStringChar) { StringBuilder str = new StringBuilder(); while (!IsFinished) { int incrCount = 1; if (Current == closeStringChar) { if (CurrentLine.Length > charIdx && CurrentLine[charIdx + 1] != closeStringChar) { str.Append(closeStringChar); incrCount = 2; } else { break; } } charIdx += incrCount; if (!LineIsUnfinished) { NextLine(); str.Append(Environment.NewLine); } else { str.Append(Current); } } if (!LineIsUnfinished) { throw ParsingException.DataEnd(currentContext, RealLineIndex); } return(str.ToString()); } else { return(GetSection()); } }