Пример #1
0
            public override void Parse(ParseContext <YamlTokenType> context)
            {
                switch (context.LookaheadToken.Type)
                {
                case YamlTokenType.EndLine:
                    break;

                default:
                    throw new InvalidDataException("Unexpected token: " + context.LookaheadToken + ", after: " + context.CurrentToken);
                }

                switch (context.CurrentToken.Type)
                {
                case YamlTokenType.Word:
                {
                    var   value = context.CurrentToken.Value;
                    Match match;
                    if ((match = floatRegex.Match(value)).Success)
                    {
                        Callback(new TinyValue(value, TinyTokenType.Float));
                    }
                    else if ((match = integerRegex.Match(value)).Success)
                    {
                        Callback(new TinyValue(value, TinyTokenType.Integer));
                    }
                    else if ((match = boolRegex.Match(value)).Success)
                    {
                        Callback(new TinyValue(value == YamlFormat.BooleanTrue));
                    }
                    else
                    {
                        Callback(new TinyValue(value));
                    }
                    context.ConsumeToken();
                    context.PopParser();
                }
                    return;

                case YamlTokenType.WordQuoted:
                {
                    var value = YamlUtil.UnescapeString(context.CurrentToken.Value);
                    Callback(new TinyValue(value));
                    context.ConsumeToken();
                    context.PopParser();
                }
                    return;
                }

                throw new InvalidDataException("Unexpected token: " + context.CurrentToken);
            }
Пример #2
0
            public override void Parse(ParseContext <YamlTokenType> context)
            {
                if (CheckIndent(context))
                {
                    return;
                }

                switch (context.LookaheadToken.Type)
                {
                case YamlTokenType.ArrayIndicator:
                case YamlTokenType.Property:
                case YamlTokenType.PropertyQuoted:
                    throw new InvalidDataException("Unexpected token: " + context.LookaheadToken + ", after: " + context.CurrentToken);
                }

                switch (context.CurrentToken.Type)
                {
                case YamlTokenType.Property:
                case YamlTokenType.PropertyQuoted:

                    var key = context.CurrentToken.Value;
                    if (context.CurrentToken.Type == YamlTokenType.PropertyQuoted)
                    {
                        key = YamlUtil.UnescapeString(key);
                    }

                    switch (context.LookaheadToken.Type)
                    {
                    case YamlTokenType.Word:
                    case YamlTokenType.WordQuoted:
                        context.PushParser(new ValueParser(r => result.Add(key, r)));
                        break;

                    case YamlTokenType.EndLine:
                        context.PushParser(new EmptyProperyParser(r => result.Add(key, r), context.IndentLevel + 1));
                        break;

                    default:
                        throw new InvalidDataException("Unexpected token: " + context.LookaheadToken + ", after: " + context.CurrentToken);
                    }
                    context.ConsumeToken();
                    return;
                }
                throw new InvalidDataException("Unexpected token: " + context.CurrentToken);
            }