From: Arnaud Le Blanc Date: Sun, 13 Nov 2011 13:11:55 +0000 (+0100) Subject: shortcut for non-interpolated double quoted strings X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=61986c1eb3dcd35c6ea006de1640535044d1cdb3;p=konrad%2Ftwig.git shortcut for non-interpolated double quoted strings --- 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);