Ejemplo n.º 1
0
        private string GetValueBase(string expectedType)
        {
            AddContext(expectedType);

            if (!SkipAhead())
            {
                throw ParsingException.LineEnd(currentContext, RealLineIndex);
            }

            return(GetSection());
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        protected string GetStrValue()
        {
            AddContext("string");

            if (!SkipAhead())
            {
                var newContext = new List <string>(currentContext);
                RemoveContext();
                throw ParsingException.LineEnd(newContext, RealLineIndex);
            }

            RemoveContext();

            return(GetStrValueUnderhood());
        }
Ejemplo n.º 4
0
        private void EndCommand()
        {
            while (LineIsUnfinished)
            {
                if (!seperatorPredicate(Current))
                {
                    Debug.Log($"{CurrentLine} @ {charIdx}; {Current}");
                    throw ParsingException.UnexpectedContinuation(currentContext, RealLineIndex);
                }

                charIdx++;
            }

            NextLine();
            RemoveContext(addedContextCount);
        }
Ejemplo n.º 5
0
        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());
            }
        }