diff --git a/mode/html.py b/mode/html.py index 82880a0..0b39780 100644 --- a/mode/html.py +++ b/mode/html.py @@ -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, ')', TagGrammar, '>'), RegionRule('html.tag', '<(?=style[^a-zA-Z0-9_])', TagGrammar, '>', CSSGrammar, ')', TagGrammar, '>'), - RegionRule(r'comment', r''), - RegionRule(r'html.tag', r'<(?![\?!])', TagGrammar, r'/?>'), - RegionRule(r'html.metadata', r'<\?', MetadataGrammar, r'\?>'), - RegionRule(r'html.doctype', r''), - PatternRule(r'html.entity', r'&[a-z]+;'), - RegionRule(r'html.cdata', r''), + RegionRule('comment', r''), + RegionRule('html.tag', r'<(?![\?!])', TagGrammar, r'/?>'), + RegionRule('html.metadata', r'<\?', MetadataGrammar, r'\?>'), + RegionRule('html.doctype', r''), + PatternRule('html.entity', r'&[a-z]+;'), + RegionRule('html.cdata', r''), ] class HtmlViewPage(method.Method): diff --git a/mode/tt.py b/mode/tt.py index 6cfa241..c27e516 100644 --- a/mode/tt.py +++ b/mode/tt.py @@ -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''), - 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''), + crule, drule, prule, + PatternRule('escaped', '&[^;]+;'), + PatternRule('html.data', r'[^\[&<]+'), + PatternRule('html.data', '[^&<]+'), + RegionRule('html.tag', '<(?=script[^a-zA-Z0-9_])', TagGrammar, '>', + JavascriptGrammar, ')', TagGrammar, '>'), + RegionRule('html.tag', '<(?=style[^a-zA-Z0-9_])', TagGrammar, '>', + CSSGrammar, ')', TagGrammar, '>'), + RegionRule('comment', ''), + RegionRule('html.tag', r'<(?![\?!])', TagGrammar, '/?>'), + RegionRule('html.metadata', r'<\?', MetadataGrammar, r'\?>'), + RegionRule('html.doctype', ''), + PatternRule('html.entity', '&[a-z]+;'), + RegionRule('html.cdata', 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 = {