gory perl fixes inspired by gory perl modules

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-07-17 16:56:32 -04:00
parent 0bbd3f52e3
commit 12c62a423c
1 changed files with 40 additions and 18 deletions

View File

@ -58,6 +58,14 @@ def _make_string_rules(forbidden):
PatternRule('cast', r"[\$\@\%\&]{.+?}"),
PatternRule('array', r"@\$*" + word2),
]
if forbidden == ')':
rules.append(PatternRule('data', r"\([^\(\)]*\)"))
elif forbidden == '}':
rules.append(PatternRule('data', r"{[^{}]*}"))
elif forbidden == ']':
rules.append(PatternRule('data', r"\[[^\[\]]*\]"))
elif forbidden == '>':
rules.append(PatternRule('data', r"<[^<>]*>"))
return rules
class QuotedWords(Grammar): rules = [
@ -72,9 +80,14 @@ class NoAngle(Grammar): rules = [PatternRule('data', '[^>]+')]
class NoHash(Grammar): rules = [PatternRule('data', '[^#]+')]
class DataGrammar(Grammar): rules = [PatternRule('data', '.+')]
class StrictStringGrammar(Grammar): rules = [PatternRule('escaped', r"\\'")]
class StringGrammar(Grammar): rules = _make_string_rules('"')
class EvalGrammar(Grammar): rules = _make_string_rules('`')
class StrictStringGrammar(Grammar): rules = [
PatternRule('escaped', r"\\[\\']"),
PatternRule('data', r"[^\\']+"),
]
class StringGrammar(Grammar):
rules = _make_string_rules('"') + [PatternRule('data', '[^\\"]+')]
class EvalGrammar(Grammar):
rules = _make_string_rules('`') + [PatternRule('data', '[^\\`]+')]
class TranslateGrammar1(Grammar):
rules = [PatternRule('data', r"(?:\\.|[^\\/])")]
@ -83,6 +96,7 @@ class TranslateGrammar2(Grammar):
class TranslateGrammarX(Grammar):
rules = [PatternRule('data', r"(?:\\.|[^\\%(delim)s])")]
class MatchGrammar0(Grammar): rules = _make_string_rules(None)
class MatchGrammar1(Grammar): rules = _make_string_rules('/')
class MatchGrammar2(Grammar): rules = _make_string_rules('#')
class MatchGrammar3(Grammar): rules = _make_string_rules(')')
@ -122,13 +136,26 @@ class PerlGrammar(Grammar):
RegionRule('perl.string', '"', StringGrammar, '"'),
RegionRule('perl.string', "'", StrictStringGrammar, "'"),
RegionRule('perl.evalstring', "`", EvalGrammar, "`"),
PatternRule('perl.number', r'0?\.[0-9]+|[0-9]+(?:\.[0-9]+)?'),
PatternRule('perl.keyword', "(?<!->)(?: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('perl.keyword', "(?<!->)(?:STDIN|STDERR|STDOUT|continue|do|else|elsif|eval|foreach|for|if|last|my|next|no|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])"),
PatternRule('perl.hash_key', '(?<={)' + wchr2 + '+(?=})'),
PatternRule('perl.method', '(?<=->)' + word1),
PatternRule('perl.hash_key', wchr2 + '+(?= *=>)'),
PatternRule('perl.length', r"\$#" + word2),
PatternRule('perl.cast', r'[\$\@\%\&\*](?= *{)'),
PatternRule('perl.number', r'0[xX][0-9A-Fa-f]+'),
PatternRule('perl.number', r'0?\.[0-9]+|[0-9]+(?:\.[0-9]+)?'),
# built-in scalars
PatternRule('perl.scalar', r'\$[_ab&`\'\+\*\./|,\\";#\%=\-~\^:\?!@\$<>()\[\]](?!' + wchr2 + ')'),
PatternRule('perl.scalar', r'\$\d+(?!' + wchr2 +')'),
PatternRule('perl.scalar', r'\$\^(?:' + word1 + '|' + wchr1 + ')'),
PatternRule('perl.scalar', r'\$\^O'),
PatternRule('perl.scalar', r'\${\^' + word1 + '}'),
PatternRule('perl.array', r'\@[\+\-]'),
PatternRule('perl.hash', r'\%(?:[!]|^H)'),
PatternRule('perl.scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" +
wchr2 + ")"),
PatternRule('perl.array', "@_"),
@ -152,18 +179,10 @@ class PerlGrammar(Grammar):
RegionRule('perl.match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)|(?<=if)|(?<=unless)|(?<=while)|(?<=until)|(?<=\|\|)|(?<=&&)|(?<==)) *(?P<delim>/)', MatchGrammar1, '/[a-z]*'),
RegionRule('perl.match', 'm *(?P<delim>/)', MatchGrammar1, '/[a-z]*'),
RegionRule('perl.match', 'm *(?P<delim>[^ #a-zA-Z0-9_])',
StringGrammar, '%(delim)s[a-z]*'),
MatchGrammar0, '%(delim)s[a-z]*'),
RegionRule('perl.match', 'm(?P<delim>#)', MatchGrammar2, '#[a-z]*'),
# match regexes; paired delimiters
#RegionRule('perl.replace', r's *(?P<delim>\()', MatchGrammar3,
# r'\) *\(', MatchGrammar3, r'\)[a-z]*'),
#RegionRule('perl.replace', r's *(?P<delim>\[)', MatchGrammar4,
# r'\] *\[', MatchGrammar4, r'\][a-z]*'),
#RegionRule('perl.replace', r's *(?P<delim>\{)', MatchGrammar5,
# r'\} *\{', MatchGrammar5, r'\}[a-z]*'),
#RegionRule('perl.replace', r's *(?P<delim>\<)', MatchGrammar6,
# r'\> *\<', MatchGrammar6, r'\>[a-z]*'),
RegionRule('perl.replace', r's *(?P<delim>\()', MatchGrammar3,
r'\)', WhitespaceGrammar, '\(', MatchGrammar3, r'\)[a-z]*'),
RegionRule('perl.replace', r's *(?P<delim>\[)', MatchGrammar4,
@ -177,8 +196,8 @@ class PerlGrammar(Grammar):
RegionRule('perl.replace', 's *(?P<delim>/)', MatchGrammar1,
'/', MatchGrammar1, '/[a-z]*'),
RegionRule('perl.replace', 's *(?P<delim>[^ a-zA-Z0-9_])',
StringGrammar, '%(delim)s',
StringGrammar, '%(delim)s[a-z]*'),
MatchGrammar0, '%(delim)s',
MatchGrammar0, '%(delim)s[a-z]*'),
RegionRule('perl.replace', 's(?P<delim>#)',
MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'),
@ -195,6 +214,7 @@ class PerlGrammar(Grammar):
PatternRule('perl.package', "(?<=package )" + word2),
PatternRule('perl.sub', "(?<=sub )" + word2),
PatternRule('perl.use', "(?<=use )" + word2),
PatternRule('perl.use', "(?<=no )" + word2),
PatternRule('perl.require', "(?<=require )" + word2),
PatternRule('perl.label', word1 + ':(?!:)'),
PatternRule('perl.function', r"&\$*" + word2),
@ -207,8 +227,8 @@ class PerlGrammar(Grammar):
RegionRule('perl.quoted', r'q[rqx] *(?P<delim>\[)', QuotedGrammar4, r'\]'),
RegionRule('perl.quoted', "q[rqx] *(?P<delim>')", Grammar, "'"),
RegionRule('perl.quoted', 'q[rqx] *(?P<delim>[^ a-zA-Z0-9#])',
StringGrammar, '%(delim)s'),
RegionRule('perl.quoted', 'q[rqx](?P<delim>#)', StringGrammar, '#'),
MatchGrammar0, '%(delim)s'),
RegionRule('perl.quoted', 'q[rqx](?P<delim>#)', MatchGrammar0, '#'),
# quote operator: q() and qw() do not interpolate
RegionRule('perl.quoted', r'qw? *\(', QuotedWords, r'\)'),
@ -781,6 +801,7 @@ class Perl(Fundamental):
# match regex
'match.start': ('cyan', 'default', 'bold'),
'match.end': ('cyan', 'default', 'bold'),
'match.data': ('cyan', 'default', 'bold'),
'match.null': ('cyan', 'default', 'bold'),
# replace regex
@ -788,6 +809,7 @@ class Perl(Fundamental):
'replace.middle0': ('cyan', 'default', 'bold'),
'replace.middle1': ('cyan', 'default', 'bold'),
'replace.end': ('cyan', 'default', 'bold'),
'replace.data': ('cyan', 'default', 'bold'),
'replace.null': ('cyan', 'default', 'bold'),
'replace.escaped': ('magenta', 'default', 'bold'),
'replace.deref': ('yellow', 'default', 'bold'),