From 61986c1eb3dcd35c6ea006de1640535044d1cdb3 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Sun, 13 Nov 2011 14:11:55 +0100 Subject: [PATCH] shortcut for non-interpolated double quoted strings --- lib/Twig/Lexer.php | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index c4f2c71..196d099 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -39,7 +39,7 @@ class Twig_Lexer implements Twig_LexerInterface const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?/A'; - const REGEX_STRING = '/\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; + const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; const REGEX_DQ_STRING_START = '/"/A'; const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; const PUNCTUATION = '()[]{}?:.,|'; @@ -260,17 +260,17 @@ class Twig_Lexer implements Twig_LexerInterface $this->pushToken(Twig_Token::PUNCTUATION_TYPE, $this->code[$this->cursor]); ++$this->cursor; } + // strings + elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) { + $this->pushToken(Twig_Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1))); + $this->moveCursor($match[0]); + } // opening double quoted string elseif (preg_match(self::REGEX_DQ_STRING_START, $this->code, $match, null, $this->cursor)) { $this->brackets[] = array('"', $this->lineno); $this->pushState(self::STATE_STRING); $this->moveCursor($match[0]); } - // strings - elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1))); - $this->moveCursor($match[0]); - } // unlexable else { throw new Twig_Error_Syntax(sprintf('Unexpected character "%s"', $this->code[$this->cursor]), $this->lineno, $this->filename); -- 1.7.2.5