comparison mercurial/templater.py @ 25784:33e613687dab

templater: remove processing of "string" literals from tokenizer They are processed as "template" strings now.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 21 Jun 2015 13:28:21 +0900
parents 1f6878c87c25
children f976b7dc5e7b
comparison
equal deleted inserted replaced
25783:1f6878c87c25 25784:33e613687dab
20 "|": (5, None, ("|", 5)), 20 "|": (5, None, ("|", 5)),
21 "%": (6, None, ("%", 6)), 21 "%": (6, None, ("%", 6)),
22 ")": (0, None, None), 22 ")": (0, None, None),
23 "integer": (0, ("integer",), None), 23 "integer": (0, ("integer",), None),
24 "symbol": (0, ("symbol",), None), 24 "symbol": (0, ("symbol",), None),
25 "string": (0, ("template",), None),
26 "rawstring": (0, ("rawstring",), None), 25 "rawstring": (0, ("rawstring",), None),
27 "template": (0, ("template",), None), 26 "template": (0, ("template",), None),
28 "end": (0, None, None), 27 "end": (0, None, None),
29 } 28 }
30 29
39 elif c in '"\'': # handle quoted templates 38 elif c in '"\'': # handle quoted templates
40 s = pos + 1 39 s = pos + 1
41 data, pos = _parsetemplate(program, s, end, c) 40 data, pos = _parsetemplate(program, s, end, c)
42 yield ('template', data, s) 41 yield ('template', data, s)
43 pos -= 1 42 pos -= 1
44 elif (c in '"\'' or c == 'r' and 43 elif c == 'r' and program[pos:pos + 2] in ("r'", 'r"'):
45 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings 44 # handle quoted strings
46 if c == 'r': 45 c = program[pos + 1]
47 pos += 1 46 s = pos = pos + 2
48 c = program[pos]
49 decode = False
50 else:
51 decode = True
52 pos += 1
53 s = pos
54 while pos < end: # find closing quote 47 while pos < end: # find closing quote
55 d = program[pos] 48 d = program[pos]
56 if d == '\\': # skip over escaped characters 49 if d == '\\': # skip over escaped characters
57 pos += 2 50 pos += 2
58 continue 51 continue
59 if d == c: 52 if d == c:
60 if not decode: 53 yield ('rawstring', program[s:pos], s)
61 yield ('rawstring', program[s:pos], s)
62 break
63 yield ('string', program[s:pos], s)
64 break 54 break
65 pos += 1 55 pos += 1
66 else: 56 else:
67 raise error.ParseError(_("unterminated string"), s) 57 raise error.ParseError(_("unterminated string"), s)
68 elif c.isdigit() or c == '-': 58 elif c.isdigit() or c == '-':