From 95c7facf830deabbe49e9c1953cfb018e42f3b4c Mon Sep 17 00:00:00 2001 From: moculus Date: Mon, 18 Jun 2007 19:09:00 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- application.py | 7 ++--- mode_xml.py | 70 +++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/application.py b/application.py index dd4a629..746e21d 100755 --- a/application.py +++ b/application.py @@ -11,6 +11,7 @@ from point2 import Point #import mode_replace, mode_xml, mode_console, mode_sh, mode_text, mode_which #import mode_mutt, mode_sql, mode_javascript, mode_diff, mode_blame, mode_tt import mode2, mode_mini, mode_python, mode_perl, mode_search, mode_replace +import mode_xml def run(buffers, jump_to_line=None, init_mode=None): # save terminal state so we can restore it when the program exits @@ -92,7 +93,7 @@ class Application(object): # 'sh': mode_sh.Sh, # 'text': mode_text.Text, # 'which': mode_which.Which, -# 'xml': mode_xml.XML, + 'xml': mode_xml.XML, # 'mutt': mode_mutt.Mutt, # 'sql': mode_sql.Sql, # 'javascript': mode_javascript.Javascript, @@ -119,8 +120,8 @@ class Application(object): # '.s': 'nasm', # '.sh': 'sh', # '.bash': 'sh', -# '.xml': 'xml', -# '.xml.in': 'xml', + '.xml': 'xml', + '.xml.in': 'xml', # '.html': 'xml', # '.htm': 'xml', # '.sql': 'sql', diff --git a/mode_xml.py b/mode_xml.py index 09b90b0..254d831 100644 --- a/mode_xml.py +++ b/mode_xml.py @@ -1,12 +1,55 @@ import sets, sys -import color, commands, default, lex, lex_xml, method, mode, point, regex, tab_xml +import color, commands, default, lex2, method, mode, point, regex +from lex2 import Grammar, ConstantRule, PatternRule, RegionRule, DualRegionRule + +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 XMLGrammar(Grammar): + rules = [ + RegionRule( + name=r'comment', + start=r'', + ), + RegionRule( + name=r'opentag', + start=r'<', + grammar=TagGrammar(), + end=r'/?>', + ), + PatternRule( + name=r'closetag', + pattern=r'< */ *[ =>\n]+ *>', + ), + ] class XML(mode.Fundamental): def __init__(self, w): mode.Fundamental.__init__(self, w) - self.grammar = lex_xml.XMLGrammar() - self.lexer = lex.Lexer(self.grammar) + self.grammar = XMLGrammar() + self.lexer = lex2.Lexer(self.name(), self.grammar) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) @@ -14,19 +57,16 @@ class XML(mode.Fundamental): self.default_color = color.build('default', 'default') self.colors = { - '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'), + '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.highlighter.lex_buffer() - #self.get_regions() - self.tabber = tab_xml.XMLTabber(self) - def name(self): return "XML"