pmacs3/mode/cheetah.py

55 lines
2.0 KiB
Python
Raw Permalink Normal View History

2009-03-29 20:50:27 -04:00
from mode import Fundamental
2008-01-27 15:10:13 -05:00
from lex import Grammar, PatternRule, RegionRule
2008-04-18 10:12:30 -04:00
class StringGrammar(Grammar):
rules = [
PatternRule('cheetah.placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'),
PatternRule('cheetah.placeholder', r'\$[a-zA-Z0-9_.\[\]]+'),
2009-03-29 20:50:27 -04:00
PatternRule('octal', r'\\[0-7]{3}'),
PatternRule('escaped', r'\\.'),
PatternRule('data', r'[^\$\\]+'),
2008-04-18 10:12:30 -04:00
]
2008-01-27 15:10:13 -05:00
class TagGrammar(Grammar):
rules = [
PatternRule('cheetah.placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'),
PatternRule('cheetah.placeholder', r'\$[a-zA-Z0-9_.\[\]]+'),
2009-03-29 20:50:27 -04:00
RegionRule('string', '"', StringGrammar, '"'),
RegionRule('string', "'", StringGrammar, "'"),
PatternRule('namespace', '[a-zA-Z_]+:'),
PatternRule('attrname', r'[^ =>\n]+(?==)'),
PatternRule('name', r'[^\[\] =>\n]+'),
2008-01-27 15:10:13 -05:00
]
class TemplateGrammar(Grammar):
rules = [
2009-03-29 20:50:27 -04:00
RegionRule('comment', r'#\*', Grammar, r'\*#'),
PatternRule('comment', r'##.*\n'),
PatternRule('cheetah.placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'),
PatternRule('cheetah.placeholder', r'\$[a-zA-Z0-9_.\[\]]+'),
PatternRule('cheetah.directive', r'#.*?[#\n]'),
RegionRule('cheetah.tag', '</?', TagGrammar, '/?>'),
2008-01-27 15:10:13 -05:00
]
2009-03-29 20:50:27 -04:00
class Template(Fundamental):
name = 'Cheetah'
2008-01-27 15:10:13 -05:00
extensions = ['.tmpl']
grammar = TemplateGrammar
2009-02-15 12:06:35 -05:00
commentc = '##'
2008-01-27 15:10:13 -05:00
colors = {
'cheetah.directive': ('magenta', 'default', 'bold'),
'cheetah.placeholder': ('magenta', 'default', 'bold'),
'cheetah.tag.start': ('default', 'default', 'bold'),
'cheetah.tag.namespace': ('magenta', 'default', 'bold'),
'cheetah.tag.name': ('blue', 'default', 'bold'),
'cheetah.tag.attrname': ('cyan', 'default', 'bold'),
'cheetah.tag.end': ('default', 'default', 'bold'),
2008-01-27 15:10:13 -05:00
}
2009-02-15 12:06:35 -05:00
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
2008-01-27 15:10:13 -05:00
install = Template.install