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

View File

@ -1,38 +1,58 @@
import color, mode import color, mode
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule
import mode.xml
import mode.html
import mode.javascript
import mode.css
from mode.perl import StringGrammar, PerlGrammar from mode.perl import StringGrammar, PerlGrammar
class PerlDirectiveGrammar(Grammar): 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): class DirectiveGrammar(Grammar):
rules = [ 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('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_]*(?= *=)'), PatternRule('attribute', '[a-zA-Z_][a-zA-Z0-9_]*(?= *=)'),
RegionRule(r'string', r'"', StringGrammar, r'"'), RegionRule('string', '"', StringGrammar, '"'),
RegionRule(r'string', r"'", StringGrammar, r"'"), 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): class TagGrammar(Grammar):
rules = [ rules = [crule, drule, prule] + mode.html.TagGrammar.rules
RegionRule(r'tt.directive', r'\[\%', DirectiveGrammar, r'%%\]'), class JavascriptGrammar(Grammar):
RegionRule(r'string', r'"', Grammar, r'"'), rules = [crule, drule, prule] + mode.javascript.JavascriptGrammar.rules
RegionRule(r'string', r"'", Grammar, r"'"), class CSSGrammar(Grammar):
PatternRule(r'namespace', r'[a-zA-Z_]+:'), rules = [crule, drule, prule] + mode.css.CSSGrammar.rules
PatternRule(r'attrname', r'[^ =>\n]+(?==)'), class CommentGrammar(Grammar):
PatternRule(r'name', r'[^\[\] =>\n]+'), 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): class TemplateGrammar(Grammar):
rules = [ rules = [
PatternRule(r'escaped', r'&[^;]+;'), crule, drule, prule,
RegionRule(r'comment', r'<!--', Grammar, r'-->'), PatternRule('escaped', '&[^;]+;'),
RegionRule(r'comment', r'\[\%#', Grammar, r'%%\]'), PatternRule('html.data', r'[^\[&<]+'),
PatternRule(r'tt.data', r'[^\[<&]+'), PatternRule('html.data', '[^&<]+'),
RegionRule(r'tt.directive', r'\[\%(?= *PERL)', PerlDirectiveGrammar, RegionRule('html.tag', '<(?=script[^a-zA-Z0-9_])', TagGrammar, '>',
r'%%\]', PerlGrammar, r'\[%%', PerlDirectiveGrammar, '%%\]'), JavascriptGrammar, '</(?=script>)', TagGrammar, '>'),
RegionRule(r'tt.directive', r'\[\%', DirectiveGrammar, r'%%\]'), RegionRule('html.tag', '<(?=style[^a-zA-Z0-9_])', TagGrammar, '>',
RegionRule(r'tt.tag', r'</?(?=[a-zA-Z_])', TagGrammar, r'/?>'), 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): class Template(mode.Fundamental):
@ -53,14 +73,14 @@ class Template(mode.Fundamental):
'tt.directive.middle0': ('magenta', 'default', 'bold'), 'tt.directive.middle0': ('magenta', 'default', 'bold'),
'tt.directive.middle1': ('magenta', 'default', 'bold'), 'tt.directive.middle1': ('magenta', 'default', 'bold'),
'tt.directive.end': ('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.namespace': ('magenta', 'default', 'bold'),
'tt.tag.name': ('blue', 'default', 'bold'), 'tt.tag.name': ('blue', 'default', 'bold'),
'tt.tag.attrname': ('cyan', 'default', 'bold'), 'tt.tag.attrname': ('cyan', 'default', 'bold'),
'tt.tag.string.start': ('green', 'default', 'bold'), 'tt.tag.string.start': ('green', 'default', 'bold'),
'tt.tag.string.null': ('green', 'default', 'bold'), 'tt.tag.string.null': ('green', 'default', 'bold'),
'tt.tag.string.end': ('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'), 'tt.perl': ('red', 'default', 'bold'),
} }
_bindings = { _bindings = {