mode detection now uses regexes; modes updated
--HG-- branch : pmacs2
This commit is contained in:
parent
a098646d42
commit
d4ebbaf5c9
|
@ -698,7 +698,8 @@ class PerlContext(context.Context):
|
|||
class Perl(Fundamental):
|
||||
name = 'Perl'
|
||||
extensions = ['.pl', '.pm', '.pod']
|
||||
detection = ['perl']
|
||||
#detection = ['perl']
|
||||
detection = [re.compile('^#!(?:.+/)?perl')]
|
||||
tabbercls = PerlTabber2
|
||||
grammar = PerlGrammar
|
||||
commentc = '#'
|
||||
|
|
|
@ -560,7 +560,8 @@ class Python(mode.Fundamental):
|
|||
'''
|
||||
name = 'Python'
|
||||
extensions = ['.py']
|
||||
detection = ['python']
|
||||
#detection = ['python']
|
||||
detection = [re.compile('^#!(?:.+/)python')]
|
||||
tabbercls = PythonTabber
|
||||
grammar = PythonGrammar
|
||||
opentokens = ('delimiter',)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import re
|
||||
|
||||
import commands
|
||||
from tab import StackTabber
|
||||
from mode import Fundamental
|
||||
|
@ -190,7 +192,8 @@ class Sh(Fundamental):
|
|||
paths = ['/etc/profile']
|
||||
basenames = ['.bashrc', '.bash_profile', '.profile']
|
||||
extensions = ['.bash', '.sh']
|
||||
detection = ['sh', 'bash']
|
||||
#detection = ['sh', 'bash']
|
||||
detection = [re.compile('^#!(?:.+/)sh'), re.compile('^#!(?:.+/)bash')]
|
||||
grammar = ShGrammar
|
||||
tabbercls = ShTabber
|
||||
opentokens = ('delimiter', 'sh_reserved', 'case.start')
|
||||
|
|
95
mode/xml.py
95
mode/xml.py
|
@ -1,56 +1,55 @@
|
|||
import re
|
||||
|
||||
import color, method, mode
|
||||
from lex import Grammar, Rule, PatternRule, RegionRule, PatternMatchRule
|
||||
|
||||
class StringGrammar1(Grammar):
|
||||
rules = [
|
||||
PatternRule(r'data', r'[^"&]+'),
|
||||
PatternRule(r'escaped', r'&[a-z]+;'),
|
||||
PatternRule('data', '[^"&]+'),
|
||||
PatternRule('escaped', '&[a-z]+;'),
|
||||
]
|
||||
class StringGrammar2(Grammar):
|
||||
rules = [
|
||||
PatternRule(r'data', r"[^'&]+"),
|
||||
PatternRule(r'escaped', r'&[a-z]+;'),
|
||||
PatternRule('data', r"[^'&]+"),
|
||||
PatternRule('escaped', '&[a-z]+;'),
|
||||
]
|
||||
|
||||
class CDataGrammar(Grammar):
|
||||
rules = [PatternRule(r'data', r'(?:[^\]]|\](?!\])|\]\](?!>))+')]
|
||||
rules = [PatternRule('data', r'(?:[^\]]|\](?!\])|\]\](?!>))+')]
|
||||
class CommentGrammar(Grammar):
|
||||
rules = [PatternRule(r'data', r'(?:[^-]|-(?!-)|--(?!>))+')]
|
||||
class MetadataGrammar(Grammar):
|
||||
rules = [PatternRule(r'data', r'(?:[^?]|\?(?!>))+')]
|
||||
class DoctypeGrammar(Grammar):
|
||||
rules = [PatternRule(r'data', r'[^>]+')]
|
||||
|
||||
rules = [PatternRule('data', '(?:[^-]|-(?!-)|--(?!>))+')]
|
||||
class TagGrammar(Grammar):
|
||||
rules = [
|
||||
PatternRule(r'attrname', r'[a-zA-Z_][a-zA-Z0-9_]+(?==)'),
|
||||
PatternRule(r'namespace', r'[a-zA-Z_]+(?=:)'),
|
||||
PatternRule(r'meta', r'\?xml'),
|
||||
PatternRule(r'doctype', r'!DOCTYPE'),
|
||||
PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||
PatternRule(r'delimiter', r'[:/=]'),
|
||||
RegionRule(r'string', r'"', StringGrammar1, r'"'),
|
||||
RegionRule(r'string', r"'", StringGrammar2, r"'"),
|
||||
PatternRule(r'spaces', r' +'),
|
||||
PatternRule(r'eol', r'\n'),
|
||||
PatternRule('attrname', '[a-zA-Z_][a-zA-Z0-9_]+(?==)'),
|
||||
PatternRule('namespace', '[a-zA-Z_]+(?=:)'),
|
||||
PatternRule('name', '[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||
PatternRule('delimiter', '[:/=]'),
|
||||
RegionRule('string', '"', StringGrammar1, '"'),
|
||||
RegionRule('string', "'", StringGrammar2, "'"),
|
||||
PatternRule('spaces', ' +'),
|
||||
PatternRule('eol', r'\n'),
|
||||
]
|
||||
class MetadataGrammar(Grammar):
|
||||
rules = [PatternRule('meta', r'\?(?:xml)?')] + TagGrammar.rules
|
||||
class DoctypeGrammar(Grammar):
|
||||
rules = [PatternRule('doctype', '!DOCTYPE')] + TagGrammar.rules
|
||||
|
||||
class XMLGrammar(Grammar):
|
||||
rules = [
|
||||
# TODO: how does cdata work again?
|
||||
PatternRule(r'data', r'[^<& \n]+'),
|
||||
PatternRule(r'spaces', r' +'),
|
||||
PatternRule(r'xml.entity', r'&[a-z]+;'),
|
||||
PatternRule(r'eol', r'\n'),
|
||||
PatternMatchRule('x', r'(<)(/)([a-zA-Z_][a-zA-Z0-9_]*)(>)',
|
||||
PatternRule('data', r'[^<& \n]+'),
|
||||
PatternRule('spaces', ' +'),
|
||||
PatternRule('xml.entity', '&[a-z]+;'),
|
||||
PatternRule('eol', r'\n'),
|
||||
PatternMatchRule('x', '(<)(/)([a-zA-Z_][a-zA-Z0-9_]*)(>)',
|
||||
'xml.tag.start', 'xml.tag.delimiter', 'xml.tag.name',
|
||||
'xml.tag.end'),
|
||||
#RegionRule(r'xml.tag', r'<(?![\?!])', TagGrammar, r'/?>'),
|
||||
RegionRule(r'xml.tag', r'<', TagGrammar, r'/?>'),
|
||||
RegionRule(r'comment', r'<!--', CommentGrammar, r'-->'),
|
||||
#RegionRule(r'xml.metadata', r'<\?', MetadataGrammar, r'\?>'),
|
||||
#RegionRule(r'xml.doctype', '<!', DoctypeGrammar, '>'),
|
||||
RegionRule(r'xml.cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
|
||||
RegionRule('xml.tag', r'<(?![\?!])', TagGrammar, '/?>'),
|
||||
RegionRule('xml.tag', r'<(?![\?!])', TagGrammar, '/?>'),
|
||||
RegionRule('comment', '<!--', CommentGrammar, '-->'),
|
||||
RegionRule('xml.tag', r'<(?=\?)', MetadataGrammar, r'\?>'),
|
||||
RegionRule('xml.tag', '<(?!!)', DoctypeGrammar, '>'),
|
||||
RegionRule('xml.cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
|
||||
]
|
||||
|
||||
class XmlValidate(method.shell.Exec):
|
||||
|
@ -90,28 +89,20 @@ class XmlCreateCdata(method.Method):
|
|||
class XML(mode.Fundamental):
|
||||
name = 'XML'
|
||||
extensions = ['.xml', '.xml.in', '.xsl', '.xsd']
|
||||
detection = ['?xml']
|
||||
detection = [re.compile(r'^<\?xml')]
|
||||
grammar = XMLGrammar
|
||||
colors = {
|
||||
#'xml.metadata.start': ('magenta', 'default', 'bold'),
|
||||
#'xml.metadata.data': ('magenta', 'default', 'bold'),
|
||||
#'xml.metadata.end': ('magenta', 'default', 'bold'),
|
||||
#'xml.doctype.start': ('magenta', 'default', 'bold'),
|
||||
#'xml.doctype.data': ('magenta', 'default', 'bold'),
|
||||
#'xml.doctype.end': ('magenta', 'default', 'bold'),
|
||||
|
||||
'xml.tag.meta': ('magenta', 'default', 'bold'),
|
||||
'xml.tag.doctype': ('magenta', 'default', 'bold'),
|
||||
|
||||
'xml.tag.start': ('default', 'default', 'bold'),
|
||||
'xml.tag.namespace': ('magenta', 'default', 'bold'),
|
||||
'xml.tag.name': ('blue', 'default', 'bold'),
|
||||
'xml.tag.attrname': ('cyan', 'default', 'bold'),
|
||||
'xml.tag.end': ('default', 'default', 'bold'),
|
||||
'xml.entity': ('magenta', 'default', 'bold'),
|
||||
'xml.cdata.start': ('magenta', 'default', 'bold'),
|
||||
'xml.cdata.data': ('green', 'default', 'bold'),
|
||||
'xml.cdata.end': ('magenta', 'default', 'bold'),
|
||||
'xml.tag.meta': ('magenta', 'default', 'bold'),
|
||||
'xml.tag.doctype': ('magenta', 'default', 'bold'),
|
||||
'xml.tag.start': ('default', 'default', 'bold'),
|
||||
'xml.tag.namespace': ('magenta', 'default', 'bold'),
|
||||
'xml.tag.name': ('blue', 'default', 'bold'),
|
||||
'xml.tag.attrname': ('cyan', 'default', 'bold'),
|
||||
'xml.tag.end': ('default', 'default', 'bold'),
|
||||
'xml.entity': ('magenta', 'default', 'bold'),
|
||||
'xml.cdata.start': ('magenta', 'default', 'bold'),
|
||||
'xml.cdata.data': ('green', 'default', 'bold'),
|
||||
'xml.cdata.end': ('magenta', 'default', 'bold'),
|
||||
}
|
||||
actions = [XmlValidate, XmlCreateTag, XmlCreateComment, XmlCreateCdata]
|
||||
_bindings = {
|
||||
|
|
|
@ -65,10 +65,10 @@ class Window(object):
|
|||
elif regex.auto_mode_vi.search(firstline):
|
||||
mode_name = regex.auto_mode_vi.search(firstline).group(1)
|
||||
else:
|
||||
line = b.lines[0]
|
||||
for word in a.mode_detection:
|
||||
if word in line:
|
||||
mode_name = a.mode_detection[word]
|
||||
for (r, name) in a.mode_detection.items():
|
||||
if r.match(b.lines[0]):
|
||||
mode_name = name
|
||||
break
|
||||
|
||||
cls = a.modes.get(mode_name, a.modes['fundamental'])
|
||||
self.set_mode(cls(self))
|
||||
|
|
Loading…
Reference in New Issue