Beispiel #1
0
        private void ParseTokenValueInDoubleQuotes(PreTokenEnumerator enumerator, ref PreToken token, ref FlatTokenParserState state, ref StringBuilder tokenContent)
        {
            var next = enumerator.Next();

            switch (next)
            {
            case @"""":
                state = FlatTokenParserState.InTokenValueRunOff;
                break;

            default:
                token.AppendValue(next);
                break;
            }

            tokenContent.Append(next);
        }
Beispiel #2
0
        private void ParseTokenValue(PreTemplate template, ref PreToken token, PreTokenEnumerator enumerator, ref FlatTokenParserState state, ref bool inFrontMatterToken, ref StringBuilder tokenContent, TokenizerOptions options)
        {
            var next = enumerator.Next();
            var peek = enumerator.Peek();

            tokenContent.Append(next);

            switch (next)
            {
            case "{":
                throw new ParsingException($"Unexpected character '{{' in token '{token.Name}'", enumerator);

            case "}" when inFrontMatterToken == false:
            case "\n" when inFrontMatterToken:
                token.IsFrontMatterToken = inFrontMatterToken;
                AppendToken(template, token, ref tokenContent, options);
                token = new PreToken();
                if (inFrontMatterToken)
                {
                    inFrontMatterToken = false;
                    state = FlatTokenParserState.InFrontMatter;
                }
                else
                {
                    state = FlatTokenParserState.InPreamble;
                }
                break;

            case ":":
                state = FlatTokenParserState.InDecorator;
                break;

            case "'":
                state = FlatTokenParserState.InTokenValueSingleQuotes;
                break;

            case "\"":
                state = FlatTokenParserState.InTokenValueDoubleQuotes;
                break;

            case " ":
                switch (peek)
                {
                case " ":
                case "}" when inFrontMatterToken == false:
                case "\n" when inFrontMatterToken:
                case ":":
                    break;

                default:
                    if (token.HasValue)
                    {
                        throw new ParsingException($"Invalid character '{peek}' in token '{token.Name}'", enumerator);
                    }
                    break;
                }

                break;

            case "}" when inFrontMatterToken:
            case "\n" when inFrontMatterToken == false:
                throw  new ParsingException($"'{token.Name}' unexpected character: {next}", enumerator);

            default:
                token.AppendValue(next);
                break;
            }
        }