From b6810248518f6c948f83b024e21268497a5a5b56 Mon Sep 17 00:00:00 2001 From: moculus Date: Fri, 13 Jul 2007 12:30:47 +0000 Subject: [PATCH] starting work on lexing improvements --HG-- branch : pmacs2 --- mode_javascript.py | 9 ++++----- mode_mutt.py | 12 ++++++------ mode_perl.py | 14 +++++++------- mode_sh.py | 16 ++++++++-------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/mode_javascript.py b/mode_javascript.py index 95752c0..2b9a7e0 100644 --- a/mode_javascript.py +++ b/mode_javascript.py @@ -11,8 +11,8 @@ class JavascriptGrammar(Grammar): PatternRule(name=r'function', pattern=r"(?<=function )[a-zA-Z_][a-zA-Z0-9_]*"), PatternRule(name=r'class', pattern=r"(?<=class )[a-zA-Z_][a-zA-Z0-9_]*"), - PatternRule(name=r'reserved1', pattern=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(name=r'reserved2', pattern=r'(?:abstract|debugger|enum|goto|implements|interface|native|protected|synchronized|throws|transient|volatile)(?![a-zA-Z0-9_])'), + PatternRule(name=r'reserved', pattern=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(name=r'reserved', pattern=r'(?:abstract|debugger|enum|goto|implements|interface|native|protected|synchronized|throws|transient|volatile)(?![a-zA-Z0-9_])'), PatternRule(name=r'nonreserved', pattern=r'(?:get|include|set)(?![a-zA-Z0-9_])'), PatternRule(name=r"method", pattern=r"(?<=\.)[a-zA-Z_][a-zA-Z0-9_]*(?= *\()"), @@ -42,7 +42,7 @@ class JavascriptTabber(tab2.StackTabber): if not highlighter.tokens[y]: return False t = highlighter.tokens[y][0] - return t.name == 'reserved1' and t.string == 'function' + return t.name == 'reserved' and t.string == 'function' def _handle_other_token(self, currlvl, y, i): token = self.get_token(y, i) fqname = token.fqname() @@ -73,8 +73,7 @@ class Javascript(mode2.Fundamental): 'function': color.build('blue', 'default'), 'class': color.build('green', 'default'), - 'reserved1': color.build('cyan', 'default'), - 'reserved2': color.build('cyan', 'default'), + 'reserved': color.build('cyan', 'default'), 'nonreserved': color.build('cyan', 'default'), 'delimiter': color.build('default', 'default'), diff --git a/mode_mutt.py b/mode_mutt.py index 17aeb3c..3ffbf97 100644 --- a/mode_mutt.py +++ b/mode_mutt.py @@ -4,9 +4,9 @@ from lex2 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'quote1', pattern=r'^ *(?:(?: *>){3})*(?: *>){1}.*$'), - PatternRule(name=r'quote2', pattern=r'^ *(?:(?: *>){3})*(?: *>){2}.*$'), - PatternRule(name=r'quote3', pattern=r'^ *(?:(?: *>){3})*(?: *>){3}.*$'), + PatternRule(name=r'quoteb', pattern=r'^ *(?:(?: *>){3})*(?: *>){2}.*$'), + PatternRule(name=r'quotea', pattern=r'^ *(?:(?: *>){3})*(?: *>){1}.*$'), + PatternRule(name=r'quotec', pattern=r'^ *(?:(?: *>){3})*(?: *>){3}.*$'), 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 ]+'), mode_text.ContinuedRule(), @@ -26,9 +26,9 @@ class Mutt(mode2.Fundamental): 'header': color.build('green', 'default', 'bold'), 'email': color.build('cyan', 'default', 'bold'), 'url': color.build('cyan', 'default', 'bold'), - 'quote1': color.build('yellow', 'default', 'bold'), - 'quote2': color.build('cyan', 'default', 'bold'), - 'quote3': color.build('magenta', 'default', 'bold'), + 'quotea': color.build('yellow', 'default', 'bold'), + 'quoteb': color.build('cyan', 'default', 'bold'), + 'quotec': color.build('magenta', 'default', 'bold'), 'misspelled': color.build('red', 'default'), 'cont.start': color.build('default', 'default'), 'cont.end': color.build('default', 'default'), diff --git a/mode_perl.py b/mode_perl.py index 5760d91..f652cb8 100644 --- a/mode_perl.py +++ b/mode_perl.py @@ -32,17 +32,17 @@ class StringGrammar(Grammar): class PerlGrammar(Grammar): rules = [ - RegionRule(r'heredoc1', r"<<(?P[a-zA-Z0-9_]+) *;", StringGrammar, r'^%(heredoc)s$'), - RegionRule(r'heredoc1', r'<< *"(?P[a-zA-Z0-9_]+)" *;', StringGrammar, r'^%(heredoc)s$'), - RegionRule(r'heredoc2', r"<< *'(?P[a-zA-Z0-9_]+)' *;", Grammar, r'^%(heredoc)s$'), + RegionRule(r'heredoc', r"<<(?P[a-zA-Z0-9_]+) *;", StringGrammar, r'^%(heredoc)s$'), + RegionRule(r'heredoc', r'<< *"(?P[a-zA-Z0-9_]+)" *;', StringGrammar, r'^%(heredoc)s$'), + RegionRule(r'heredoc', r"<< *'(?P[a-zA-Z0-9_]+)' *;", Grammar, r'^%(heredoc)s$'), RegionRule(r'eval_heredoc', r"<< *`(?P[a-zA-Z0-9_]+)` *;", StringGrammar, r'^%(heredoc)s$'), RegionRule(r'endblock', r"^__END__|__DATA__ *$", Grammar, r''), RegionRule(r'pod', r'^=[a-zA-Z0-9_]+', PodGrammar, r'^=cut'), PatternRule(r'comment', r'#.*$'), - RegionRule(r'string1', r'"', StringGrammar, r'"'), - RegionRule(r'string2', r"'", Grammar, r"'"), + RegionRule(r'string', r'"', StringGrammar, r'"'), + RegionRule(r'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_])"), @@ -96,7 +96,7 @@ class PerlGrammar(Grammar): PatternRule(r'delimiter', r"[,;=\?(){}\[\]]|->|=>|(?>=|<<=|\*\*="), PatternRule(r'operator', r"\+\+|\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|\*|&&|&|\|\||\||/|\^|==|//|~|=~|!~|!=|%|!|\.|x(?![a-zA-Z_])"), - PatternRule(r'operator2', r"(?:xor|or|not|ne|lt|le|gt|ge|eq|cmp|and)(?![a-zA-Z_])"), + PatternRule(r'noperator', r"(?:xor|or|not|ne|lt|le|gt|ge|eq|cmp|and)(?![a-zA-Z_])"), PatternRule(r'bareword', r'(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*'), PatternRule(r"eol", r"\n$"), @@ -201,7 +201,7 @@ class Perl(mode2.Fundamental): 'sub': color.build('cyan', 'default'), 'number': color.build('default', 'default'), 'operator': color.build('default', 'default'), - 'operator2': color.build('magenta', 'default'), + 'noperator': color.build('magenta', 'default'), 'endblock': color.build('red', 'default'), 'keyword': color.build('magenta', 'default'), 'cast': color.build('yellow', 'default'), diff --git a/mode_sh.py b/mode_sh.py index 03d998e..2f22c0a 100644 --- a/mode_sh.py +++ b/mode_sh.py @@ -17,8 +17,8 @@ class ShGrammar(Grammar): PatternRule(r'operator', r"(?:-eq|-ne|-gt|-lt|-ge|-le| = | != )"), PatternRule(r'delimiter', r";;|[\[\]\(\);\{\}|&><]"), RegionRule(r'eval', '`', StringGrammar, '`'), - #RegionRule(r'eval2', r'\$\(', None, r'\)'), - RegionRule(r'eval2', r'\$\(', StringGrammar, r'\)'), + #RegionRule(r'neval', r'\$\(', None, r'\)'), + RegionRule(r'neval', r'\$\(', StringGrammar, r'\)'), PatternRule(r'variable', r"(?:^|(?<= ))[a-zA-Z_][a-zA-Z_][a-zA-Z0-9_]*(?==)"), PatternRule(r'variable', r"\${(?:[a-zA-Z0-9_]+|\?\$)}"), PatternRule(r"variable", r"\$[^({][a-zA-Z0-9_]*"), @@ -86,12 +86,12 @@ class Sh(mode2.Fundamental): 'eval.null': color.build('cyan', 'default'), 'eval.end': color.build('cyan', 'default'), - #'eval2.start': color.build('cyan', 'default'), - #'eval2.end': color.build('cyan', 'default'), - 'eval2.start': color.build('yellow', 'default'), - 'eval2.variable': color.build('yellow', 'default'), - 'eval2.null': color.build('cyan', 'default'), - 'eval2.end': color.build('yellow', 'default'), + #'neval.start': color.build('cyan', 'default'), + #'neval.end': color.build('cyan', 'default'), + 'neval.start': color.build('yellow', 'default'), + 'neval.variable': color.build('yellow', 'default'), + 'neval.null': color.build('cyan', 'default'), + 'neval.end': color.build('yellow', 'default'), 'comment': color.build('red', 'default'), 'continuation': color.build('red', 'default'),