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

Yuya Nishihara yuya at tcha.org
Sun Jul 12 09:55:00 CDT 2015


# HG changeset patch
# User Yuya Nishihara <yuya at 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.

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:


More information about the Mercurial-devel mailing list