Changeset 12
- Timestamp:
- 12/08/04 15:17:03 (8 years ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
. (modified) (1 prop)
-
airspeed.py (modified) (3 diffs)
-
airspeed_test.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:ignore set
to
*.pyc
-
Property
svn:ignore set
to
-
trunk/airspeed.py
r11 r12 8 8 9 9 class Tokeniser: 10 PLAIN, IF, PLACEHOLDER, FOREACH, END, SET = range(6)10 PLAIN, IF, PLACEHOLDER, FOREACH, END, SET, ELSE = range(7) 11 11 12 12 UP_TO_NEXT_TEMPLATE_BIT = re.compile('^(.*?)((?:#|\$).*)', re.MULTILINE + re.DOTALL) … … 14 14 NAME = '[a-z0-9_]+' 15 15 NAME_OR_CALL = NAME + '(?:\(\))?' 16 RE_FLAGS = re.IGNORECASE + re.DOTALL + re.MULTILINE 16 17 EXPRESSION = '(' + NAME_OR_CALL + '(?:\.' + NAME_OR_CALL + ')*)' 17 PLACEHOLDER_PATTERN = re.compile('^\$(!?)({?)' + EXPRESSION + '(}?)' + REST, re.IGNORECASE + re.DOTALL + re.MULTILINE) 18 SET_PATTERN = re.compile('^#set[ \t]*\([ \t]*\$(' + NAME + ')[ \t]*=[ \t]*(\d+|"[^"]+")[ \t]*\)' + REST, re.IGNORECASE + re.DOTALL + re.MULTILINE) 19 BEGIN_IF_PATTERN = re.compile('^#if[ \t]*\([ \t]*\$' + EXPRESSION + '[ \t]*\)' + REST, re.IGNORECASE + re.DOTALL + re.MULTILINE) 20 BEGIN_FOREACH_PATTERN = re.compile('^#foreach[ \t]*\([ \t]*\$(' + NAME + ')[ \t]+in[ \t]+\$' + EXPRESSION + '[ \t]*\)' + REST, re.IGNORECASE + re.DOTALL + re.MULTILINE) 21 END_PATTERN = re.compile('^#end' + REST, re.IGNORECASE + re.DOTALL + re.MULTILINE) 18 PLACEHOLDER_PATTERN = re.compile('^\$(!?)({?)' + EXPRESSION + '(}?)' + REST, RE_FLAGS) 19 SET_PATTERN = re.compile('^#set[ \t]*\([ \t]*\$(' + NAME + ')[ \t]*=[ \t]*(\d+|"[^"]+")[ \t]*\)' + REST, RE_FLAGS) 20 BEGIN_IF_PATTERN = re.compile('^#if[ \t]*\([ \t]*\$' + EXPRESSION + '[ \t]*\)' + REST, RE_FLAGS) 21 BEGIN_FOREACH_PATTERN = re.compile('^#foreach[ \t]*\([ \t]*\$(' + NAME + ')[ \t]+in[ \t]+\$' + EXPRESSION + '[ \t]*\)' + REST, RE_FLAGS) 22 END_PATTERN = re.compile('^#end' + REST, RE_FLAGS) 23 ELSE_PATTERN = re.compile('^#else' + REST, RE_FLAGS) 24 COMMENT_PATTERN = re.compile('^##.*?(?:\n|$)' + REST, RE_FLAGS) 25 MULTI_LINE_COMMENT_PATTERN = re.compile('^#\*.*?\*#(?:[ \t]*\n)?' + REST, RE_FLAGS) 22 26 23 27 def tokenise(self, text): … … 53 57 (var_name, rvalue, text) = m.groups() 54 58 yield self.SET, (var_name, rvalue) 59 continue 60 m = self.ELSE_PATTERN.match(interesting) 61 if m: 62 (text,) = m.groups() 63 yield self.ELSE, None 64 continue 65 m = self.COMMENT_PATTERN.match(interesting) 66 if m: 67 (text,) = m.groups() 68 continue 69 m = self.MULTI_LINE_COMMENT_PATTERN.match(interesting) 70 if m: 71 (text,) = m.groups() 55 72 continue 56 73 if interesting.startswith('$'): -
trunk/airspeed_test.py
r11 r12 131 131 self.assertEquals("Steve", template.merge({})) 132 132 133 def test_single_line_comments_skipped(self): 134 template = airspeed.Template('## comment\nStuff\nMore stuff## more comments $blah') 135 self.assertEquals("Stuff\nMore stuff", template.merge({})) 136 137 def test_multi_line_comments_skipped(self): 138 template = airspeed.Template('Stuff#*\n more comments *#\n and more stuff') 139 self.assertEquals("Stuff and more stuff", template.merge({})) 133 140 134 141 if __name__ == '__main__':
