Fix the comment parsing: allow more than simply alphanums in the text. Now
it allows everything but the closing bracket. Add some commentary for the regex since it is central to the operation of the templating engine. git-svn-id: http://viewvc.tigris.org/svn/viewvc/trunk@215 8cb11bc2-c004-0410-86c3-e597b4017df7remotes/tags/V0_8
parent
4e07d3a2ae
commit
27bcce39a8
18
lib/ezt.py
18
lib/ezt.py
|
@ -35,7 +35,19 @@ import string
|
||||||
import re
|
import re
|
||||||
from types import StringType, IntType, FloatType
|
from types import StringType, IntType, FloatType
|
||||||
|
|
||||||
_re_parse = re.compile('(\[[-\w.# ]+\])|(\[\[\])')
|
#
|
||||||
|
# This regular expression matches three alternatives:
|
||||||
|
# expr: DIRECTIVE | BRACKET | COMMENT
|
||||||
|
# DIRECTIVE: '[' ('-' | '.' | ' ' | alphanum)+ ']
|
||||||
|
# BRACKET: '[[]'
|
||||||
|
# COMMENT: '[#' not-rbracket* ']'
|
||||||
|
#
|
||||||
|
# When used with the split() method, the return value will be composed of
|
||||||
|
# non-matching text and the two paren groups (DIRECTIVE and BRACKET). Since
|
||||||
|
# the COMMENT matches are not placed into a group, they are considered a
|
||||||
|
# "splitting" value and simply dropped.
|
||||||
|
#
|
||||||
|
_re_parse = re.compile('(\[[-\w. ]+\])|(\[\[\])|\[#[^\]]*\]')
|
||||||
|
|
||||||
# block commands and their argument counts
|
# block commands and their argument counts
|
||||||
_block_cmd_specs = { 'if-any':1, 'if-index':2, 'for':1 }
|
_block_cmd_specs = { 'if-any':1, 'if-index':2, 'for':1 }
|
||||||
|
@ -54,6 +66,7 @@ class Template:
|
||||||
# parse the program into: (TEXT DIRECTIVE BRACKET)* TEXT
|
# parse the program into: (TEXT DIRECTIVE BRACKET)* TEXT
|
||||||
# DIRECTIVE will be '[directive]' or None
|
# DIRECTIVE will be '[directive]' or None
|
||||||
# BRACKET will be '[[]' or None
|
# BRACKET will be '[[]' or None
|
||||||
|
# note that comments are automatically dropped
|
||||||
parts = _re_parse.split(text)
|
parts = _re_parse.split(text)
|
||||||
|
|
||||||
program = [ ]
|
program = [ ]
|
||||||
|
@ -74,9 +87,6 @@ class Template:
|
||||||
# DIRECTIVE is present.
|
# DIRECTIVE is present.
|
||||||
args = string.split(piece[1:-1])
|
args = string.split(piece[1:-1])
|
||||||
cmd = args[0]
|
cmd = args[0]
|
||||||
if cmd == '#':
|
|
||||||
# comment
|
|
||||||
continue
|
|
||||||
if cmd == 'else':
|
if cmd == 'else':
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
raise ArgCountSyntaxError()
|
raise ArgCountSyntaxError()
|
||||||
|
|
Loading…
Reference in New Issue