##// END OF EJS Templates
templater: fix position of terminator character in error message...
Yuya Nishihara -
r36709:1b179d15 default
parent child Browse files
Show More
@@ -543,16 +543,14 b' def parse(spec, lookup=None):'
543 return _parsewith(spec, lookup=lookup)
543 return _parsewith(spec, lookup=lookup)
544 except error.ParseError as inst:
544 except error.ParseError as inst:
545 if len(inst.args) > 1: # has location
545 if len(inst.args) > 1: # has location
546 # Add 1 to location because unlike templates, revset parse errors
546 loc = inst.args[1]
547 # point to the char where the error happened, not the char after.
548 loc = inst.args[1] + 1
549 # Remove newlines -- spaces are equivalent whitespace.
547 # Remove newlines -- spaces are equivalent whitespace.
550 spec = spec.replace('\n', ' ')
548 spec = spec.replace('\n', ' ')
551 # We want the caret to point to the place in the template that
549 # We want the caret to point to the place in the template that
552 # failed to parse, but in a hint we get a open paren at the
550 # failed to parse, but in a hint we get a open paren at the
553 # start. Therefore, we print "loc + 1" spaces (instead of "loc")
551 # start. Therefore, we print "loc + 1" spaces (instead of "loc")
554 # to line up the caret with the location of the error.
552 # to line up the caret with the location of the error.
555 inst.hint = spec + '\n' + ' ' * loc + '^ ' + _('here')
553 inst.hint = spec + '\n' + ' ' * (loc + 1) + '^ ' + _('here')
556 raise
554 raise
557
555
558 def _quote(s):
556 def _quote(s):
@@ -145,7 +145,7 b' def tokenize(program, start, end, term=N'
145 yield ('symbol', sym, s)
145 yield ('symbol', sym, s)
146 pos -= 1
146 pos -= 1
147 elif c == term:
147 elif c == term:
148 yield ('end', None, pos + 1)
148 yield ('end', None, pos)
149 return
149 return
150 else:
150 else:
151 raise error.ParseError(_("syntax error"), pos)
151 raise error.ParseError(_("syntax error"), pos)
@@ -237,9 +237,10 b' def _scantemplate(tmpl, start, stop, quo'
237 return
237 return
238
238
239 parseres, pos = p.parse(tokenize(tmpl, n + 1, stop, '}'))
239 parseres, pos = p.parse(tokenize(tmpl, n + 1, stop, '}'))
240 if not tmpl.endswith('}', n + 1, pos):
240 if not tmpl.startswith('}', pos):
241 raise error.ParseError(_("invalid token"), pos)
241 raise error.ParseError(_("invalid token"), pos)
242 yield ('template', parseres, n)
242 yield ('template', parseres, n)
243 pos += 1
243
244
244 if quote:
245 if quote:
245 raise error.ParseError(_("unterminated string"), start)
246 raise error.ParseError(_("unterminated string"), start)
@@ -253,9 +254,10 b' def _scantemplate(tmpl, start, stop, quo'
253 tmpl = tmpl.replace('\n', br'\n')
254 tmpl = tmpl.replace('\n', br'\n')
254 # We want the caret to point to the place in the template that
255 # We want the caret to point to the place in the template that
255 # failed to parse, but in a hint we get a open paren at the
256 # failed to parse, but in a hint we get a open paren at the
256 # start. Therefore, we print "loc" spaces (instead of "loc - 1")
257 # start. Therefore, we print "loc + 1" spaces (instead of "loc")
257 # to line up the caret with the location of the error.
258 # to line up the caret with the location of the error.
258 inst.hint = tmpl + '\n' + ' ' * (loc + offset) + '^ ' + _('here')
259 inst.hint = (tmpl + '\n'
260 + ' ' * (loc + 1 + offset) + '^ ' + _('here'))
259 raise
261 raise
260 yield ('end', None, pos)
262 yield ('end', None, pos)
261
263
@@ -2767,26 +2767,26 b' Error on syntax:'
2767 $ hg log -T '{date'
2767 $ hg log -T '{date'
2768 hg: parse error at 1: unterminated template expansion
2768 hg: parse error at 1: unterminated template expansion
2769 ({date
2769 ({date
2770 ^ here)
2770 ^ here)
2771 [255]
2771 [255]
2772 $ hg log -T '{date(}'
2772 $ hg log -T '{date(}'
2773 hg: parse error at 7: not a prefix: end
2773 hg: parse error at 6: not a prefix: end
2774 ({date(}
2774 ({date(}
2775 ^ here)
2775 ^ here)
2776 [255]
2776 [255]
2777 $ hg log -T '{date)}'
2777 $ hg log -T '{date)}'
2778 hg: parse error at 5: invalid token
2778 hg: parse error at 5: invalid token
2779 ({date)}
2779 ({date)}
2780 ^ here)
2780 ^ here)
2781 [255]
2781 [255]
2782 $ hg log -T '{date date}'
2782 $ hg log -T '{date date}'
2783 hg: parse error at 6: invalid token
2783 hg: parse error at 6: invalid token
2784 ({date date}
2784 ({date date}
2785 ^ here)
2785 ^ here)
2786 [255]
2786 [255]
2787
2787
2788 $ hg log -T '{}'
2788 $ hg log -T '{}'
2789 hg: parse error at 2: not a prefix: end
2789 hg: parse error at 1: not a prefix: end
2790 ({}
2790 ({}
2791 ^ here)
2791 ^ here)
2792 [255]
2792 [255]
@@ -2838,13 +2838,13 b' Error in nested template:'
2838 $ hg log -T '{"date'
2838 $ hg log -T '{"date'
2839 hg: parse error at 2: unterminated string
2839 hg: parse error at 2: unterminated string
2840 ({"date
2840 ({"date
2841 ^ here)
2841 ^ here)
2842 [255]
2842 [255]
2843
2843
2844 $ hg log -T '{"foo{date|?}"}'
2844 $ hg log -T '{"foo{date|?}"}'
2845 hg: parse error at 11: syntax error
2845 hg: parse error at 11: syntax error
2846 ({"foo{date|?}"}
2846 ({"foo{date|?}"}
2847 ^ here)
2847 ^ here)
2848 [255]
2848 [255]
2849
2849
2850 Thrown an error if a template function doesn't exist
2850 Thrown an error if a template function doesn't exist
@@ -3377,7 +3377,7 b' Test integer literal:'
3377 $ hg debugtemplate '{(-)}\n'
3377 $ hg debugtemplate '{(-)}\n'
3378 hg: parse error at 3: not a prefix: )
3378 hg: parse error at 3: not a prefix: )
3379 ({(-)}\n
3379 ({(-)}\n
3380 ^ here)
3380 ^ here)
3381 [255]
3381 [255]
3382 $ hg debugtemplate '{(-a)}\n'
3382 $ hg debugtemplate '{(-a)}\n'
3383 hg: parse error: negation needs an integer argument
3383 hg: parse error: negation needs an integer argument
@@ -3544,7 +3544,7 b' escaped single quotes and errors:'
3544 $ hg log -r 2 -T '{if(rev, "{if(rev, \")}")}\n'
3544 $ hg log -r 2 -T '{if(rev, "{if(rev, \")}")}\n'
3545 hg: parse error at 21: unterminated string
3545 hg: parse error at 21: unterminated string
3546 ({if(rev, "{if(rev, \")}")}\n
3546 ({if(rev, "{if(rev, \")}")}\n
3547 ^ here)
3547 ^ here)
3548 [255]
3548 [255]
3549 $ hg log -r 2 -T '{if(rev, \"\\"")}\n'
3549 $ hg log -r 2 -T '{if(rev, \"\\"")}\n'
3550 hg: parse error: trailing \ in string
3550 hg: parse error: trailing \ in string
@@ -219,7 +219,7 b' Invalid pattern in file name:'
219 $ hg export -o '%m{' tip
219 $ hg export -o '%m{' tip
220 hg: parse error at 3: unterminated template expansion
220 hg: parse error at 3: unterminated template expansion
221 (%m{
221 (%m{
222 ^ here)
222 ^ here)
223 [255]
223 [255]
224 $ hg export -o '%\' tip
224 $ hg export -o '%\' tip
225 abort: invalid format spec '%\' in output filename
225 abort: invalid format spec '%\' in output filename
@@ -2293,7 +2293,7 b' Templater parse errors:'
2293
2293
2294 simple error
2294 simple error
2295 $ hg log -r . -T '{shortest(node}'
2295 $ hg log -r . -T '{shortest(node}'
2296 hg: parse error at 15: unexpected token: end
2296 hg: parse error at 14: unexpected token: end
2297 ({shortest(node}
2297 ({shortest(node}
2298 ^ here)
2298 ^ here)
2299 [255]
2299 [255]
@@ -2303,7 +2303,7 b' multi-line template with error'
2303 > line2
2303 > line2
2304 > {shortest(node}
2304 > {shortest(node}
2305 > line4\nline5'
2305 > line4\nline5'
2306 hg: parse error at 28: unexpected token: end
2306 hg: parse error at 27: unexpected token: end
2307 (line 1\nline2\n{shortest(node}\nline4\nline5
2307 (line 1\nline2\n{shortest(node}\nline4\nline5
2308 ^ here)
2308 ^ here)
2309 [255]
2309 [255]
General Comments 0
You need to be logged in to leave comments. Login now