[svn] added jinja whitespace prevention system (tm) ^^
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent c2fde02 · Browse files · 1 file·+46 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+46 added−9 removed
- other:+46 added−9 removed
Provenance
- Commit
a6c3ac5- Tree
71180f3- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
c2fde02
1 file changed+46 added−9 removed
modified:jinja/lexer.py+46 added-9 removed
65 unmodified lines66 # shortcuts67 c = lambda x: re.compile(x, re.M | re.S)68 e = re.escape69 70- # parsing rules for tags70+ # lexing rules for tags71 tag_rules = [72 (whitespace_re, None, None),73 (number_re, 'number', None),74 (name_re, 'name', None),11 unmodified lines86 ('variable', environment.variable_start_string)87 ]88 root_tag_rules.sort(lambda a, b: cmp(len(b[1]), len(a[1])))89 90+ # block suffix if trimming is enabled91+ block_suffix_re = environment.trim_blocks and '\\n?' or ''92+90- # global parsing rules93+ # global lexing rules94 self.rules = {95 'root': [93- (c('(%s\s*raw\s%s)(.*?)(%s\s*endraw\s*%s)' % (94- (e(environment.block_start_string),95- e(environment.block_end_string)) * 2)),96- (None, 'data', None), None),96+ # raw directive with whitespace rule97+ (c('(\s*%s\-\sraw\s\-?%s)' % (98+ e(environment.block_start_string),99+ e(environment.block_end_string)100+ )), (None,), 'raw'),101+ # raw directive without whitespace rule102+ (c('(%s\sraw\s\-?%s)' % (103+ e(environment.block_start_string),104+ e(environment.block_end_string)105+ )), (None,), 'raw'),106+ # directives with dropped leading whitespace107 (c('(.*?)(?:%s)' % '|'.join([108+ '(?P<%s_begin>\s*%s\-)' % (n, e(r)) for n, r in root_tag_rules109+ ])), ('data', '#bygroup'), '#bygroup'),110+ # directives with normal semantics111+ (c('(.*?)(?:%s)' % '|'.join([112 '(?P<%s_begin>%s)' % (n, e(r)) for n, r in root_tag_rules113 ])), ('data', '#bygroup'), '#bygroup'),114+ # data115 (c('.+'), 'data', None)116 ],117+ # comments118 'comment_begin': [119 (c(r'(.*?)(%s)' % e(environment.comment_end_string)),120 ('comment', 'comment_end'), '#pop'),121 (c('(.)'), (Failure('Missing end of comment tag'),), None)122 ],123+ # directives124 'block_begin': [108- (c(e(environment.block_end_string) +109- (environment.trim_blocks and '\\n?' or '')), 'block_end', '#pop')125+ # block end with dropping whitespace rule126+ (c('\-%s\s*' % e(environment.block_end_string)), 'block_end', '#pop'),127+ # regular block end128+ (c(e(environment.block_end_string) + block_suffix_re),129+ 'block_end', '#pop')130 ] + tag_rules,131+ # variables132 'variable_begin': [133 (c(e(environment.variable_end_string)), 'variable_end',134 '#pop')114- ] + tag_rules135+ ] + tag_rules,136+ # raw block137+ 'raw': [138+ # with whitespace rule139+ (c('(.*?)(%s\-?\s*endraw\s*\-%s%s\s*)' % (140+ environment.block_start_string,141+ environment.block_end_string,142+ block_suffix_re143+ )), ('data', None), '#pop'),144+ # without whitespace rule145+ (c('(.*?)(%s\-?\s*endraw\s*%s%s)' % (146+ environment.block_start_string,147+ environment.block_end_string,148+ block_suffix_re149+ )), ('data', None), '#pop'),150+ (c('(.)'), (Failure('Missing end of raw directive'),), None)151+ ]152 }153 154 def tokenize(self, source):155 """116 unmodified lines