mode fixups/speed ups

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-10-08 03:39:22 +00:00
parent 45100bd4a6
commit 993d6f8269
9 changed files with 86 additions and 85 deletions

View File

@ -1,6 +1,5 @@
import color, mode
from lex import Grammar, PatternRule, RegionRule
#from mode.perl import StringGrammar
class StringGrammar(Grammar):
rules = [
@ -8,6 +7,7 @@ class StringGrammar(Grammar):
PatternRule(r'cheetah_placeholder', r'\$[a-zA-Z0-9_.\[\]]+'),
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
PatternRule(r'data', r'[^\$\\]+'),
]

View File

@ -2,24 +2,36 @@ import color, mode
from lex import Grammar, PatternRule, NocasePatternRule, RegionRule, NocaseRegionRule
from point import Point
class StringGrammar(Grammar):
class StringGrammar1(Grammar):
rules = [
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
PatternRule(r'data', r"[^']+"),
]
class StringGrammar2(Grammar):
rules = [
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
PatternRule(r'data', r'[^"]+'),
]
class CommentGrammar1(Grammar):
rules = [PatternRule(r'data', r'(?:[^*]|\*(?!/))+')]
class CommentGrammar2(Grammar):
rules = [PatternRule(r'data', r'(?:[^-]|-(?!-)|--(?!>))+')]
class KeywordGrammar(Grammar):
rules = [
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
RegionRule(r'string', "'", StringGrammar, r"'"),
RegionRule(r'string', '"', StringGrammar, r'"'),
RegionRule(r'string', "'", StringGrammar1, r"'"),
RegionRule(r'string', '"', StringGrammar2, r'"'),
]
class CSSGrammar(Grammar):
rules = [
RegionRule(r'comment', '/\*', Grammar, '\*/'),
RegionRule(r'comment', '<!--', Grammar, '-->'),
RegionRule(r'comment', '/\*', CommentGrammar1, '\*/'),
RegionRule(r'comment', '<!--', CommentGrammar2, '-->'),
NocasePatternRule(r'css_dimension', r'[+-]?(?:[0-9]+|[0-9]*\.[0-9]+)[-a-z_][-a-z0-9_]*'),
NocasePatternRule(r'css_percentage', r'[+-]?(?:[0-9]+|[0-9]*\.[0-9]+)%%'),
NocasePatternRule(r'css_length', r'[+-]?(?:[0-9]+|[0-9]*\.[0-9]+)(?:em|ex|px|in|cm|mm|pt|pc)'),
@ -33,12 +45,11 @@ class CSSGrammar(Grammar):
NocaseRegionRule(r'css_keyword', '(?:(?<=url)|(?<=rgb)|(?<=counter))\(', KeywordGrammar, '\)'),
NocasePatternRule(r'css_label', r"\.?[-a-zA-Z0-9_]+(?= *{)"),
NocasePatternRule(r'css_ident', r"-?[a-z_][-a-z0-9_]*"),
NocasePatternRule(r'css_name', r"[-a-z0-9_]+"),
NocasePatternRule(r'delimiter', r'[:;,{}()\[\]]|~=|\|=|='),
RegionRule(r'string', "'", StringGrammar, r"'"),
RegionRule(r'string', '"', StringGrammar, r'"'),
RegionRule(r'string', "'", StringGrammar1, r"'"),
RegionRule(r'string', '"', StringGrammar2, r'"'),
]
class CSS(mode.Fundamental):
@ -50,13 +61,12 @@ class CSS(mode.Fundamental):
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
'css_dimension': ('magenta', 'default', 'bold'),
'css_percentage': ('magenta', 'default', 'bold'),
'css_length': ('magenta', 'default', 'bold'),
'css_real': ('magenta', 'default', 'bold'),
'css_int': ('magenta', 'default', 'bold'),
'css_color': ('magenta', 'default', 'bold'),
'css_dimension': ('magenta', 'default', 'bold'),
'css_percentage': ('magenta', 'default', 'bold'),
'css_length': ('magenta', 'default', 'bold'),
'css_real': ('magenta', 'default', 'bold'),
'css_int': ('magenta', 'default', 'bold'),
'css_color': ('magenta', 'default', 'bold'),
'css_hash': ('cyan', 'default', 'bold'),
'css_rule': ('cyan', 'default', 'bold'),
'css_label': ('cyan', 'default', 'bold'),

