starting work on lexing improvements

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-07-13 12:30:47 +00:00
parent dd784fb483
commit b681024851
4 changed files with 25 additions and 26 deletions

View File

@ -11,8 +11,8 @@ class JavascriptGrammar(Grammar):
PatternRule(name=r'function', pattern=r"(?<=function )[a-zA-Z_][a-zA-Z0-9_]*"), 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'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'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'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'(?: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'nonreserved', pattern=r'(?:get|include|set)(?![a-zA-Z0-9_])'),
PatternRule(name=r"method", pattern=r"(?<=\.)[a-zA-Z_][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]: if not highlighter.tokens[y]:
return False return False
t = highlighter.tokens[y][0] 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): def _handle_other_token(self, currlvl, y, i):
token = self.get_token(y, i) token = self.get_token(y, i)
fqname = token.fqname() fqname = token.fqname()
@ -73,8 +73,7 @@ class Javascript(mode2.Fundamental):
'function': color.build('blue', 'default'), 'function': color.build('blue', 'default'),
'class': color.build('green', 'default'), 'class': color.build('green', 'default'),
'reserved1': color.build('cyan', 'default'), 'reserved': color.build('cyan', 'default'),
'reserved2': color.build('cyan', 'default'),
'nonreserved': color.build('cyan', 'default'), 'nonreserved': color.build('cyan', 'default'),
'delimiter': color.build('default', 'default'), 'delimiter': color.build('default', 'default'),

View File

@ -4,9 +4,9 @@ from lex2 import Grammar, PatternRule
class MuttGrammar(Grammar): class MuttGrammar(Grammar):
rules = [ rules = [
PatternRule(name=r'header', pattern=r'^(?:From|To|Cc|Bcc|Subject|Reply-To|In-Reply-To|Delivered-To|Date):'), 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'quoteb', pattern=r'^ *(?:(?: *>){3})*(?: *>){2}.*$'),
PatternRule(name=r'quote2', pattern=r'^ *(?:(?: *>){3})*(?: *>){2}.*$'), PatternRule(name=r'quotea', pattern=r'^ *(?:(?: *>){3})*(?: *>){1}.*$'),
PatternRule(name=r'quote3', pattern=r'^ *(?:(?: *>){3})*(?: *>){3}.*$'), PatternRule(name=r'quotec', pattern=r'^ *(?:(?: *>){3})*(?: *>){3}.*$'),
PatternRule(name=r'email', pattern=r'(?:^|(?<=[ :]))<?[^<>@\n ]+@(?:[^<>@\.\n ]+\.)*[^<>@\.\n ]+>?'), 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'url', pattern=r'(?:^|(?<= ))(?:http|https|ftp|sftp|file|smtp|smtps|torrent|news|jabber|irc|telnet)://(?:[^\.\n ]+\.)*[^\.\n ]+'),
mode_text.ContinuedRule(), mode_text.ContinuedRule(),
@ -26,9 +26,9 @@ class Mutt(mode2.Fundamental):
'header': color.build('green', 'default', 'bold'), 'header': color.build('green', 'default', 'bold'),
'email': color.build('cyan', 'default', 'bold'), 'email': color.build('cyan', 'default', 'bold'),
'url': color.build('cyan', 'default', 'bold'), 'url': color.build('cyan', 'default', 'bold'),
'quote1': color.build('yellow', 'default', 'bold'), 'quotea': color.build('yellow', 'default', 'bold'),
'quote2': color.build('cyan', 'default', 'bold'), 'quoteb': color.build('cyan', 'default', 'bold'),
'quote3': color.build('magenta', 'default', 'bold'), 'quotec': color.build('magenta', 'default', 'bold'),
'misspelled': color.build('red', 'default'), 'misspelled': color.build('red', 'default'),
'cont.start': color.build('default', 'default'), 'cont.start': color.build('default', 'default'),
'cont.end': color.build('default', 'default'), 'cont.end': color.build('default', 'default'),

View File

