branch : pmacs2
This commit is contained in:
moculus 2007-06-18 19:09:00 +00:00
parent 6ca089f3b7
commit 95c7facf83
2 changed files with 59 additions and 18 deletions

View File

@ -11,6 +11,7 @@ from point2 import Point
#import mode_replace, mode_xml, mode_console, mode_sh, mode_text, mode_which #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 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 mode2, mode_mini, mode_python, mode_perl, mode_search, mode_replace
import mode_xml
def run(buffers, jump_to_line=None, init_mode=None): def run(buffers, jump_to_line=None, init_mode=None):
# save terminal state so we can restore it when the program exits # save terminal state so we can restore it when the program exits
@ -92,7 +93,7 @@ class Application(object):
# 'sh': mode_sh.Sh, # 'sh': mode_sh.Sh,
# 'text': mode_text.Text, # 'text': mode_text.Text,
# 'which': mode_which.Which, # 'which': mode_which.Which,
# 'xml': mode_xml.XML, 'xml': mode_xml.XML,
# 'mutt': mode_mutt.Mutt, # 'mutt': mode_mutt.Mutt,
# 'sql': mode_sql.Sql, # 'sql': mode_sql.Sql,
# 'javascript': mode_javascript.Javascript, # 'javascript': mode_javascript.Javascript,
@ -119,8 +120,8 @@ class Application(object):
# '.s': 'nasm', # '.s': 'nasm',
# '.sh': 'sh', # '.sh': 'sh',
# '.bash': 'sh', # '.bash': 'sh',
# '.xml': 'xml', '.xml': 'xml',
# '.xml.in': 'xml', '.xml.in': 'xml',
# '.html': 'xml', # '.html': 'xml',
# '.htm': 'xml', # '.htm': 'xml',
# '.sql': 'sql', # '.sql': 'sql',

View File

@ -1,12 +1,55 @@
import sets, sys 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<tag>["\'])',
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'<!--',
grammar=Grammar(),
end=r'-->',
),
RegionRule(
name=r'opentag',
start=r'<',
grammar=TagGrammar(),
end=r'/?>',
),
PatternRule(
name=r'closetag',
pattern=r'< */ *[ =>\n]+ *>',
),
]
class XML(mode.Fundamental): class XML(mode.Fundamental):
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) mode.Fundamental.__init__(self, w)
self.grammar = lex_xml.XMLGrammar() self.grammar = XMLGrammar()
self.lexer = lex.Lexer(self.grammar) self.lexer = lex2.Lexer(self.name(), self.grammar)
self.add_bindings('close-paren', (')',)) self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',)) self.add_bindings('close-brace', ('}',))
@ -14,19 +57,16 @@ class XML(mode.Fundamental):
self.default_color = color.build('default', 'default') self.default_color = color.build('default', 'default')
self.colors = { self.colors = {
'namespace': color.build('magenta', 'default'), 'comment': color.build('red', 'default'),
'opentag': color.build('blue', 'default'), 'opentag.start': color.build('default', 'default'),
'nodevalue': color.build('default', 'default'), 'opentag.namespace': color.build('magenta', 'default'),
'attrname': color.build('cyan', 'default'), 'opentag.name': color.build('blue', 'default'),
'attrvalue': color.build('green', 'default'), 'opentag.attrname': color.build('cyan', 'default'),
'closetag': color.build('blue', 'default'), 'opentag.string.start': color.build('green', 'default'),
'comment': color.build('red', 'default'), 'opentag.string.null': color.build('green', 'default'),
'bizzaro': color.build('magenta', 'green'), '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): def name(self):
return "XML" return "XML"