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