Beispiel #1
0
        private bool ConsumeValue()
        {
            var local = yaml.Slice(consumed + 1);
            var start = 0;
            var i     = 0;

            for (; i < local.Length; i++)
            {
                consumed++;
                if (local[i] == ' ')
                {
                    start++;
                }

                if (local[i] == '\n')
                {
                    consumed++;
                    i--;
                    break;
                }

                if (local[i] == '#')
                {
                    SkipComment();
                    break;
                }
            }

            Value        = local.Slice(start, i - start);
            CurrentToken = MiniYamlToken.String;

            return(true);
        }
Beispiel #2
0
 public MiniYamlReader(ReadOnlySpan <char> yaml)
 {
     CurrentToken = MiniYamlToken.None;
     Value        = ReadOnlySpan <char> .Empty;
     this.yaml    = yaml;
     consumed     = 0;
 }
Beispiel #3
0
        public bool Read()
        {
            while (true)
            {
                var c = yaml[consumed];
                switch (c)
                {
                case ' ':
                case '\n':
                    SkipWhitespace();
                    break;

                case ':':
                    consumed++;
                    break;

                case '#':
                    CurrentToken = MiniYamlToken.Comment;
                    SkipComment();
                    break;

                default:
                {
                    if (CurrentToken == MiniYamlToken.Key)
                    {
                        return(ConsumeValue());
                    }
                    else
                    {
                        return(ConsumeKey());
                    }
                }
                }
            }


            if (yaml[consumed] == '#')
            {
                SkipComment();
            }

            if (CurrentToken == MiniYamlToken.None)
            {
                return(ConsumeKey());
            }
            if (CurrentToken == MiniYamlToken.Key)
            {
                return(ConsumeValue());
            }

            if (CurrentToken == MiniYamlToken.String)
            {
                return(ConsumeKey());
            }

            return(false);
        }
Beispiel #4
0
        bool ConsumeKey()
        {
            var localBuffer = yaml.Slice(consumed);
            var i           = 0;

            for (; i < localBuffer.Length; i++)
            {
                var c = localBuffer[i];

                if (c == ':' || c == '@')
                {
                    break;
                }
            }

            consumed += i;


            Value        = localBuffer.Slice(0, i);
            CurrentToken = MiniYamlToken.Key;

            return(true);
        }
Beispiel #5
0
        private bool ConsumeValue()
        {
            var local = yaml.Slice(consumed);

            var i = 0;

            for (; i < local.Length; i++)
            {
                var c = local[i];

                if (c == '\n' || c == '#')
                {
                    i--;
                    break;
                }

                consumed++;
            }

            Value        = local.Slice(0, i);
            CurrentToken = MiniYamlToken.String;

            return(true);
        }
Beispiel #6
0
        public bool Read()
        {
            var c = NextChar();

            while (true)
            {
                switch (c)
                {
                //case '!':
                //    if (PeekChar() == '=')
                //    {
                //        i++;
                //        return MiniYamlToken.NotEquals;
                //    }

                //    return MiniYamlToken.Not;

                //case '<':
                //    if (PeekChar()  == '=')
                //    {
                //        i++;
                //        return TokenType.LessThanOrEqual;
                //    }

                //    return TokenType.LessThan;

                //case '>':
                //    if (PeekChar()  == '=')
                //    {
                //        i++;
                //        return TokenType.GreaterThanOrEqual;
                //    }

                //    return TokenType.GreaterThan;

                //case '=':
                //    if (PeekChar()  == '=')
                //    {
                //        i++;
                //        return TokenType.Equals;
                //    }

                //    throw new InvalidDataException("Unexpected character '=' at index {0} - should it be `==`?".F(start));

                //case '&':
                //    if (PeekChar()  == '&')
                //    {
                //        i++;
                //        return TokenType.And;
                //    }

                //    throw new InvalidDataException("Unexpected character '&' at index {0} - should it be `&&`?".F(start));

                //case '|':
                //    if (PeekChar()  == '|')
                //    {
                //        i++;
                //        return TokenType.Or;
                //    }

                //    throw new InvalidDataException("Unexpected character '|' at index {0} - should it be `||`?".F(start));

                //case '(':
                //    return TokenType.OpenParen;

                //case ')':
                //    return TokenType.CloseParen;

                //case '~':
                //    return TokenType.OnesComplement;
                //case '+':
                //    return TokenType.Add;

                //case '-':
                //    if (++i < expression.Length && ScanIsNumber(expression, start, ref i))
                //        return TokenType.Number;

                //    i = start + 1;
                //    if (IsLeftOperandOrNone(lastType))
                //        return TokenType.Negate;
                //    return TokenType.Subtract;

                //case '*':
                //    return TokenType.Multiply;

                //case '/':
                //    i++;
                //    return TokenType.Divide;

                //case '%':
                //    return TokenType.Modulo;
                case ':':
                    CurrentToken = MiniYamlToken.Colon;
                    Value        = yaml.Slice(consumed, 1);
                    return(true);

                    break;

                case '#':
                    CurrentToken = MiniYamlToken.Comment;
                    SkipComment();
                    break;

                default:
                    CurrentToken = MiniYamlToken.Litteral;
                    ConsumeKey();
                    return(true);
                }
            }


            if (yaml[consumed] == '#')
            {
                SkipComment();
            }

            if (CurrentToken == MiniYamlToken.None)
            {
                return(ConsumeKey());
            }
            if (CurrentToken == MiniYamlToken.Key)
            {
                return(ConsumeValue());
            }

            if (CurrentToken == MiniYamlToken.String)
            {
                return(ConsumeKey());
            }

            return(false);
        }