Patchwork [5,of,7] templater: remove processing of "string" literals from tokenizer

login
register
mail settings
Submitter Yuya Nishihara
Date July 12, 2015, 2:55 p.m.
Message ID <8fd451a45ea89649e85e.1436712900@mimosa>
Download mbox | patch
Permalink /patch/9957/
State Accepted
Headers show

Comments

Yuya Nishihara - July 12, 2015, 2:55 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1434860901 -32400
#      Sun Jun 21 13:28:21 2015 +0900
# Node ID 8fd451a45ea89649e85ec8051a9b6dff03d94293
# Parent  2651605c4d75484687faf5c97653c24580dce6fa
templater: remove processing of "string" literals from tokenizer

They are processed as "template" strings now.

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -22,7 +22,6 @@  elements = {
     ")": (0, None, None),
     "integer": (0, ("integer",), None),
     "symbol": (0, ("symbol",), None),
-    "string": (0, ("template",), None),
     "rawstring": (0, ("rawstring",), None),
     "template": (0, ("template",), None),
     "end": (0, None, None),
@@ -41,26 +40,17 @@  def tokenize(program, start, end):
             data, pos = _parsetemplate(program, s, end, c)
             yield ('template', data, s)
             pos -= 1
-        elif (c in '"\'' or c == 'r' and
-              program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
-            if c == 'r':
-                pos += 1
-                c = program[pos]
-                decode = False
-            else:
-                decode = True
-            pos += 1
-            s = pos
+        elif c == 'r' and program[pos:pos + 2] in ("r'", 'r"'):
+            # handle quoted strings
+            c = program[pos + 1]
+            s = pos = pos + 2
             while pos < end: # find closing quote
                 d = program[pos]
                 if d == '\\': # skip over escaped characters
                     pos += 2
                     continue
                 if d == c:
-                    if not decode:
-                        yield ('rawstring', program[s:pos], s)
-                        break
-                    yield ('string', program[s:pos], s)
+                    yield ('rawstring', program[s:pos], s)
                     break
                 pos += 1
             else: