diff --git a/application.py b/application.py
index 1ef10a6..13e37a2 100755
--- a/application.py
+++ b/application.py
@@ -7,12 +7,12 @@ import util, window2
from point2 import Point
# modes
-# TODO: mode_sql mode_tt
import mode2
import mode_mini, mode_search, mode_replace, mode_which
import mode_console, mode_consolemini
import mode_blame, mode_diff
-import mode_c, mode_python, mode_perl, mode_xml, mode_nasm, mode_sh, mode_javascript, mode_sql
+import mode_c, mode_python, mode_perl, mode_nasm, mode_sh, mode_javascript, mode_sql
+import mode_xml, mode_tt
import mode_life, mode_text, mode_mutt
def run(buffers, jump_to_line=None, init_mode=None):
@@ -101,7 +101,7 @@ class Application(object):
'mutt': mode_mutt.Mutt,
'javascript': mode_javascript.Javascript,
'sql': mode_sql.Sql,
- #'template': mode_tt.Template,
+ 'template': mode_tt.Template,
}
# these are used in this order to determine which mode to open certain
@@ -130,7 +130,7 @@ class Application(object):
'.htm': 'xml',
'.js': 'javascript',
'.sql': 'sql',
- #'.tt': 'template'
+ '.tt': 'template'
}
self.mode_detection = {
'python': 'python',
diff --git a/code_examples/body.tt b/code_examples/body.tt
new file mode 100644
index 0000000..407b627
--- /dev/null
+++ b/code_examples/body.tt
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+ [% INCLUDE "links.tt" %]
+
+
+
+
+
+
+
+
+
+[%# triggers here %]
+
+[% FOREACH field IN hidden_fields %]
+
+[% END %]
+
+
+
+[% INCLUDE body_footer.tt %]
+
+[% INCLUDE debug_footer.tt %]
+
+[% INCLUDE glos_help.tt %]
+
+
diff --git a/mode_tt.py b/mode_tt.py
index b035049..a2d3d51 100644
--- a/mode_tt.py
+++ b/mode_tt.py
@@ -1,33 +1,42 @@
-import sets, sys
-import color, commands, default, lex, lex_tt, method, mode, point, regex, tab_xml
+import color, mode2
+from lex2 import Grammar, PatternRule, RegionRule
-class Template(mode.Fundamental):
+class TagGrammar(Grammar):
+ rules = [
+ RegionRule(name=r'string', start=r'(?P["\'])', grammar=Grammar(), end=r'%(tag)s'),
+ PatternRule(name=r'namespace', pattern=r'[a-zA-Z_]+:'),
+ PatternRule(name=r'attrname', pattern=r'[^ =>\n]+(?==)'),
+ PatternRule(name=r'name', pattern=r'[^ =>\n]+'),
+ ]
+
+class TemplateGrammar(Grammar):
+ rules = [
+ RegionRule(name=r'comment', start=r''),
+ RegionRule(name=r'template', start=r'\[\%', grammar=Grammar(), end=r'%%\]'),
+ RegionRule(name=r'opentag', start=r'<', grammar=TagGrammar(), end=r'/?>'),
+ PatternRule(name=r'closetag', pattern=r'< */ *[ =>\n]+ *>'),
+ ]
+
+class Template(mode2.Fundamental):
+ grammar = TemplateGrammar
def __init__(self, w):
- mode.Fundamental.__init__(self, w)
-
- #self.grammar = lex_xml.XMLGrammar()
- self.grammar = lex_tt.TTGrammar()
- self.lexer = lex.Lexer(self.grammar)
-
+ mode2.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
-
- self.default_color = color.build('default', 'default')
self.colors = {
- 'template': color.build('magenta', 'default'),
- 'markup': color.build('red', 'default'),
- 'namespace': color.build('magenta', 'default'),
- 'opentag': color.build('blue', 'default'),
- 'nodevalue': color.build('default', 'default'),
- 'attrname': color.build('cyan', 'default'),
- 'attrvalue': color.build('green', 'default'),
- 'closetag': color.build('blue', 'default'),
- 'comment': color.build('red', 'default'),
- 'bizzaro': color.build('magenta', 'green'),
+ 'comment': color.build('red', 'default'),
+ 'template.start': color.build('magenta', 'default'),
+ 'template.null': color.build('magenta', 'default'),
+ 'template.end': color.build('magenta', 'default'),
+ 'opentag.start': color.build('default', 'default'),
+ 'opentag.namespace': color.build('magenta', 'default'),
+ 'opentag.name': color.build('blue', 'default'),
+ 'opentag.attrname': color.build('cyan', 'default'),
+ 'opentag.string.start': color.build('green', 'default'),
+ 'opentag.string.null': color.build('green', 'default'),
+ 'opentag.string.end': color.build('green', 'default'),
+ 'opentag.end': color.build('default', 'default'),
}
-
- self.tabber = tab_xml.XMLTabber(self)
-
def name(self):
return "Template"
diff --git a/mode_xml.py b/mode_xml.py
index 254d831..9a37ea3 100644
--- a/mode_xml.py
+++ b/mode_xml.py
@@ -1,5 +1,4 @@
-import sets, sys
-import color, commands, default, lex2, method, mode, point, regex
+import color, mode2
from lex2 import Grammar, ConstantRule, PatternRule, RegionRule, DualRegionRule
class TagGrammar(Grammar):
@@ -44,18 +43,13 @@ class XMLGrammar(Grammar):
),
]
-class XML(mode.Fundamental):
+class XML(mode2.Fundamental):
+ grammar = XMLGrammar
def __init__(self, w):
- mode.Fundamental.__init__(self, w)
-
- self.grammar = XMLGrammar()
- self.lexer = lex2.Lexer(self.name(), self.grammar)
-
+ mode2.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
-
- self.default_color = color.build('default', 'default')
self.colors = {
'comment': color.build('red', 'default'),
'opentag.start': color.build('default', 'default'),
@@ -67,6 +61,5 @@ class XML(mode.Fundamental):
'opentag.string.end': color.build('green', 'default'),
'opentag.end': color.build('default', 'default'),
}
-
def name(self):
return "XML"