pmacs3/mode/cheetah.py

58 lines
2.2 KiB
Python

from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule
class StringGrammar(Grammar):
rules = [
PatternRule('cheetah_placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'),
PatternRule('cheetah_placeholder', r'\$[a-zA-Z0-9_.\[\]]+'),
PatternRule('octal', r'\\[0-7]{3}'),
PatternRule('escaped', r'\\.'),
PatternRule('data', r'[^\$\\]+'),
]
class TagGrammar(Grammar):
rules = [
PatternRule('cheetah_placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'),
PatternRule('cheetah_placeholder', r'\$[a-zA-Z0-9_.\[\]]+'),
RegionRule('string', '"', StringGrammar, '"'),
RegionRule('string', "'", StringGrammar, "'"),
PatternRule('namespace', '[a-zA-Z_]+:'),
PatternRule('attrname', r'[^ =>\n]+(?==)'),
PatternRule('name', r'[^\[\] =>\n]+'),
]
class TemplateGrammar(Grammar):
rules = [
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, '/?>'),
]
class Template(Fundamental):
name = 'Cheetah'
extensions = ['.tmpl']
grammar = TemplateGrammar
commentc = '##'
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.string.start': ('green', 'default', 'bold'),
'cheetah_tag.string.null': ('green', 'default', 'bold'),
'cheetah_tag.string.end': ('green', 'default', 'bold'),
'cheetah_tag.end': ('default', 'default', 'bold'),
}
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
install = Template.install