From bc65acb16d23da68ac66c8c4172a967c02338dad Mon Sep 17 00:00:00 2001 From: moculus Date: Sun, 16 Mar 2008 05:23:14 +0000 Subject: [PATCH] lexing improvements --HG-- branch : pmacs2 --- application.py | 2 + code_examples/Reporting2.pm | 5 ++- code_examples/python-overrides.py | 12 ++++++ lex.py | 20 +++++----- method/__init__.py | 2 +- mode/__init__.py | 14 +++++-- mode/cheetah.py | 26 ++++++------ mode/console.py | 14 +++---- mode/css.py | 40 +++++++++---------- mode/elisp.py | 24 +++++------ mode/html.py | 8 ++-- mode/java.py | 42 ++++++++++---------- mode/javascript.py | 52 ++++++++++++------------ mode/lisp.py | 12 +++--- mode/make.py | 26 ++++++------ mode/mutt.py | 4 +- mode/nasm.py | 16 ++++---- mode/ocaml.py | 32 +++++++-------- mode/perl.py | 56 +++++++++++++------------- mode/python.py | 44 ++++++++++----------- mode/rst.py | 4 +- mode/scheme.py | 33 ++++++++-------- mode/sh.py | 38 +++++++++--------- mode/sql.py | 66 ++++++++++++++++--------------- mode/text.py | 12 +++--- mode/text2.py | 20 +++++----- mode/tt.py | 24 +++++------ mode/xml.py | 24 +++++------ 28 files changed, 347 insertions(+), 325 deletions(-) create mode 100644 code_examples/python-overrides.py diff --git a/application.py b/application.py index 4e71ae9..58c33f5 100755 --- a/application.py +++ b/application.py @@ -48,6 +48,8 @@ class Application(object): self.error_string = "" self.error_timestamp = None self.input = keyinput.Handler() + self.token_colors = {} + self.default_color = ('default', 'default',) # initialize our colors if curses.has_colors(): diff --git a/code_examples/Reporting2.pm b/code_examples/Reporting2.pm index 15da053..b44a66d 100644 --- a/code_examples/Reporting2.pm +++ b/code_examples/Reporting2.pm @@ -10,6 +10,7 @@ sub foo { #@@:heredoc:mode.sql.Sql my $s = <'), + RegionRule(r'cheetah_tag', r''), ] class Template(mode.Fundamental): @@ -26,22 +26,22 @@ class Template(mode.Fundamental): extensions = ['.tmpl'] grammar = TemplateGrammar colors = { - 'comment': ('red', 'default'), - 'comment.start': ('red', 'default'), - 'comment.null': ('red', 'default'), - 'comment.end': ('red', 'default'), + #'comment': ('red', 'default'), + #'comment.start': ('red', 'default'), + #'comment.null': ('red', 'default'), + #'comment.end': ('red', 'default'), 'directive': ('magenta', 'default'), 'placeholder': ('magenta', 'default'), - 'tag.start': ('default', 'default'), - 'tag.namespace': ('magenta', 'default'), - 'tag.name': ('blue', 'default'), - 'tag.attrname': ('cyan', 'default'), - 'tag.string.start': ('green', 'default'), - 'tag.string.null': ('green', 'default'), - 'tag.string.end': ('green', 'default'), - 'tag.end': ('default', 'default'), + 'cheetah_tag.start': ('default', 'default'), + 'cheetah_tag.namespace': ('magenta', 'default'), + 'cheetah_tag.name': ('blue', 'default'), + 'cheetah_tag.attrname': ('cyan', 'default'), + 'cheetah_tag.string.start': ('green', 'default'), + 'cheetah_tag.string.null': ('green', 'default'), + 'cheetah_tag.string.end': ('green', 'default'), + 'cheetah_tag.end': ('default', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/console.py b/mode/console.py index a8f6a6d..4b6660c 100644 --- a/mode/console.py +++ b/mode/console.py @@ -9,8 +9,8 @@ class ConsoleGrammar(Grammar): PatternRule(r'input', r'^-->.*$'), #PatternRule(r'output', r'^ .*$'), - RegionRule(r'string', r'"', StringGrammar, r'"'), - RegionRule(r'string', r"'", StringGrammar, r"'"), + RegionRule(r'py_string', r'"', StringGrammar, r'"'), + RegionRule(r'py_string', r"'", StringGrammar, r"'"), PatternRule(r'bareword', r'[a-zA-Z_][a-zA-Z0-9_]*'), ] class Console(mode.Fundamental): @@ -21,11 +21,11 @@ class Console(mode.Fundamental): 'input': ('cyan', 'default'), 'output': ('default', 'default'), - 'string.start': ('green', 'default'), - 'string.octal': ('magenta', 'default'), - 'string.escaped': ('magenta', 'default'), - 'string.null': ('green', 'default'), - 'string.end': ('green', 'default'), + 'py_string.start': ('green', 'default'), + 'py_string.octal': ('magenta', 'default'), + 'py_string.escaped': ('magenta', 'default'), + 'py_string.null': ('green', 'default'), + 'py_string.end': ('green', 'default'), } install = Console.install diff --git a/mode/css.py b/mode/css.py index 54dedc0..dc8cb58 100644 --- a/mode/css.py +++ b/mode/css.py @@ -29,10 +29,10 @@ class CSSGrammar(Grammar): NocasePatternRule(r'rule', r'@(?:page|media|import)'), NocasePatternRule(r'color', r'(?:aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|#[0-9]{6}|#[0-9]{3})'), - NocasePatternRule(r'keyword', r'(?:url|rgb|counter)'), - NocaseRegionRule(r'keyword', '(?:(?<=url)|(?<=rgb)|(?<=counter))\(', KeywordGrammar, '\)'), + NocasePatternRule(r'css_keyword', r'(?:url|rgb|counter)'), + NocaseRegionRule(r'css_keyword', '(?:(?<=url)|(?<=rgb)|(?<=counter))\(', KeywordGrammar, '\)'), - NocasePatternRule(r'label', r"\.?[-a-zA-Z0-9_]+(?= *{)"), + NocasePatternRule(r'css_label', r"\.?[-a-zA-Z0-9_]+(?= *{)"), NocasePatternRule(r'ident', r"-?[a-z_][-a-z0-9_]*"), NocasePatternRule(r'name', r"[-a-z0-9_]+"), @@ -50,10 +50,10 @@ class CSS(mode.Fundamental): closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} colors = { - 'comment': ('red', 'default'), - 'comment.start': ('red', 'default'), - 'comment.null': ('red', 'default'), - 'comment.end': ('red', 'default'), + #'comment': ('red', 'default'), + #'comment.start': ('red', 'default'), + #'comment.null': ('red', 'default'), + #'comment.end': ('red', 'default'), 'htmlcomment': ('red', 'default'), 'htmlcomment.start': ('red', 'default'), @@ -68,27 +68,27 @@ class CSS(mode.Fundamental): 'color': ('magenta', 'default'), 'hash': ('cyan', 'default'), - 'label': ('cyan', 'default'), + 'css_label': ('cyan', 'default'), 'rule': ('cyan', 'default'), - 'keyword': ('cyan', 'default'), + 'css_keyword': ('cyan', 'default'), 'ident': ('default', 'default'), 'name': ('default', 'default'), 'delimiter': ('default', 'default'), - 'keyword': ('cyan', 'default'), - 'keyword.start': ('default', 'default'), - 'keyword.null': ('cyan', 'default'), - 'keyword.octal': ('magenta', 'default'), - 'keyword.escaped': ('magenta', 'default'), - 'keyword.end': ('default', 'default'), + 'css_keyword': ('cyan', 'default'), + 'css_keyword.start': ('default', 'default'), + 'css_keyword.null': ('cyan', 'default'), + 'css_keyword.octal': ('magenta', 'default'), + 'css_keyword.escaped': ('magenta', 'default'), + 'css_keyword.end': ('default', 'default'), - 'string.start': ('green', 'default'), - 'string.null': ('green', 'default'), - 'string.octal': ('magenta', 'default'), - 'string.escaped': ('magenta', 'default'), - 'string.end': ('green', 'default'), + #'string.start': ('green', 'default'), + #'string.null': ('green', 'default'), + #'string.octal': ('magenta', 'default'), + #'string.escaped': ('magenta', 'default'), + #'string.end': ('green', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/elisp.py b/mode/elisp.py index be0b013..31d6392 100644 --- a/mode/elisp.py +++ b/mode/elisp.py @@ -13,7 +13,7 @@ class ELispGrammar(Grammar): rules = [ PatternRule(r'comment', r';.*$'), PatternRule(r'reserved', r'(?:nil)(?![a-zA-Z0-9_])'), - PatternRule(r'keyword', r'(?:while|when|unless|setq|require|or|not|mapcar|list|let|lambda|if|exists|equal|defvar|defun|defalias|count|cons|cdr|car|apply|and)(?![a-zA-Z0-9_])'), + PatternRule(r'elisp_keyword', r'(?:while|when|unless|setq|require|or|not|mapcar|list|let|lambda|if|exists|equal|defvar|defun|defalias|count|cons|cdr|car|apply|and)(?![a-zA-Z0-9_])'), PatternRule(r'symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"), PatternRule(r'type', r":[a-zA-Z_][a-zA-Z0-9-_]*"), PatternRule(r'attribute', r"&[a-zA-Z_][a-zA-Z0-9-_]*"), @@ -39,20 +39,20 @@ class ELisp(mode.Fundamental): closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} colors = { - 'keyword': ('cyan', 'default'), + 'elisp_keyword': ('cyan', 'default'), 'reserved': ('blue', 'default'), 'symbol': ('magenta', 'default'), 'type': ('blue', 'default'), - 'string.start': ('green', 'default'), - 'string.null': ('green', 'default'), - 'string.octal': ('magenta', 'default'), - 'string.escaped': ('magenta', 'default'), - 'string.format': ('yellow', 'default'), - 'string.end': ('green', 'default'), - 'integer': ('default', 'default'), - 'float': ('default', 'default'), - 'imaginary': ('default', 'default'), - 'comment': ('red', 'default'), + #'string.start': ('green', 'default'), + #'string.null': ('green', 'default'), + #'string.octal': ('magenta', 'default'), + #'string.escaped': ('magenta', 'default'), + #'string.format': ('yellow', 'default'), + #'string.end': ('green', 'default'), + #'integer': ('default', 'default'), + #'float': ('default', 'default'), + #'imaginary': ('default', 'default'), + #'comment': ('red', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/html.py b/mode/html.py index c9c8e10..983da6a 100644 --- a/mode/html.py +++ b/mode/html.py @@ -19,9 +19,9 @@ class HTML(mode.Fundamental): extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml'] grammar = HTMLGrammar colors = { - 'comment.start': ('red', 'default'), - 'comment.null': ('red', 'default'), - 'comment.end': ('red', 'default'), + #'comment.start': ('red', 'default'), + #'comment.null': ('red', 'default'), + #'comment.end': ('red', 'default'), 'script.start': ('default', 'default'), 'script.namespace': ('magenta', 'default'), @@ -41,7 +41,7 @@ class HTML(mode.Fundamental): 'tag.string.end': ('green', 'default'), 'tag.end': ('default', 'default'), } - colors.update(Javascript.colors) + #colors.update(Javascript.colors) def __init__(self, w): mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) diff --git a/mode/java.py b/mode/java.py index 153ea2f..ece8be2 100644 --- a/mode/java.py +++ b/mode/java.py @@ -13,19 +13,19 @@ class JavaGrammar(Grammar): PatternRule(r'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'label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'), + PatternRule(r'java_label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'), - PatternRule(r'builtin', r"(?:null|true|false|this)"), + PatternRule(r'java_builtin', r"(?:null|true|false|this)"), PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"), PatternRule(r"unop", r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="), PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"), PatternRule(r"delimiter", r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"), - PatternRule(r"integer", r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"), - PatternRule(r"float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"), + PatternRule(r"java_integer", r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"), + PatternRule(r"java_float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"), RegionRule(r'string', '"', StringGrammar, '"'), - PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'"), + PatternRule(r'java_char', r"'.'|'\\.'|'\\[0-7]{3}'"), PatternRule(r"eol", r"\n$"), ] @@ -163,29 +163,29 @@ class Java(mode.Fundamental): closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} colors = { - 'comment': ('red', 'default'), - 'comment.start': ('red', 'default'), - 'comment.end': ('red', 'default'), - 'comment.null': ('red', 'default'), + #'comment': ('red', 'default'), + #'comment.start': ('red', 'default'), + #'comment.end': ('red', 'default'), + #'comment.null': ('red', 'default'), 'doccomment.start': ('red', 'default'), 'doccomment.end': ('red', 'default'), 'doccomment.null': ('red', 'default'), 'import': ('blue', 'default'), - 'label': ('magenta', 'default'), - 'keyword': ('cyan', 'default'), - 'function': ('blue', 'default'), - 'builtin': ('magenta', 'default'), + 'java_label': ('magenta', 'default'), + #'keyword': ('cyan', 'default'), + #'function': ('blue', 'default'), + 'java_builtin': ('magenta', 'default'), - 'char': ('green', 'default'), - 'string.start': ('green', 'default'), - 'string.octal': ('green', 'default'), - 'string.escaped': ('green', 'default'), - 'string.null': ('green', 'default'), - 'string.end': ('green', 'default'), - 'integer': ('green', 'default'), - 'float': ('green', 'default'), + 'java_char': ('green', 'default'), + #'string.start': ('green', 'default'), + #'string.octal': ('green', 'default'), + #'string.escaped': ('green', 'default'), + #'string.null': ('green', 'default'), + #'string.end': ('green', 'default'), + 'java_integer': ('green', 'default'), + 'java_float': ('green', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/javascript.py b/mode/javascript.py index 4a9600a..3c857fe 100644 --- a/mode/javascript.py +++ b/mode/javascript.py @@ -8,12 +8,12 @@ class JavascriptGrammar(Grammar): PatternRule(r'comment', r'//.*$'), RegionRule(r'comment', '/\*', Grammar, '\*/'), PatternRule(r'continuation', r'\\(?= *$)'), - PatternRule(r'function', r"(?<=function )[a-zA-Z_][a-zA-Z0-9_]*"), + PatternRule(r'js_function', r"(?<=function )[a-zA-Z_][a-zA-Z0-9_]*"), PatternRule(r'class', r"(?<=class )[a-zA-Z_][a-zA-Z0-9_]*"), - PatternRule(r'reserved', r'(?:as|break|case|catch|class|const|continue|default|delete|do|else|export|extends|false|finally|for|function|if|import|in|instanceof|is|namespace|new|null|package|private|public|return|super|switch|this|throw|true|try|typeof|use|var|void|while|with)(?![a-zA-Z0-9_])'), - PatternRule(r'reserved', r'(?:abstract|debugger|enum|goto|implements|interface|native|protected|synchronized|throws|transient|volatile)(?![a-zA-Z0-9_])'), - PatternRule(r'nonreserved', r'(?:get|include|set)(?![a-zA-Z0-9_])'), + PatternRule(r'js_reserved', r'(?:as|break|case|catch|class|const|continue|default|delete|do|else|export|extends|false|finally|for|function|if|import|in|instanceof|is|namespace|new|null|package|private|public|return|super|switch|this|throw|true|try|typeof|use|var|void|while|with)(?![a-zA-Z0-9_])'), + PatternRule(r'js_reserved', r'(?:abstract|debugger|enum|goto|implements|interface|native|protected|synchronized|throws|transient|volatile)(?![a-zA-Z0-9_])'), + PatternRule(r'js_nonreserved', r'(?:get|include|set)(?![a-zA-Z0-9_])'), PatternRule(r"method", r"(?<=\.)[a-zA-Z_][a-zA-Z0-9_]*(?= *\()"), PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"), @@ -29,7 +29,7 @@ class JavascriptGrammar(Grammar): PatternRule(r'delimiter', r'%=|&&=|&=|\(|\)|\*=|\+=|,|-=|\.{3}|\.|/=(?= |$)|::|:|;|<<=|>>=|>>>=|\?|\[|\]|^=|^^=|\{|\}|\|=|\|\|='), PatternRule(r'operator', r'!==|!=|!|%|&&|&|\*|\+\+|\+|--|-|/(?= |$)|<<=|<<|<=|<|===|==|=|>>>=|>>>|>>=|>>|>=|>|\\'), - RegionRule('regex', "/", StringGrammar, "/"), + RegionRule('js_regex', "/", StringGrammar, "/"), RegionRule('string', "'", StringGrammar, "'"), RegionRule('string', '"', StringGrammar, '"'), ] @@ -62,33 +62,33 @@ class Javascript(mode.Fundamental): closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} colors = { - 'comment': ('red', 'default'), - 'comment.start': ('red', 'default'), - 'comment.null': ('red', 'default'), - 'comment.end': ('red', 'default'), + #'comment': ('red', 'default'), + #'comment.start': ('red', 'default'), + #'comment.null': ('red', 'default'), + #'comment.end': ('red', 'default'), 'continuation': ('red', 'default'), - 'function': ('blue', 'default'), + 'js_function': ('blue', 'default'), 'class': ('green', 'default'), - 'reserved': ('cyan', 'default'), - 'nonreserved': ('cyan', 'default'), + 'js_reserved': ('cyan', 'default'), + 'js_nonreserved': ('cyan', 'default'), - 'delimiter': ('default', 'default'), - 'operator': ('default', 'default'), - 'integer': ('default', 'default'), - 'float': ('default', 'default'), + #'delimiter': ('default', 'default'), + #'operator': ('default', 'default'), + #'integer': ('default', 'default'), + #'float': ('default', 'default'), - 'string.start': ('green', 'default'), - 'string.null': ('green', 'default'), - 'string.octal': ('magenta', 'default'), - 'string.escaped': ('magenta', 'default'), - 'string.end': ('green', 'default'), + #'string.start': ('green', 'default'), + #'string.null': ('green', 'default'), + #'string.octal': ('magenta', 'default'), + #'string.escaped': ('magenta', 'default'), + #'string.end': ('green', 'default'), - 'regex.start': ('cyan', 'default'), - 'regex.null': ('cyan', 'default'), - 'regex.octal': ('magenta', 'default'), - 'regex.escaped': ('magenta', 'default'), - 'regex.end': ('cyan', 'default'), + 'js_regex.start': ('cyan', 'default'), + 'js_regex.null': ('cyan', 'default'), + 'js_regex.octal': ('magenta', 'default'), + 'js_regex.escaped': ('magenta', 'default'), + 'js_regex.end': ('cyan', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/lisp.py b/mode/lisp.py index daa8278..e38c572 100644 --- a/mode/lisp.py +++ b/mode/lisp.py @@ -40,12 +40,12 @@ class Lisp(mode.Fundamental): closetokens = ('delimiter',) closetags = {')': '('} colors = { - 'comment': ('red', 'default'), - 'string.start': ('green', 'default'), - 'string.null': ('green', 'default'), - 'string.octal': ('magenta', 'default'), - 'string.escaped': ('magenta', 'default'), - 'string.end': ('green', 'default'), + #'comment': ('red', 'default'), + #'string.start': ('green', 'default'), + #'string.null': ('green', 'default'), + #'string.octal': ('magenta', 'default'), + #'string.escaped': ('magenta', 'default'), + #'string.end': ('green', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/make.py b/mode/make.py index f348f64..461aa94 100644 --- a/mode/make.py +++ b/mode/make.py @@ -21,10 +21,10 @@ class MakeGrammar(Grammar): #RegionRule(r'targets', r'^[^:= ]+ *:', Grammar, r';|\n', ShGrammar, r'\n'), RegionRule(r'actions', r'^ ', ShGrammar, r'\n'), - PatternRule(r'variable', r'\$\([a-zA-Z0-9_]+\)'), - PatternRule(r'variable', r'\${[a-zA-Z0-9_]+}'), - RegionRule(r'string', r'"', StringGrammar, r'"'), - RegionRule(r'string', r"'", StringGrammar, r"'"), + PatternRule(r'make_variable', r'\$\([a-zA-Z0-9_]+\)'), + PatternRule(r'make_variable', r'\${[a-zA-Z0-9_]+}'), + RegionRule(r'make_string', r'"', StringGrammar, r'"'), + RegionRule(r'make_string', r"'", StringGrammar, r"'"), ] class Make(mode.Fundamental): @@ -33,22 +33,22 @@ class Make(mode.Fundamental): grammar = MakeGrammar savetabs = True colors = { - 'comment': ('red', 'default'), - 'continuation': ('red', 'default'), + #'comment': ('red', 'default'), + #'continuation': ('red', 'default'), 'targets.start': ('cyan', 'default'), 'assignment.start': ('yellow', 'default'), #'targets': ('cyan', 'default'), #'assignment': ('yellow', 'default'), - 'variable': ('yellow', 'default'), + 'make_variable': ('yellow', 'default'), - 'string.start': ('green', 'default'), - 'string.variable': ('yellow', 'default'), - 'string.escaped': ('magenta', 'default'), - 'string.null': ('green', 'default'), - 'string.end': ('green', 'default'), + 'make_string.start': ('green', 'default'), + 'make_string.variable': ('yellow', 'default'), + 'make_string.escaped': ('magenta', 'default'), + 'make_string.null': ('green', 'default'), + 'make_string.end': ('green', 'default'), } - colors.update(Sh.colors) + #colors.update(Sh.colors) install = Make.install diff --git a/mode/mutt.py b/mode/mutt.py index 6d36642..e19c76d 100644 --- a/mode/mutt.py +++ b/mode/mutt.py @@ -5,7 +5,7 @@ from lex import Grammar, PatternRule class MuttGrammar(Grammar): rules = [ - PatternRule(name=r'header', pattern=r'^(?:From|To|Cc|Bcc|Subject|Reply-To|In-Reply-To|Delivered-To|Date):'), + PatternRule(name=r'mutt_header', pattern=r'^(?:From|To|Cc|Bcc|Subject|Reply-To|In-Reply-To|Delivered-To|Date):'), PatternRule(name=r'quoteb', pattern=r'^ *(?:(?: *>){3})*(?: *>){2}.*$'), PatternRule(name=r'quotea', pattern=r'^ *(?:(?: *>){3})*(?: *>){1}.*$'), PatternRule(name=r'quotec', pattern=r'^ *(?:(?: *>){3})*(?: *>){3}.*$'), @@ -21,7 +21,7 @@ class Mutt(mode.Fundamental): modename = 'Mutt' grammar = MuttGrammar() colors = { - 'header': ('green', 'default', 'bold'), + 'mutt_header': ('green', 'default', 'bold'), 'email': ('cyan', 'default', 'bold'), 'url': ('cyan', 'default', 'bold'), 'quotea': ('yellow', 'default', 'bold'), diff --git a/mode/nasm.py b/mode/nasm.py index 6ea60eb..d978f59 100644 --- a/mode/nasm.py +++ b/mode/nasm.py @@ -9,12 +9,12 @@ class StringGrammar(Grammar): class NasmGrammar(Grammar): rules = [ - PatternRule(r'keyword', r"(?:section|global|extern)(?![a-zA-Z_])"), + PatternRule(r'nasm_keyword', r"(?:section|global|extern)(?![a-zA-Z_])"), PatternRule(r'macros', r"%(?:define|undef|assign|strlen|macro|endmacro|if|elif|else|endif|ifdef|ifndef|include|push|pop|stacksize)(?![a-zA-Z_])"), PatternRule(r'instructions', r"(?:jeq|jne|ja|jmp|push|pushad|pushfd|call|ret|sub|add|pop|popa|popad|popfd|call|and|cwd|cdq|cmp|cmpxchg|cpuid|div|divpd|enter|leave|fadd|fld|fmul|fsqrt|fsub|hlt|imul|inc|int|int3|lea|mov|movd|mul|neg|not|nop|or|sal|sar|shl|shr|shld|shrd|syscall|sysenter|sysexit|test|xchg|xadd|xor)(?![a-zA-Z_])"), PatternRule(r'registers', r"(?:eax|ax|ah|al|ebx|bx|bh|bl|ecx|cx|ch|cl|esi|edi|esp|ebp)(?![a-zA-Z_])"), PatternRule(r'prefix', r"(?:dword|word|lock)(?![a-zA-Z_])"), - PatternRule(r'label', r"[a-zA-Z_.][a-zA-Z0-9_.]*:"), + PatternRule(r'nasm_label', r"[a-zA-Z_.][a-zA-Z0-9_.]*:"), PatternRule(r"identifier", r"[a-zA-Z_][a-zA-Z0-9_]*"), PatternRule(r"integer", r"(0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"), PatternRule(r"float", r"[0-9]+\.[0-9]*|\.[0-9]+|([0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"), @@ -31,15 +31,15 @@ class Nasm(mode.Fundamental): extensions = ['.s'] grammar = NasmGrammar colors = { - 'keyword': ('cyan', 'default', 'bold'), + 'nasm_keyword': ('cyan', 'default', 'bold'), 'macros': ('blue', 'default', 'bold'), - 'string.start': ('green', 'default'), - 'string.null': ('green', 'default'), - 'string.end': ('green', 'default'), - 'comment': ('red', 'default'), + #'string.start': ('green', 'default'), + #'string.null': ('green', 'default'), + #'string.end': ('green', 'default'), + #'comment': ('red', 'default'), 'registers': ('yellow', 'default'), 'instructions': ('magenta', 'default'), - 'label': ('blue', 'default'), + 'nasm_label': ('blue', 'default'), } install = Nasm.install diff --git a/mode/ocaml.py b/mode/ocaml.py index d39a63d..7172059 100644 --- a/mode/ocaml.py +++ b/mode/ocaml.py @@ -25,7 +25,7 @@ class OcamlGrammar(Grammar): PatternRule(r'delimiter', r"[()]"), - PatternRule(r'keyword', r"(?:with|while|when|virtual|val|type|try|true|to|then|struct|sig|rec|private|parser|or|open|of|object|new|mutable|module|mod|method|match|lxor|lsr|lsl|lor|let|lazy|land|initializer|inherti|include|in|if|functor|function|fun|for|false|external|exception|end|else|downto|done|do|constraint|class|begin|asr|assert|as|and)(?!['a-zA-Z0-9_])"), + PatternRule(r'ocaml_keyword', r"(?:with|while|when|virtual|val|type|try|true|to|then|struct|sig|rec|private|parser|or|open|of|object|new|mutable|module|mod|method|match|lxor|lsr|lsl|lor|let|lazy|land|initializer|inherti|include|in|if|functor|function|fun|for|false|external|exception|end|else|downto|done|do|constraint|class|begin|asr|assert|as|and)(?!['a-zA-Z0-9_])"), PatternRule(r'builtin', r"(?:int|char|string|float|bool|false|true|unit|exn|array|list|option|int32|int64|nativeint|format4|lazy_t)(?!['a-zA-Z0-9_])"), PatternRule(r'builtin_exception', r"(?:Match_failure|Assert_failure|Invalid_argument|Failure|Not_found|Out_of_memory|Stack_overflow|Sys_error|End_of_file|Division_by_zero|Sys_blocked_io|Undefined_recursive_module|Exit)(?!['a-zA-Z0-9_])"), @@ -45,7 +45,7 @@ class OcamlGrammar(Grammar): PatternRule(r'char', r"'\\[0-9]{3}'"), PatternRule(r'char', r"'\\x[0-9A-Fa-f]{2}'"), - RegionRule(r'string', r'"', StringGrammar, '"'), + RegionRule(r'ocaml_string', r'"', StringGrammar, '"'), PatternRule(r'label', r"~[a-z_]['a-zA-Z0-9_]*:"), PatternRule(r'optlabel', r"\?[a-z_]['a-zA-Z0-9_]*:"), @@ -63,29 +63,29 @@ class Ocaml(mode.Fundamental): closetokens = ('delimiter',) closetags = {')': '('} colors = { - 'comment.start': ('red', 'default'), - 'comment.null': ('red', 'default'), - 'comment.end': ('red', 'default'), + #'comment.start': ('red', 'default'), + #'comment.null': ('red', 'default'), + #'comment.end': ('red', 'default'), 'linenum': ('red', 'default'), - 'keyword': ('cyan', 'default'), + 'ocaml_keyword': ('cyan', 'default'), #'builtin': ('magenta', 'default'), #'builtin_exception': ('magenta', 'default'), #'builtin_function': ('magenta', 'default'), - 'label': ('blue', 'default'), + 'ocaml_label': ('blue', 'default'), 'optlabel': ('blue', 'default'), - 'string.start': ('green', 'default'), - 'string.null': ('green', 'default'), - 'string.octal': ('magenta', 'default'), - 'string.hex': ('magenta', 'default'), - 'string.escaped': ('magenta', 'default'), - 'string.end': ('green', 'default'), - 'char': ('green', 'default'), - 'integer': ('default', 'default'), - 'float': ('default', 'default'), + 'ocaml_string.start': ('green', 'default'), + 'ocaml_string.null': ('green', 'default'), + 'ocaml_string.octal': ('magenta', 'default'), + 'ocaml_string.hex': ('magenta', 'default'), + 'ocaml_string.escaped': ('magenta', 'default'), + 'ocaml_string.end': ('green', 'default'), + #'char': ('green', 'default'), + #'integer': ('default', 'default'), + #'float': ('default', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/perl.py b/mode/perl.py index 31d7440..c0e66aa 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -59,21 +59,21 @@ class PerlGrammar(Grammar): PatternGroupRule(r'prototype', r'delimiter', r'\(', r'prototype', r'[\[\]\\@$%&*;]+', r'delimiter', '\)'), PatternRule(r'comment', r'#.*$'), - RegionRule(r'string', r'"', StringGrammar, r'"'), - RegionRule(r'string', r"'", Grammar, r"'"), + RegionRule(r'perl_string', r'"', StringGrammar, r'"'), + RegionRule(r'perl_string', r"'", Grammar, r"'"), RegionRule(r'evalstring', r"`", StringGrammar, r"`"), PatternRule(r'number', r'0?\.[0-9]+|[0-9]+(?:\.[0-9]+)?'), - PatternRule(r'keyword', r"(?)(?:STDIN|STDERR|STDOUT|continue|do|else|elsif|eval|foreach|for|if|last|my|next|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])"), + PatternRule(r'perl_keyword', r"(?)(?:STDIN|STDERR|STDOUT|continue|do|else|elsif|eval|foreach|for|if|last|my|next|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])"), PatternRule(r'hash_key', r'(?<={)[A-Za-z0-9_]+(?=})'), PatternRule(r'hash_key', r'[A-Za-z0-9_]+(?= *=>)'), PatternRule(r'length', r"\$#[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*"), PatternRule(r'cast', r'[\$\@\%\^\&](?= *{)'), PatternRule(r'scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?![A-Za-z0-9_])"), PatternRule(r'array', r"@_"), - PatternRule(r'function', r"\$\$*[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*(?=-> *\()"), + PatternRule(r'perl_function', r"\$\$*[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*(?=-> *\()"), PatternRule(r'scalar', r"\$\$*[A-Za-z0-9_](?:[A-Za-z0-9_]|::)*"), PatternRule(r'array', r"@\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"), - PatternRule(r'hash', r"%\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"), + PatternRule(r'perl_hash', r"%\$*[A-Za-z_](?:[A-Za-z0-9_]|::)*"), PatternRule(r'deref', r"[@%\$&\*](?={)"), # match regexes @@ -94,10 +94,10 @@ class PerlGrammar(Grammar): PatternRule(r'sub', r"(?<=sub )[a-zA-Z_][a-zA-Z_0-9]*"), PatternRule(r'use', r"(?<=use )(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*"), PatternRule(r'require', r"(?<=require )(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*"), - PatternRule(r'label', r'[a-zA-Z_][a-zA-Z0-9_]*:(?!:)'), + PatternRule(r'perl_label', r'[a-zA-Z_][a-zA-Z0-9_]*:(?!:)'), PatternRule(r'method', r"(?<=->)[a-zA-Z_][a-zA-Z_0-9]*"), - PatternRule(r'function', r"&\$*(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*"), - PatternRule(r'builtin', r"(?)&?(?:write|warn|wantarray|waitpid|wait|vec|values|utime|use|untie|unshift|unpack|unlink|undef|umask|ucfirst|uc|truncate|times|time|tied|tie|telldir|tell|syswrite|system|sysseek|sysread|sysopen|syscall|symlink|substr|sub|study|stat|srand|sqrt|sprintf|split|splice|sort|socketpair|socket|sleep|sin|shutdown|shmwrite|shmread|shmget|shmctl|shift|setsockopt|setservent|setpwent|setprotoent|setpriority|setpgrp|setnetent|sethostent|setgrent|send|semop|semget|semctl|select|seekdir|seek|scalar|rmdir|rindex|rewinddir|reverse|return|reset|require|rename|ref|redo|recv|readpipe|readlink|readline|readdir|read|rand|quotemeta|push|prototype|printf|print|pos|pop|pipe|package|pack|our|ord|opendir|open|oct|no|next|my|msgsnd|msgrcv|msgget|msgctl|mkdir|map|lstat|log|lock|localtime|local|listen|link|length|lcfirst|lc|last|kill|keys|join|ioctl|int|index|import|hex|grep|goto|gmtime|glob|getsockopt|getsockname|getservent|getservbyport|getservbyname|getpwuid|getpwnam|getpwent|getprotoent|getprotobynumber|getprotobyname|getpriority|getppid|getpgrp|getpeername|getnetent|getnetbyname|getnetbyaddr|getlogin|gethostent|gethostbyname|gethostbyaddr|getgrnam|getgrgid|getgrent|getc|formline|format|fork|flock|fileno|fcntl|exp|exit|exists|exec|eval|eof|endservent|endpwent|endprotoent|endnetent|endhostent|endgrent|each|dump|do|die|delete|defined|dbmopen|dbmclose|crypt|cos|continue|connect|closedir|close|chroot|chr|chown|chop|chomp|chmod|chdir|caller|bless|binmode|bind|atan2|alarm|accept|abs)(?![a-zA-Z0-9_])"), + PatternRule(r'perl_function', r"&\$*(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*"), + PatternRule(r'perl_builtin', r"(?)&?(?:write|warn|wantarray|waitpid|wait|vec|values|utime|use|untie|unshift|unpack|unlink|undef|umask|ucfirst|uc|truncate|times|time|tied|tie|telldir|tell|syswrite|system|sysseek|sysread|sysopen|syscall|symlink|substr|sub|study|stat|srand|sqrt|sprintf|split|splice|sort|socketpair|socket|sleep|sin|shutdown|shmwrite|shmread|shmget|shmctl|shift|setsockopt|setservent|setpwent|setprotoent|setpriority|setpgrp|setnetent|sethostent|setgrent|send|semop|semget|semctl|select|seekdir|seek|scalar|rmdir|rindex|rewinddir|reverse|return|reset|require|rename|ref|redo|recv|readpipe|readlink|readline|readdir|read|rand|quotemeta|push|prototype|printf|print|pos|pop|pipe|package|pack|our|ord|opendir|open|oct|no|next|my|msgsnd|msgrcv|msgget|msgctl|mkdir|map|lstat|log|lock|localtime|local|listen|link|length|lcfirst|lc|last|kill|keys|join|ioctl|int|index|import|hex|grep|goto|gmtime|glob|getsockopt|getsockname|getservent|getservbyport|getservbyname|getpwuid|getpwnam|getpwent|getprotoent|getprotobynumber|getprotobyname|getpriority|getppid|getpgrp|getpeername|getnetent|getnetbyname|getnetbyaddr|getlogin|gethostent|gethostbyname|gethostbyaddr|getgrnam|getgrgid|getgrent|getc|formline|format|fork|flock|fileno|fcntl|exp|exit|exists|exec|eval|eof|endservent|endpwent|endprotoent|endnetent|endhostent|endgrent|each|dump|do|die|delete|defined|dbmopen|dbmclose|crypt|cos|continue|connect|closedir|close|chroot|chr|chown|chop|chomp|chmod|chdir|caller|bless|binmode|bind|atan2|alarm|accept|abs)(?![a-zA-Z0-9_])"), # quote operator: qq(), qx() and qr() usually interpolate RegionRule(r'quoted', r'q[rqx] *(?P\()', QuotedGrammar1, r'\)'), @@ -116,8 +116,8 @@ class PerlGrammar(Grammar): RegionRule(r'quoted', r'qw?#', Grammar, r'#'), RegionRule(r'quoted', r'qw? *(?P[^ #])', Grammar, r'%(delim)s'), - PatternRule(r'function', r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?= *\()"), - PatternRule(r'class', r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?=->)"), + PatternRule(r'perl_function', r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?= *\()"), + PatternRule(r'perl_class', r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?=->)"), # some basic stuff PatternRule(r'delimiter', r"->|=>|(?|unquote-splicing|unquote|syntax-rules|set!|quote|quasiquote|or|map|loop|letrec-syntax|letrec|let-syntax|let\*|let|lambda|if|for-each|else|dynamic-wind|do|delay|define-syntax|define-macro|define|cond|case|call-with-output-file|call-with-input-file|call-with-current-continuation|begin|and)(?![^\n )])'), + PatternRule(r'scheme_keyword', r'(?:=>|unquote-splicing|unquote|syntax-rules|set!|quote|quasiquote|or|map|loop|letrec-syntax|letrec|let-syntax|let\*|let|lambda|if|for-each|else|dynamic-wind|do|delay|define-syntax|define-macro|define|cond|case|call-with-output-file|call-with-input-file|call-with-current-continuation|begin|and)(?![^\n )])'), - PatternRule(r'boolean', r'#[tf]'), - PatternRule(r'char', r'#\\space|#\\newline|#\\.'), - PatternRule(r'number', '[+-]?[0-9][^ ()\n]+'), - PatternRule(r'number', '#[bodx][ie]?[^ ()\n]+'), - PatternRule(r'number', '#[ie][bodx]?[^ ()\n]+'), + PatternRule(r'scheme_boolean', r'#[tf]'), + PatternRule(r'scheme_char', r'#\\space|#\\newline|#\\.'), + PatternRule(r'scheme_number', '[+-]?[0-9][^ ()\n]+'), + PatternRule(r'scheme_number', '#[bodx][ie]?[^ ()\n]+'), + PatternRule(r'scheme_number', '#[ie][bodx]?[^ ()\n]+'), PatternRule(r'variable', r'[a-zA-Z!$%&*/:<=>?\^_~][-a-zA-Z0-9!$%&*/:<=>?^_~+.@]*|\+|-|\.\.\.'), ] @@ -36,19 +36,18 @@ class Scheme(mode.Fundamental): closetokens = ('delimiter',) closetags = {')': '('} colors = { - 'comment': ('red', 'default'), + #'comment': ('red', 'default'), - 'keyword': ('cyan', 'default'), - 'builtin': ('cyan', 'default'), + 'scheme_keyword': ('cyan', 'default'), - 'string.start': ('green', 'default'), - 'string.null': ('green', 'default'), - 'string.octal': ('magenta', 'default'), - 'string.escaped': ('magenta', 'default'), - 'string.end': ('green', 'default'), - 'char': ('green', 'default'), - 'boolean': ('magenta', 'default'), - 'number': ('default', 'default'), + #'string.start': ('green', 'default'), + #'string.null': ('green', 'default'), + #'string.octal': ('magenta', 'default'), + #'string.escaped': ('magenta', 'default'), + #'string.end': ('green', 'default'), + 'scheme_char': ('green', 'default'), + 'scheme_boolean': ('magenta', 'default'), + 'scheme_number': ('default', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/sh.py b/mode/sh.py index 21e61e4..2ff8e3c 100644 --- a/mode/sh.py +++ b/mode/sh.py @@ -28,7 +28,7 @@ class CaseGrammar(Grammar): class TestGrammar(Grammar): rules = [ - PatternRule(r'builtin', r"(?:source|alias|bg|bind|break|builtin|cd|command|compgen|complete|declare|dirs|disown|echo|enable|eval|exec|exit|export|fc|fg|getops|hash|help|history|jobs|kill|let|local|logout|popd|printf|pushd|pwd|readonly|read|return|set|shift|shopt|suspend|test|times|trap|type|ulimit|umask|unalias|unset|wait)(?![a-zA-Z0-9_=/])"), + PatternRule(r'sh_builtin', r"(?:source|alias|bg|bind|break|builtin|cd|command|compgen|complete|declare|dirs|disown|echo|enable|eval|exec|exit|export|fc|fg|getops|hash|help|history|jobs|kill|let|local|logout|popd|printf|pushd|pwd|readonly|read|return|set|shift|shopt|suspend|test|times|trap|type|ulimit|umask|unalias|unset|wait)(?![a-zA-Z0-9_=/])"), PatternRule(r'binop', r'==|=|!=|<|>'), PatternRule(r'binop', r'-(?:nt|ot|ef|eq|ne|lt|gt|le|ge)(?![a-zA-Z0-9_])'), PatternRule(r'unop', r'-[a-zA-Z](?![a-zA-Z0-9_])'), @@ -47,10 +47,10 @@ class TestGrammar(Grammar): class ShGrammar(Grammar): rules = [ - PatternRule(r'function', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\(\))'), - PatternRule(r'reserved', r"(?:done|do|elif|else|esac|fi|for|function|if|in|select|then|until|while|time)(?![a-zA-Z0-9_=/])"), + PatternRule(r'sh_function', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\(\))'), + PatternRule(r'sh_reserved', r"(?:done|do|elif|else|esac|fi|for|function|if|in|select|then|until|while|time)(?![a-zA-Z0-9_=/])"), RegionRule(r'case', r'case', Grammar, 'in', CaseGrammar, r'esac'), - PatternRule(r'builtin', r"(?:source|alias|bg|bind|break|builtin|cd|command|compgen|complete|declare|dirs|disown|echo|enable|eval|exec|exit|export|fc|fg|getops|hash|help|history|jobs|kill|let|local|logout|popd|printf|pushd|pwd|readonly|read|return|set|shift|shopt|suspend|times|trap|type|ulimit|umask|unalias|unset|wait)(?![a-zA-Z0-9_=/])"), + PatternRule(r'sh_builtin', r"(?:source|alias|bg|bind|break|builtin|cd|command|compgen|complete|declare|dirs|disown|echo|enable|eval|exec|exit|export|fc|fg|getops|hash|help|history|jobs|kill|let|local|logout|popd|printf|pushd|pwd|readonly|read|return|set|shift|shopt|suspend|times|trap|type|ulimit|umask|unalias|unset|wait)(?![a-zA-Z0-9_=/])"), RegionRule(r'test', r'test', TestGrammar, r'\n'), RegionRule(r'test2', r'\[', TestGrammar, r'\]'), PatternRule(r'delimiter', r";;|[();{}|&><]"), @@ -82,7 +82,7 @@ class ShTabber(tab.StackTabber): if not highlighter.tokens[y]: return False t = highlighter.tokens[y][0] - return t.name == 'function' + return t.name == 'sh_function' def _handle_close_token(self, currlvl, y, i): s = self.get_token(y, i).string if s == ')' and self.markers and self._peek_name() == "case": @@ -95,7 +95,7 @@ class ShTabber(tab.StackTabber): fqname = token.fqname() if token.name == 'continuation': self._opt_append("cont", currlvl + 4) - elif token.name == 'reserved' and token.string == 'else': + elif token.name == 'sh_reserved' and token.string == 'else': currlvl -= 4 elif token.name == 'eol': self._opt_pop("cont") @@ -109,15 +109,15 @@ class Sh(mode.Fundamental): detection = ['sh', 'bash'] grammar = ShGrammar tabbercls = ShTabber - opentokens = ('delimiter', 'reserved', 'case.start') + opentokens = ('delimiter', 'sh_reserved', 'case.start') opentags = {'(': ')', '[': ']', '{': '}', 'do': 'done', 'then': 'fi', 'case': 'esac'} - closetokens = ('delimiter', 'reserved', 'case.end') + closetokens = ('delimiter', 'sh_reserved', 'case.end') closetags = {')': '(', ']': '[', '}': '{', 'done': 'do', 'fi': 'then', 'esac': 'case'} colors = { - 'builtin': ('cyan', 'default', 'bold'), - 'function': ('magenta', 'default', 'bold'), - 'reserved': ('magenta', 'default', 'bold'), + 'sh_builtin': ('cyan', 'default', 'bold'), + 'sh_function': ('magenta', 'default', 'bold'), + 'sh_reserved': ('magenta', 'default', 'bold'), 'variable': ('yellow', 'default', 'bold'), # case statements @@ -125,16 +125,16 @@ class Sh(mode.Fundamental): 'case.middle0': ('magenta', 'default', 'bold'), 'case.end': ('magenta', 'default', 'bold'), - 'delimiter': ('default', 'default', 'bold'), + #'delimiter': ('default', 'default', 'bold'), 'test.start': ('cyan', 'default', 'bold'), 'binop': ('magenta', 'default', 'bold'), 'unop': ('magenta', 'default', 'bold'), - 'string.start': ('green', 'default'), - 'string.variable': ('yellow', 'default'), - 'string.escaped': ('magenta', 'default'), - 'string.null': ('green', 'default'), - 'string.end': ('green', 'default'), + #'string.start': ('green', 'default'), + #'string.variable': ('yellow', 'default'), + #'string.escaped': ('magenta', 'default'), + #'string.null': ('green', 'default'), + #'string.end': ('green', 'default'), 'eval.start': ('cyan', 'default'), 'eval.variable': ('yellow', 'default'), @@ -146,8 +146,8 @@ class Sh(mode.Fundamental): 'neval.null': ('cyan', 'default'), 'neval.end': ('yellow', 'default'), - 'comment': ('red', 'default'), - 'continuation': ('red', 'default'), + #'comment': ('red', 'default'), + #'continuation': ('red', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/sql.py b/mode/sql.py index 82537de..b6de3db 100644 --- a/mode/sql.py +++ b/mode/sql.py @@ -9,16 +9,16 @@ class PlPgSqlGrammar(Grammar): PatternRule(r'delimiter', r':=|[():;,\.\[\]]'), NocasePatternRule(r'attribute', r'(?:check|exists|unique|not null|default|primary key|minvalue|foreign key|references)(?![A-Za-z0-9_])'), - NocasePatternRule(r'keyword', r'(?:declare|begin|end if|end loop|end|raise notice|return|if|while|for|else)(?![A-Za-z0-9_])'), - NocasePatternRule(r'operator', r'(?:case|when|then|else|end|not|and|or|is not|is|in|not in)(?![A-Za-z0-9_])'), - NocasePatternRule(r'keyword', r'(?:create database|create index|create sequence|create table|create trigger|create view|select|insert|update|delete|drop database|drop index|drop sequence|drop table|drop trigger|drop view|create user|alter user|drop user|drop function|grant|revoke|create function|create or replace function|create or replace view|create language|create operator|create type)(?![A-Za-z0-9_])'), + NocasePatternRule(r'sql_keyword', r'(?:declare|begin|end if|end loop|end|raise notice|return|if|while|for|else)(?![A-Za-z0-9_])'), + NocasePatternRule(r'sql_operator', r'(?:case|when|then|else|end|not|and|or|is not|is|in|not in)(?![A-Za-z0-9_])'), + NocasePatternRule(r'sql_keyword', r'(?:create database|create index|create sequence|create table|create trigger|create view|select|insert|update|delete|drop database|drop index|drop sequence|drop table|drop trigger|drop view|create user|alter user|drop user|drop function|grant|revoke|create function|create or replace function|create or replace view|create language|create operator|create type)(?![A-Za-z0-9_])'), NocasePatternRule(r'pseudokeyword', r'(?:returns|language|right join|left join|inner join|outer join|join|where|null|true|false|into|values|as|from|order by|next|asc|desc|limit|distinct|cascade|alias for|using|on)(?![A-Za-z0-9_])'), - NocasePatternRule(r'type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool|record|row)(?![A-Za-z0-9_])'), - PatternRule(r'builtin', r'(?:nextval|current_timestamp|current_time|current_date)(?![A-Za-z0-9_])'), + NocasePatternRule(r'sql_type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool|record|row)(?![A-Za-z0-9_])'), + PatternRule(r'sql_builtin', r'(?:nextval|current_timestamp|current_time|current_date)(?![A-Za-z0-9_])'), RegionRule(r'string', "''", StringGrammar, "''"), - RegionRule(r'quoted', '"', StringGrammar, '"'), - PatternRule(r'variable', r'\$[1-9][0-9]*'), - PatternRule(r'bareword', r'[A-Za-z0-9_]+'), + RegionRule(r'sql_quoted', '"', StringGrammar, '"'), + PatternRule(r'sql_variable', r'\$[1-9][0-9]*'), + PatternRule(r'sql_bareword', r'[A-Za-z0-9_]+'), PatternRule(r'empty', r'^ *\n$'), PatternRule(r'eol', r'\n'), ] @@ -30,13 +30,13 @@ class FunctionGrammar(Grammar): PatternRule(r'delimiter', r':=|[():;,\.\$\[\]]'), PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*(?=\()'), - NocasePatternRule(r'keyword', r'(?:as|returns|language)'), - NocasePatternRule(r'type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool)(?![A-Za-z0-9_])'), + NocasePatternRule(r'sql_keyword', r'(?:as|returns|language)'), + NocasePatternRule(r'sql_type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool)(?![A-Za-z0-9_])'), NocasePatternRule(r'language', r'(?<=language ) *[a-zA-Z_][a-zA-Z0-9_]+'), RegionRule(r'definition', "'", PlPgSqlGrammar, "'(?!')"), - PatternRule(r'bareword', r'[A-Za-z0-9_]+'), + PatternRule(r'sql_bareword', r'[A-Za-z0-9_]+'), PatternRule(r'empty', r'^ *\n$'), PatternRule(r'eol', r'\n'), ] @@ -51,14 +51,14 @@ class SqlGrammar(Grammar): NocaseRegionRule(r'function', r'create or replace function', FunctionGrammar, r';'), NocasePatternRule(r'attribute', r'(?:check|exists|unique|not null|default|primary key|minvalue|foreign key|references)(?![A-Za-z0-9_])'), - NocasePatternRule(r'operator', r'(?:case|when|then|else|end|not|and|or|is not|is|in|not in)(?![A-Za-z0-9_])'), - NocasePatternRule(r'keyword', r'(?:create database|create index|create sequence|create table|create trigger|create view|select|insert|update|delete|drop database|drop index|drop sequence|drop table|drop trigger|drop view|create user|alter user|drop user|drop function|grant|revoke|create function|create or replace function|create or replace view|create language|create operator|create type)(?![A-Za-z0-9_])'), + NocasePatternRule(r'sql_operator', r'(?:case|when|then|else|end|not|and|or|is not|is|in|not in)(?![A-Za-z0-9_])'), + NocasePatternRule(r'sql_keyword', r'(?:create database|create index|create sequence|create table|create trigger|create view|select|insert|update|delete|drop database|drop index|drop sequence|drop table|drop trigger|drop view|create user|alter user|drop user|drop function|grant|revoke|create function|create or replace function|create or replace view|create language|create operator|create type)(?![A-Za-z0-9_])'), NocasePatternRule(r'pseudokeyword', r'(?:returns|language|right join|left join|inner join|outer join|join|where|null|true|false|into|values|as|from|order by|asc|desc|limit|distinct|cascade|using|on)(?![A-Za-z0-9_])'), - NocasePatternRule(r'type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool)(?![A-Za-z0-9_])'), - PatternRule(r'builtin', r'(?:nextval|current_timestamp|current_time|current_date)(?![A-Za-z0-9_])'), + NocasePatternRule(r'sql_type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool)(?![A-Za-z0-9_])'), + PatternRule(r'sql_builtin', r'(?:nextval|current_timestamp|current_time|current_date)(?![A-Za-z0-9_])'), RegionRule(r'string', "'", StringGrammar, "'"), - RegionRule(r'quoted', '"', StringGrammar, '"'), - PatternRule(r'bareword', r'[A-Za-z0-9_]+'), + RegionRule(r'sql_quoted', '"', StringGrammar, '"'), + PatternRule(r'sql_bareword', r'[A-Za-z0-9_]+'), PatternRule(r'empty', r'^ *\n$'), PatternRule(r'eol', r'\n'), ] @@ -78,7 +78,7 @@ class SqlTabber(tab.StackTabber): s = token.string.lower() if token.name == 'delimiter' and s == ';': self._opt_pop('cont') - elif token.name == 'keyword': + elif token.name == 'sql_keyword': if s == 'declare': self._append('declare', currlvl + 4) elif s == 'begin': @@ -116,21 +116,23 @@ class Sql(mode.Fundamental): closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} colors = { - 'comment': ('red', 'default'), - 'operator': ('yellow', 'default'), + #'comment': ('red', 'default'), + 'sql_operator': ('yellow', 'default'), 'attribute': ('magenta', 'default'), - 'keyword': ('cyan', 'default'), + 'sql_keyword': ('cyan', 'default'), 'pseudokeyword': ('cyan', 'default'), - 'type': ('green', 'default'), - 'builtin': ('yellow', 'default'), - 'quoted': ('yellow', 'default'), - 'string.start': ('green', 'default'), - 'string.null': ('green', 'default'), - 'string.escaped': ('magenta', 'default'), - 'string.octal': ('magenta', 'default'), - 'string.end': ('green', 'default'), - 'variable': ('yellow', 'default'), - 'bareword': ('default', 'default'), + 'sql_type': ('green', 'default'), + 'sql_builtin': ('yellow', 'default'), + 'sql_quoted.start': ('yellow', 'default'), + 'sql_quoted.null': ('yellow', 'default'), + 'sql_quoted.end': ('yellow', 'default'), + #'string.start': ('green', 'default'), + #'string.null': ('green', 'default'), + #'string.escaped': ('magenta', 'default'), + #'string.octal': ('magenta', 'default'), + #'string.end': ('green', 'default'), + 'sql_variable': ('yellow', 'default'), + 'sql_bareword': ('default', 'default'), 'function.start': ('cyan', 'default'), 'function.null': ('default', 'default'), @@ -139,7 +141,7 @@ class Sql(mode.Fundamental): 'function.end': ('default', 'default'), 'function.definition.start': ('magenta', 'default'), - 'function.definition.bareword': ('magenta', 'default'), + 'function.definition.sql_bareword': ('magenta', 'default'), 'function.definition.null': ('magenta', 'default'), 'function.definition.end': ('magenta', 'default'), } diff --git a/mode/text.py b/mode/text.py index 25f7ed0..280b5e1 100644 --- a/mode/text.py +++ b/mode/text.py @@ -39,12 +39,12 @@ class Text(mode.Fundamental): extensions=['.txt'] grammar = TextGrammar colors = { - 'misspelled': ('red', 'default'), - 'cont.start': ('default', 'default'), - 'cont.end': ('default', 'default'), - 'word': ('default', 'default'), - 'punct': ('default', 'default'), - 'stuff': ('default', 'default'), + #'misspelled': ('red', 'default'), + #'cont.start': ('default', 'default'), + #'cont.end': ('default', 'default'), + #'word': ('default', 'default'), + #'punct': ('default', 'default'), + #'stuff': ('default', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/text2.py b/mode/text2.py index b040582..b5094e8 100644 --- a/mode/text2.py +++ b/mode/text2.py @@ -4,8 +4,8 @@ from mode.text import WordRule, ContinuedRule class Text2Grammar(Grammar): rules = [ - PatternRule(name=r'email', pattern=r'(?:^|(?<=[ :]))@\n ]+@(?:[^<>@\.\n ]+\.)*[^<>@\.\n ]+>?'), - PatternRule(name=r'url', pattern=r'(?:^|(?<= ))(?:http|https|ftp|sftp|file|smtp|smtps|torrent|news|jabber|irc|telnet)://(?:[^\.\n ]+\.)*[^\.\n ]+'), + PatternRule(name=r'text2_email', pattern=r'(?:^|(?<=[ :]))@\n ]+@(?:[^<>@\.\n ]+\.)*[^<>@\.\n ]+>?'), + PatternRule(name=r'text2_url', pattern=r'(?:^|(?<= ))(?:http|https|ftp|sftp|file|smtp|smtps|torrent|news|jabber|irc|telnet)://(?:[^\.\n ]+\.)*[^\.\n ]+'), ContinuedRule(), WordRule(), PatternRule(r'punct', r'[^a-zA-Z0-9_]'), @@ -18,14 +18,14 @@ class Text2(mode.text.Text): extensions = ['.txt'] extensions = [] colors = { - 'email': ('cyan', 'default'), - 'url': ('green', 'default'), - 'misspelled': ('red', 'default'), - 'cont.start': ('default', 'default'), - 'cont.end': ('default', 'default'), - 'word': ('default', 'default'), - 'punct': ('default', 'default'), - 'stuff': ('default', 'default'), + 'text2_email': ('cyan', 'default'), + 'text2_url': ('green', 'default'), + #'misspelled': ('red', 'default'), + #'cont.start': ('default', 'default'), + #'cont.end': ('default', 'default'), + #'word': ('default', 'default'), + #'punct': ('default', 'default'), + #'stuff': ('default', 'default'), } install = Text2.install diff --git a/mode/tt.py b/mode/tt.py index be6d68c..cab48c5 100644 --- a/mode/tt.py +++ b/mode/tt.py @@ -25,7 +25,7 @@ class TemplateGrammar(Grammar): rules = [ RegionRule(r'comment', r''), RegionRule(r'directive', r'\[\%', DirectiveGrammar, r'%%\]'), - RegionRule(r'tag', r''), + RegionRule(r'tt_tag', r''), ] class Template(mode.Fundamental): @@ -33,9 +33,9 @@ class Template(mode.Fundamental): extensions = ['.tt'] grammar = TemplateGrammar colors = { - 'comment.start': ('red', 'default'), - 'comment.null': ('red', 'default'), - 'comment.end': ('red', 'default'), + #'comment.start': ('red', 'default'), + #'comment.null': ('red', 'default'), + #'comment.end': ('red', 'default'), 'directive.start': ('magenta', 'default'), 'directive.comment': ('red', 'default'), @@ -48,14 +48,14 @@ class Template(mode.Fundamental): 'directive.null': ('magenta', 'default'), 'directive.end': ('magenta', 'default'), - 'tag.start': ('default', 'default'), - 'tag.namespace': ('magenta', 'default'), - 'tag.name': ('blue', 'default'), - 'tag.attrname': ('cyan', 'default'), - 'tag.string.start': ('green', 'default'), - 'tag.string.null': ('green', 'default'), - 'tag.string.end': ('green', 'default'), - 'tag.end': ('default', 'default'), + 'tt_tag.start': ('default', 'default'), + 'tt_tag.namespace': ('magenta', 'default'), + 'tt_tag.name': ('blue', 'default'), + 'tt_tag.attrname': ('cyan', 'default'), + 'tt_tag.string.start': ('green', 'default'), + 'tt_tag.string.null': ('green', 'default'), + 'tt_tag.string.end': ('green', 'default'), + 'tt_tag.end': ('default', 'default'), } def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/mode/xml.py b/mode/xml.py index 1af5c28..2ab1521 100644 --- a/mode/xml.py +++ b/mode/xml.py @@ -14,7 +14,7 @@ class XMLGrammar(Grammar): rules = [ # TODO: how does cdata work again? RegionRule(r'comment', r''), - RegionRule(r'tag', r'<', TagGrammar, r'/?>'), + RegionRule(r'xml_tag', r'<', TagGrammar, r'/?>'), ] class XML(mode.Fundamental): @@ -22,17 +22,17 @@ class XML(mode.Fundamental): extensions = ['.xml', '.xml.in'] grammar = XMLGrammar colors = { - 'comment.start': ('red', 'default'), - 'comment.null': ('red', 'default'), - 'comment.end': ('red', 'default'), - 'tag.start': ('default', 'default'), - 'tag.namespace': ('magenta', 'default'), - 'tag.name': ('blue', 'default'), - 'tag.attrname': ('cyan', 'default'), - 'tag.string.start': ('green', 'default'), - 'tag.string.null': ('green', 'default'), - 'tag.string.end': ('green', 'default'), - 'tag.end': ('default', 'default'), + #'comment.start': ('red', 'default'), + #'comment.null': ('red', 'default'), + #'comment.end': ('red', 'default'), + 'xml_tag.start': ('default', 'default'), + 'xml_tag.namespace': ('magenta', 'default'), + 'xml_tag.name': ('blue', 'default'), + 'xml_tag.attrname': ('cyan', 'default'), + 'xml_tag.string.start': ('green', 'default'), + 'xml_tag.string.null': ('green', 'default'), + 'xml_tag.string.end': ('green', 'default'), + 'xml_tag.end': ('default', 'default'), } install = XML.install