View File

@ -8,6 +8,7 @@ class StringGrammar(Grammar):
rules = [
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
PatternRule(r'escaped', r'[^\\]+'),
]
class ELispGrammar(Grammar):
@ -27,9 +28,6 @@ class ELispGrammar(Grammar):
PatternRule(r'eol', r'\n$'),
]
#class ELispTabber(tab.StackTabber):
# pass
class ELisp(mode.Fundamental):
modename = 'ELisp'
tabwidth = 2

View File

@ -6,6 +6,7 @@ from lex import Grammar, PatternRule, RegionRule, OverridePatternRule, NocasePat
class StringGrammar(Grammar):
rules = [
NocasePatternRule(r'escaped', r'\\(?:[bdefnrstv\\"\']|\^[a-z]|\d{1,3})'),
NocasePatternRule(r'data', r'[^\\]+'),
]
class ErlangGrammar(Grammar):
@ -36,30 +37,6 @@ class ErlangTabber(tab.StackTabber):
token = self.get_token(y, i)
rtoken = self.get_next_right_token(y, i)
ltoken = self.get_next_left_token(y, i)
# if token.name == 'eol':
# pass
# if ltoken is not None and ltoken.name == 'comment':
# ltoken = self.get_next_left_token(y, i - 1)
#
# if ltoken is None:
# pass
# elif ltoken.name == 'erl_reserved' and ltoken.string in self.enterlvl:
# pass
# elif ltoken.name == 'delimiter':
# if ltoken.string == ';':
# #self._opt_pop('->')
# pass
# if ltoken.string == '.':
# #self._opt_pop('->')
# pass
# else:
# pass
# else:
# pass
# #self._pop_while('->')
# #self._pop_while('->')
# #if not self._empty() and self._peek_name() != '->':
# # self._pop()
if token.name == 'eol':
pass
@ -108,7 +85,7 @@ class Erlang(mode.Fundamental):
'erl_reserved': ('cyan', 'default', 'bold'),
'erl_arity': ('magenta', 'default', 'bold'),
'erl_namespace': ('magenta', 'default', 'bold'),
'erl_function': ('blue', 'default', 'bold'),
'erl_function': ('blue', 'default', 'bold'),
'erl_builtin': ('magenta', 'default', 'bold'),
'erl_variable': ('yellow', 'default', 'bold'),
'erl_operator': ('default', 'default', 'bold'),

View File