@ -32,17 +32,17 @@ class StringGrammar(Grammar):
class PerlGrammar(Grammar): class PerlGrammar(Grammar):
rules = [ rules = [
RegionRule(r'heredoc1', r"<<(?P<heredoc>[a-zA-Z0-9_]+) *;", StringGrammar, r'^%(heredoc)s$'), RegionRule(r'heredoc', r"<<(?P<heredoc>[a-zA-Z0-9_]+) *;", StringGrammar, r'^%(heredoc)s$'),
RegionRule(r'heredoc1', r'<< *"(?P<heredoc>[a-zA-Z0-9_]+)" *;', StringGrammar, r'^%(heredoc)s$'), RegionRule(r'heredoc', r'<< *"(?P<heredoc>[a-zA-Z0-9_]+)" *;', StringGrammar, r'^%(heredoc)s$'),
RegionRule(r'heredoc2', r"<< *'(?P<heredoc>[a-zA-Z0-9_]+)' *;", Grammar, r'^%(heredoc)s$'), RegionRule(r'heredoc', r"<< *'(?P<heredoc>[a-zA-Z0-9_]+)' *;", Grammar, r'^%(heredoc)s$'),
RegionRule(r'eval_heredoc', r"<< *`(?P<heredoc>[a-zA-Z0-9_]+)` *;", StringGrammar, r'^%(heredoc)s$'), RegionRule(r'eval_heredoc', r"<< *`(?P<heredoc>[a-zA-Z0-9_]+)` *;", StringGrammar, r'^%(heredoc)s$'),
RegionRule(r'endblock', r"^__END__|__DATA__ *$", Grammar, r''), RegionRule(r'endblock', r"^__END__|__DATA__ *$", Grammar, r''),
RegionRule(r'pod', r'^=[a-zA-Z0-9_]+', PodGrammar, r'^=cut'), RegionRule(r'pod', r'^=[a-zA-Z0-9_]+', PodGrammar, r'^=cut'),
PatternRule(r'comment', r'#.*$'), PatternRule(r'comment', r'#.*$'),
RegionRule(r'string1', r'"', StringGrammar, r'"'), RegionRule(r'string', r'"', StringGrammar, r'"'),
RegionRule(r'string2', r"'", Grammar, r"'"), RegionRule(r'string', r"'", Grammar, r"'"),
RegionRule(r'evalstring', r"`", StringGrammar, r"`"), RegionRule(r'evalstring', r"`", StringGrammar, r"`"),
PatternRule(r'number', r'0?\.[0-9]+|[0-9]+(?:\.[0-9]+)?'), 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'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'delimiter', r"[,;=\?(){}\[\]]|->|=>|(?<!:):(?!=:)"),
PatternRule(r'operator', r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="), PatternRule(r'operator', r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
PatternRule(r'operator', r"\+\+|\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|\*|&&|&|\|\||\||/|\^|==|//|~|=~|!~|!=|%|!|\.|x(?![a-zA-Z_])"), 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'bareword', r'(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*'),
PatternRule(r"eol", r"\n$"), PatternRule(r"eol", r"\n$"),
@ -201,7 +201,7 @@ class Perl(mode2.Fundamental):
'sub': color.build('cyan', 'default'), 'sub': color.build('cyan', 'default'),
'number': color.build('default', 'default'), 'number': color.build('default', 'default'),
'operator': color.build('default', 'default'), 'operator': color.build('default', 'default'),
'operator2': color.build('magenta', 'default'), 'noperator': color.build('magenta', 'default'),
'endblock': color.build('red', 'default'), 'endblock': color.build('red', 'default'),
'keyword': color.build('magenta', 'default'), 'keyword': color.build('magenta', 'default'),
'cast': color.build('yellow', 'default'), 'cast': color.build('yellow', 'default'),

View File

@ -17,8 +17,8 @@ class ShGrammar(Grammar):
PatternRule(r'operator', r"(?:-eq|-ne|-gt|-lt|-ge|-le| = | != )"), PatternRule(r'operator', r"(?:-eq|-ne|-gt|-lt|-ge|-le| = | != )"),
PatternRule(r'delimiter', r";;|[\[\]\(\);\{\}|&><]"), PatternRule(r'delimiter', r";;|[\[\]\(\);\{\}|&><]"),
RegionRule(r'eval', '`', StringGrammar, '`'), RegionRule(r'eval', '`', StringGrammar, '`'),
#RegionRule(r'eval2', r'\$\(', None, r'\)'), #RegionRule(r'neval', r'\$\(', None, r'\)'),
RegionRule(r'eval2', r'\$\(', StringGrammar, 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-Z_][a-zA-Z_][a-zA-Z0-9_]*(?==)"),
PatternRule(r'variable', r"\${(?:[a-zA-Z0-9_]+|\?\$)}"), PatternRule(r'variable', r"\${(?:[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.null': color.build('cyan', 'default'),
'eval.end': color.build('cyan', 'default'), 'eval.end': color.build('cyan', 'default'),
#'eval2.start': color.build('cyan', 'default'), #'neval.start': color.build('cyan', 'default'),
#'eval2.end': color.build('cyan', 'default'), #'neval.end': color.build('cyan', 'default'),
'eval2.start': color.build('yellow', 'default'), 'neval.start': color.build('yellow', 'default'),
'eval2.variable': color.build('yellow', 'default'), 'neval.variable': color.build('yellow', 'default'),
'eval2.null': color.build('cyan', 'default'), 'neval.null': color.build('cyan', 'default'),
'eval2.end': color.build('yellow', 'default'), 'neval.end': color.build('yellow', 'default'),
'comment': color.build('red', 'default'), 'comment': color.build('red', 'default'),
'continuation': color.build('red', 'default'), 'continuation': color.build('red', 'default'),