public static PhpStringLiteralSyntaxNode Parse(PhpTokeniser tokeniser)
        {
            tokeniser.SkipWhitespace();

            char trivia = tokeniser.GetTrivia();

            // Skip leading trivia.
            tokeniser.Advance();

            var  stringBuilder = new StringBuilder();
            bool isEscaping    = false;

            while (isEscaping || tokeniser.GetTrivia() != trivia)
            {
                var token = tokeniser.GetTrivia();
                tokeniser.Advance();

                if (token == '\\' && !isEscaping)
                {
                    isEscaping = true;
                    continue;
                }

                stringBuilder.Append(token);
                isEscaping = false;
            }

            // Skip trailing trivia.
            tokeniser.Advance();
            tokeniser.SkipWhitespace();

            return(new PhpStringLiteralSyntaxNode(stringBuilder.ToString()));
        }
예제 #2
0
        public static PhpArraySyntaxNode Parse(PhpTokeniser tokeniser)
        {
            tokeniser.SkipWhitespace();
            tokeniser.SkipPattern(new[] { '[' });

            var elements = ImmutableArray.CreateBuilder <PhpArrayElementSyntaxNode>();

            while (true)
            {
                tokeniser.SkipWhitespace();
                if (tokeniser.GetTrivia() == ']')
                {
                    break;
                }

                elements.Add(PhpArrayElementSyntaxNode.Parse(tokeniser));
            }

            // Skip trailing trivia.
            tokeniser.Advance();
            tokeniser.SkipWhitespace();

            return(new PhpArraySyntaxNode(elements.ToImmutableArray()));
        }