template toolkit updates

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-05-06 18:39:26 +00:00
parent ca649aa7e1
commit 6d538a1b10
2 changed files with 50 additions and 29 deletions

View File

@ -13,6 +13,7 @@ class DoctypeGrammar(Grammar):
class HTMLGrammar(Grammar):
rules = [
PatternRule(r'escaped', r'&[^;]+;'),
PatternRule(r'html.data', r'[^&<]+'),
# BUG: not all scripts are javascript and not all styles are CSS but
# dynamically choosing a grammar based on the 'type' attribute (which
@ -21,12 +22,12 @@ class HTMLGrammar(Grammar):
JavascriptGrammar, '</(?=script>)', TagGrammar, '>'),
RegionRule('html.tag', '<(?=style[^a-zA-Z0-9_])', TagGrammar, '>',
CSSGrammar, '</(?=style>)', TagGrammar, '>'),
RegionRule(r'comment', r'<!--', CommentGrammar, r'-->'),
RegionRule(r'html.tag', r'<(?![\?!])', TagGrammar, r'/?>'),
RegionRule(r'html.metadata', r'<\?', MetadataGrammar, r'\?>'),
RegionRule(r'html.doctype', r'<!', DoctypeGrammar, r'>'),
PatternRule(r'html.entity', r'&[a-z]+;'),
RegionRule(r'html.cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
RegionRule('comment', r'<!--', CommentGrammar, r'-->'),
RegionRule('html.tag', r'<(?![\?!])', TagGrammar, r'/?>'),
RegionRule('html.metadata', r'<\?', MetadataGrammar, r'\?>'),
RegionRule('html.doctype', r'<!', DoctypeGrammar, r'>'),
PatternRule('html.entity', r'&[a-z]+;'),
RegionRule('html.cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
]
class HtmlViewPage(method.Method):

View File

@ -1,38 +1,58 @@
import color, mode
from lex import Grammar, PatternRule, RegionRule
import mode.xml
import mode.html
import mode.javascript
import mode.css
from mode.perl import StringGrammar, PerlGrammar
class PerlDirectiveGrammar(Grammar):
rules = [PatternRule(r'tt.perl', r'(?:PERL|RAWPERL|END)(?![A-Z_])')]
rules = [PatternRule('tt.perl', '(?:PERL|RAWPERL|END)(?![A-Z_])')]
class DirectiveGrammar(Grammar):
rules = [
PatternRule(r'tt.keyword', r'(?:BLOCK|CALL|CASE|CATCH|CLEAR|DEBUG|DEFAULT|FINAL|FILTER|FOREACH|ELSIF|ELSE|END|GET|IF|INCLUDE|INSERT|IN|LAST|MACRO|META|NEXT|PERL|PROCESS|RAWPERL|RETURN|SET|STOP|SWITCH|TAGS|THROW|TRY|UNLESS|USE|WHILE|WRAPPER)(?![A-Z_])'),
PatternRule(r'attribute', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *=)'),
RegionRule(r'string', r'"', StringGrammar, r'"'),
RegionRule(r'string', r"'", StringGrammar, r"'"),
PatternRule('tt.keyword', r'(?:BLOCK|CALL|CASE|CATCH|CLEAR|DEBUG|DEFAULT|FINAL|FILTER|FOREACH|ELSIF|ELSE|END|GET|IF|INCLUDE|INSERT|IN|LAST|MACRO|META|NEXT|PERL|PROCESS|RAWPERL|RETURN|SET|STOP|SWITCH|TAGS|THROW|TRY|UNLESS|USE|WHILE|WRAPPER)(?![A-Z_])'),
PatternRule('attribute', '[a-zA-Z_][a-zA-Z0-9_]*(?= *=)'),
RegionRule('string', '"', StringGrammar, '"'),
RegionRule('string', "'", StringGrammar, "'"),
]
crule = RegionRule('comment', r'\[\%#', Grammar, r'%%\]')
drule = RegionRule('tt.directive', r'\[\%', DirectiveGrammar, r'%%\]')
prule = RegionRule('tt.directive', r'\[\%(?= *PERL)', PerlDirectiveGrammar,
r'%%\]', PerlGrammar, r'\[%%', PerlDirectiveGrammar, '%%\]')
class TagGrammar(Grammar):
rules = [
RegionRule(r'tt.directive', r'\[\%', DirectiveGrammar, r'%%\]'),
RegionRule(r'string', r'"', Grammar, r'"'),
RegionRule(r'string', r"'", Grammar, r"'"),
PatternRule(r'namespace', r'[a-zA-Z_]+:'),
PatternRule(r'attrname', r'[^ =>\n]+(?==)'),
PatternRule(r'name', r'[^\[\] =>\n]+'),
]
rules = [crule, drule, prule] + mode.html.TagGrammar.rules
class JavascriptGrammar(Grammar):
rules = [crule, drule, prule] + mode.javascript.JavascriptGrammar.rules
class CSSGrammar(Grammar):
rules = [crule, drule, prule] + mode.css.CSSGrammar.rules
class CommentGrammar(Grammar):
rules = [crule, drule, prule] + mode.html.CommentGrammar.rules
class CDataGrammar(Grammar):
rules = [crule, drule, prule] + mode.html.CDataGrammar.rules
class MetadataGrammar(Grammar):
rules = [crule, drule, prule] + mode.html.MetadataGrammar.rules
class DoctypeGrammar(Grammar):
rules = [crule, drule, prule] + mode.html.MetadataGrammar.rules
class TemplateGrammar(Grammar):
rules = [
PatternRule(r'escaped', r'&[^;]+;'),
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
RegionRule(r'comment', r'\[\%#', Grammar, r'%%\]'),
PatternRule(r'tt.data', r'[^\[<&]+'),
RegionRule(r'tt.directive', r'\[\%(?= *PERL)', PerlDirectiveGrammar,
r'%%\]', PerlGrammar, r'\[%%', PerlDirectiveGrammar, '%%\]'),
RegionRule(r'tt.directive', r'\[\%', DirectiveGrammar, r'%%\]'),
RegionRule(r'tt.tag', r'</?(?=[a-zA-Z_])', TagGrammar, r'/?>'),
crule, drule, prule,
PatternRule('escaped', '&[^;]+;'),
PatternRule('html.data', r'[^\[&<]+'),
PatternRule('html.data', '[^&<]+'),
RegionRule('html.tag', '<(?=script[^a-zA-Z0-9_])', TagGrammar, '>',
JavascriptGrammar, '</(?=script>)', TagGrammar, '>'),
RegionRule('html.tag', '<(?=style[^a-zA-Z0-9_])', TagGrammar, '>',
CSSGrammar, '</(?=style>)', TagGrammar, '>'),
RegionRule('comment', '<!--', CommentGrammar, '-->'),
RegionRule('html.tag', r'<(?![\?!])', TagGrammar, '/?>'),
RegionRule('html.metadata', r'<\?', MetadataGrammar, r'\?>'),
RegionRule('html.doctype', '<!', DoctypeGrammar, '>'),
PatternRule('html.entity', '&[a-z]+;'),
RegionRule('html.cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
]
class Template(mode.Fundamental):
@ -53,14 +73,14 @@ class Template(mode.Fundamental):
'tt.directive.middle0': ('magenta', 'default', 'bold'),
'tt.directive.middle1': ('magenta', 'default', 'bold'),
'tt.directive.end': ('magenta', 'default', 'bold'),
'tt.tag.start': ('default', 'default', 'bold'),
'tt.tag.start': ('default', 'default'),
'tt.tag.namespace': ('magenta', 'default', 'bold'),
'tt.tag.name': ('blue', 'default', 'bold'),
'tt.tag.attrname': ('cyan', 'default', 'bold'),
'tt.tag.string.start': ('green', 'default', 'bold'),
'tt.tag.string.null': ('green', 'default', 'bold'),
'tt.tag.string.end': ('green', 'default', 'bold'),
'tt.tag.end': ('default', 'default', 'bold'),
'tt.tag.end': ('default', 'default'),
'tt.perl': ('red', 'default', 'bold'),
}
_bindings = {