@ -11,22 +11,21 @@ class FstabGrammar(Grammar):
r'fstab_options', r' *(?:[^# \n\t]+|\\.)+',
r'fstab_dump', r' *(?:[^# \n\t]+|\\.)+',
r'fstab_pass', r' *(?:[^# \n\t]+|\\.)+',
r'fstab_error', r'[^\n]*',
r'fstab_eol', r'\n')
r'fstab_error', r'[^\n]*', r'fstab_eol', r'\n'),
]
class Fstab(mode.Fundamental):
modename = 'fstab'
basenames = ['fstab']
grammar = FstabGrammar
colors = {
'fstab_device': ('magenta', 'default', 'bold'),
'fstab_point': ('cyan', 'default', 'bold'),
'fstab_type': ('green', 'default', 'bold'),
modename = 'fstab'
basenames = ['fstab']
grammar = FstabGrammar
colors = {
'fstab_device': ('magenta', 'default', 'bold'),
'fstab_point': ('cyan', 'default', 'bold'),
'fstab_type': ('green', 'default', 'bold'),
'fstab_options': ('cyan', 'default', 'bold'),
'fstab_dump': ('green', 'default', 'bold'),
'fstab_pass': ('green', 'default', 'bold'),
'fstab_error': ('default', 'red', 'bold'),
'fstab_dump': ('green', 'default', 'bold'),
'fstab_pass': ('green', 'default', 'bold'),
'fstab_error': ('default', 'red', 'bold'),
}
install = Fstab.install

View File

@ -3,18 +3,17 @@ import color, completer, default, mode, method, regex, tab
from point import Point
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule, NocasePatternRule
#class CommentGrammar(Grammar):
# rules = [
# RegionRule(r'comment', r'{-', None, r'-}'),
# ]
class CommentGrammar(Grammar):
pass
CommentGrammar.rules.append(RegionRule(r'comment', r'{-', None, r'-}'))
rules = [
RegionRule(r'comment', r'{-', None, r'-}'),
PatternRule(r'data', r'(?:[^{]|{(?!-))+'),
]
class StringGrammar(Grammar):
rules = [
RegionRule(r'gap', r'\\ *\n$', Grammar, r'^ *[^ \n]'),
NocasePatternRule(r'escaped', r'\\(?:NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|[&abfnrtv\\"\']|\^[a-z]|\d{1,3}|o[0-7]{0,3}|x(?:[0-9a-f]){0,2})'),
PatternRule(r'data', r'[^\\]+'),
]
class HaskellGrammar(Grammar):
@ -26,7 +25,6 @@ class HaskellGrammar(Grammar):
PatternRule(r'hs_declaration', r"^[a-z_][a-zA-Z0-9_']*"),
PatternRule(r'hs_variable', r"[a-z_][a-zA-Z0-9_']*"),
PatternRule(r'hs_constructor', r"[A-Z][a-zA-Z0-9_']*"),
#PatternRule(r'hs_operator', r'(?:=>|=|::|\||->|==|=)'),
PatternRule(r'hs_operator', r'@|!|>@>|>>=|>>|=>|::|->|;|<-|\\\\|\.\.|!!|:|\+\+|\||\.|\\|>=|>|/=|==|<=|<|\|\||&&|\^\^|\*\*|\^|/|\*|-|\+|='),
]

View File

@ -5,13 +5,16 @@ from mode.xml import TagGrammar
from mode.javascript import JavascriptGrammar
from mode.css import CSSGrammar
class CommentGrammar(Grammar):
rules = [PatternRule(r'data', r'(?:[^-]|-(?!-)|--(?!>))+')]
class HTMLGrammar(Grammar):
rules = [
# TODO: how does cdata work again?
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
# BUG: not all scripts are javascript and not all styles are CSS
# but, dynamically choosing a grammar based on the 'type' attribute
# (which may be on a different line) is impractical.
RegionRule(r'comment', r'<!--', CommentGrammar, r'-->'),
# BUG: not all scripts are javascript and not all styles are CSS but
# dynamically choosing a grammar based on the 'type' attribute (which
# may be on a different line) is impractical.
RegionRule(r'script', r'<(?=script[^a-zA-Z0-9_])', TagGrammar, r'>', JavascriptGrammar, r'</(?=script>)', TagGrammar, r'>'),
RegionRule(r'style', r'<(?=style[^a-zA-Z0-9_])', TagGrammar, r'>', CSSGrammar, r'</(?=style>)', TagGrammar, r'>'),
RegionRule(r'tag', r'</?', TagGrammar, r'/?>'),
@ -37,8 +40,7 @@ class HtmlViewPage(method.Method):
class HtmlValidatePage(method.Method):
'''View the HTML data in a browser (curses or external)'''
args = [method.arg('url', dv=default.build_mode_var('url'), ld=True,
h='')]
args = [method.arg('url', dv=default.build_mode_var('url'), ld=True, h='')]
base = 'http://validator.w3.org/check?'
def _execute(self, w, **vargs):
w.mode.url = vargs['url']

View File

@ -3,15 +3,20 @@ from lex import Grammar, PatternRule, RegionRule
from mode.python import StringGrammar2
from mode.c import CTabber2
class CommentGrammar(Grammar):
rules = [
PatternRule(r"javadoc", r"@[a-z]+"),
PatternRule(r"data", r"(?:[^@*]|\*(?!/))+"),
]
class JavaGrammar(Grammar):
rules = [
PatternRule(r"spaces", r" +"),
PatternRule(r'import', r'(?<=import ) *[a-zA-Z0-9_.*]+'),
PatternRule(r'package', r'(?<=package ) *[a-zA-Z0-9_.*]+'),
RegionRule(r'doccomment', '/\*\*', Grammar, '\*/'),
RegionRule(r'comment', '/\*', Grammar, '\*/'),
PatternRule(r'comment', r'//.*$'),
RegionRule(r'java_comment', '/\*', CommentGrammar, '\*/'),
PatternRule(r'java_comment', r'//.*$'),
PatternRule(r'keyword', r"(?:abstract|assert|boolean|break|byte|case|catch|char|class|continue|default|double|do|else|extends|finally|final|float|for|if|implements|import|instanceof|interface|int|long|native|new|package|private|protected|public|return|short|static|switch|super|synchronized|threadsafe|throws|throw|transient|try|void|while)(?![a-zA-Z_])"),
PatternRule(r'java_label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
@ -145,7 +150,7 @@ class JavaTabber(CTabber2):
if self._has_markers() and self._peek_name() == 'cond':
pass
elif(not fqname.startswith('string') and
not fqname.startswith('comment') and
not fqname.startswith('java-comment') and
not fqname.startswith('macro') and
not fqname == 'delimiter' and
not fqname == 'header' and
@ -165,15 +170,17 @@ class Java(mode.Fundamental):
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
'doccomment.start': ('red', 'default', 'bold'),
'doccomment.end': ('red', 'default', 'bold'),
'doccomment.null': ('red', 'default', 'bold'),
'import': ('blue', 'default', 'bold'),
'java_label': ('magenta', 'default', 'bold'),
'java_builtin': ('magenta', 'default', 'bold'),
'java_char': ('green', 'default', 'bold'),
'java_integer': ('green', 'default', 'bold'),
'java_float': ('green', 'default', 'bold'),
'java_comment.start': ('red', 'default', 'bold'),
'java_comment.end': ('red', 'default', 'bold'),
'java_comment.javadoc': ('magenta', 'default', 'bold'),
'java_comment.data': ('red', 'default', 'bold'),
'java_comment.null': ('red', 'default', 'bold'),
'import': ('blue', 'default', 'bold'),
'java_label': ('magenta', 'default', 'bold'),
'java_builtin': ('magenta', 'default', 'bold'),
'java_char': ('green', 'default', 'bold'),
'java_integer': ('green', 'default', 'bold'),
'java_float': ('green', 'default', 'bold'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)

View File

@ -3,16 +3,24 @@ import color, method, mode
from lex import Grammar, PatternRule, RegionRule
from mode.text import TextInsertSpace
class ArgumentGrammar(Grammar):
rules = [PatternRule(r'data', r'[^}]+')]
class StringGrammar1(Grammar):
rules = [PatternRule(r'data', r"[^']+")]
class StringGrammar2(Grammar):
rules = [PatternRule(r'data', r"(?:[^']|'(?!'))+")]
class LatexGrammar(Grammar):
rules = [
PatternRule(r'comment', r'\%.*$'),
PatternRule(r'latex_wrapper', r'\\(?:begin|end)'),
PatternRule(r'latex_control', r'\\[a-zA-Z]+'),
RegionRule(r'latex_argument', r'{', None, r'}'),
RegionRule(r'latex_string', r"``", None, r"''"),
RegionRule(r'latex_string', r"`", None, r"'"),
RegionRule(r'latex_argument', r'{', ArgumentGrammar, r'}'),
RegionRule(r'latex_string', r"``", StringGrammar2, r"''"),
RegionRule(r'latex_string', r"`", StringGrammar1, r"'"),
PatternRule(r'latex_escaped', r'\\.'),
PatternRule(r'latex_special', r'[{}$^_%~#&]'),
PatternRule(r'data', r'[^{}$^_%~#&%\\`]+'),
]
class LatexBuild(method.Method):
@ -113,8 +121,10 @@ class Latex(mode.Fundamental):
'latex_wrapper': ('magenta', 'default', 'bold'),
'latex_control': ('blue', 'default', 'bold'),
'latex_argument.null': ('cyan', 'default', 'bold'),
'latex_argument.data': ('cyan', 'default', 'bold'),
'latex_string.start': ('green', 'default', 'bold'),
'latex_string.null': ('green', 'default', 'bold'),
'latex_string.data': ('green', 'default', 'bold'),
'latex_string.end': ('green', 'default', 'bold'),
'latex_escaped': ('magenta', 'default', 'bold'),
}