Permalink
Browse files

shortcut for non-interpolated double quoted strings

  • Loading branch information...
1 parent 062ed5c commit 61986c1eb3dcd35c6ea006de1640535044d1cdb3 @arnaud-lb arnaud-lb committed Nov 13, 2011
Showing with 6 additions and 6 deletions.
  1. +6 −6 lib/Twig/Lexer.php
View
12 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 @@ protected function lexExpression()
$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);

0 comments on commit 61986c1

Please sign in to comment.