improved perl grammar and some clean up

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-07-26 22:50:12 -04:00
parent e3b2818038
commit 34f81cdb0d
2 changed files with 205 additions and 200 deletions

View File

@ -214,13 +214,12 @@ class Application(object):
def _load_config_defaults(self):
self.config['ignore_suffix'] = ['~', '-', 'CVS', '.svn', '.git', '.hg']
self.config['error_timeout'] = -1
self.config['max_error_len'] = 192
self.config['max_num_kills'] = 64
self.config['word_letters'] = string.ascii_letters + string.digits
self.config['default_color'] = ('default', 'default',)
self.config['margin'] = 80
self.config['margin'] = 79
self.config['margin_color'] = 'blue'
self.config['use_last_replace'] = False

View File

@ -16,6 +16,8 @@ from tab import StackTabber, StackTabber2
from parse import Any, And, Or, Optional, Name, Match, Matchs
import term
class PerlGrammar(Grammar): pass
class WhitespaceGrammar(Grammar):
rules = [
PatternRule('spaces', ' +'),
@ -49,16 +51,21 @@ def _make_string_rules(forbidden):
rules = [
PatternRule('octal', r'\\[0-7]{3}'),
PatternRule('escaped', r'\\.'),
PatternRule('perl.deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" +
hword + "|" + strg1 + "|" + strg2 + ")}|" +
"(?:->)?\[\$?"+hword+"\]"+ ")+"),
#PatternRule('perl.deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" +
# hword + "|" + strg1 + "|" + strg2 + ")}|" +
# "(?:->)?\[\$?"+hword+"\]"+ ")+"),
PatternRule('perl.length', r"\$#" + word2),
PatternRule('perl.array', r"\$\$*" + word2 + '(?= *\[)'),
PatternRule('perl.hash', r"\$\$*" + word2 + '(?= *\{)'),
PatternRule('perl.scalar', r"\$\$*" + word2),
PatternRule('perl.scalar', r"\$[0-9]+"),
PatternRule('perl.array', r"@\$*" + word2),
PatternRule('perl.hash', r"\%\$*" + word2),
PatternMatchRule('x', r"(\$\$*" + word2 + ')(->)', 'perl.scalar', 'delimiter'),
PatternRule('perl.scalar', r"\$\$*" + word2),
PatternRule('perl.scalar', r"\$\$*" + word2),
#RegionRule('perl.interpolate', r'\[', PerlGrammar, r'\]'),
#RegionRule('perl.interpolate', '{', PerlGrammar, '}'),
]
if forbidden == ')':
rules.append(PatternRule('data', r"\([^$%@\(\)]*\)"))
@ -87,7 +94,7 @@ class StrictStringGrammar(Grammar): rules = [
PatternRule('data', r"[^\\']+"),
]
class StringGrammar(Grammar):
rules = _make_string_rules('"') + [PatternRule('data', r'[^$%@\\"]+')]
rules = _make_string_rules('"') #+ [PatternRule('data', r'[^$%@\\"]+')]
class EvalGrammar(Grammar):
rules = _make_string_rules('`') + [PatternRule('data', r'[^$%@\\`]+')]
@ -111,8 +118,7 @@ class QuotedGrammar2(Grammar): rules = _make_string_rules('}')
class QuotedGrammar3(Grammar): rules = _make_string_rules('>')
class QuotedGrammar4(Grammar): rules = _make_string_rules(']')
class PerlGrammar(Grammar):
rules = [
PerlGrammar.rules = [
RegionRule('perl.heredoc', r"<<(?P<heredoc>" + word1 + ")", None,
r';\n', StringGrammar, r'^%(heredoc)s$'),
RegionRule('perl.heredoc', r'<< *"(?P<heredoc>[^"]+)"', None,
@ -201,13 +207,13 @@ class PerlGrammar(Grammar):
r'\>', WhitespaceGrammar, '\<', MatchGrammar6, r'\>[a-z]*'),
# replace regexes; standard delimiters
RegionRule('perl.replace', 's *(?P<delim>/)', MatchGrammar1,
'/', MatchGrammar1, '/[a-z]*'),
RegionRule('perl.replace', 's(?P<delim>#)',
MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'),
RegionRule('perl.replace', 's *(?P<delim>/)',
MatchGrammar1, '/', MatchGrammar1, '/[a-z]*'),
RegionRule('perl.replace', 's *(?P<delim>[^ a-zA-Z0-9_])',
MatchGrammar0, '%(delim)s',
MatchGrammar0, '%(delim)s[a-z]*'),
RegionRule('perl.replace', 's(?P<delim>#)',
MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'),
# translate operator
RegionRule('perl.translate', '(?:y|tr) *(?P<delim>/)',
@ -731,6 +737,22 @@ class PerlContext(context.Context):
# white is for delimiters, operators, numbers
default = ('default', 'default', 'bold')
# magenta is for keywords/builtins, translation, globs
lo_magenta = ('magenta202', 'default', 'bold')
hi_magenta = ('magenta505', 'default', 'bold')
# red is for comments, pods, endblocks
lo_red = ('red300', 'default', 'bold')
hi_red = ('red511', 'default', 'bold')
# orange are for arrays and hashes
hi_orange = ('yellow531', 'default', 'bold')
lo_orange = ('yellow520', 'default', 'bold')
# yellow is for scalars and prototypes
hi_yellow = ('yellow551', 'default', 'bold')
lo_yellow = ('yellow330', 'default', 'bold')
# green is for strings and hash keys
lo_green = ('green020', 'default', 'bold')
hi_green = ('green050', 'default', 'bold')
@ -739,19 +761,6 @@ hi_green = ('green050', 'default', 'bold')
lo_cyan = ('cyan022', 'default', 'bold')
hi_cyan = ('cyan255', 'default', 'bold')
# magenta is for keywords/builtins, translation, globs
lo_magenta = ('magenta202', 'default', 'bold')
hi_magenta = ('magenta505', 'default', 'bold')
# yellow/orange are for scalars, arrays and hashes
hi_yellow = ('yellow', 'default', 'bold')
lo_yellow = ('yellow530', 'default', 'bold')
lo_orange = ('yellow520', 'default', 'bold')
# red is for comments, pods, endblocks
lo_red = ('red300', 'default', 'bold')
hi_red = ('red500', 'default', 'bold')
# blue is unused
lo_blue = ('blue113', 'default', 'bold')
hi_blue = ('blue225', 'default', 'bold')
@ -770,10 +779,6 @@ class Perl(Fundamental):
colors = {
# comments
'perl.comment': hi_red,
'endblock.start': lo_red,
'endblock.end': hi_red,
'endblock.data': hi_red,
'endblock.null': hi_red,
# pod
'pod.start': hi_red,
@ -786,18 +791,19 @@ class Perl(Fundamental):
'pod.entry.null': hi_magenta,
# basic stuff
'perl.sub': hi_cyan,
'perl.prototype': hi_yellow,
'perl.glob': hi_magenta,
'perl.noperator': hi_magenta,
'perl.keyword': hi_magenta,
'perl.builtin': hi_magenta,
'perl.reserved': hi_magenta,
'perl.prototype': hi_yellow,
'perl.scalar': hi_yellow,
'perl.length': hi_yellow,
'perl.deref': hi_yellow,
'perl.array': lo_yellow,
#'perl.deref': hi_yellow,
'perl.array': hi_orange,
'perl.hash': lo_orange,
'perl.hashkey': hi_green,
'perl.sub': hi_cyan,
'perl.method': hi_cyan,
'perl.function': hi_cyan,
'perl.label': hi_cyan,
@ -805,14 +811,20 @@ class Perl(Fundamental):
'perl.class': hi_cyan,
'perl.use': hi_cyan,
'perl.require': hi_cyan,
'perl.glob': hi_magenta,
# heredoc/evaldoc
# end/data block
'endblock.start': hi_red,
'endblock.end': hi_red,
'endblock.data': hi_red,
'endblock.null': hi_red,
# heredoc
'heredoc.start': lo_green,
'heredoc.end': lo_green,
'heredoc.data': hi_green,
'heredoc.null': hi_green,
# evaldoc
'evaldoc.start': lo_cyan,
'evaldoc.end': lo_cyan,
'evaldoc.data': hi_cyan,
@ -826,24 +838,18 @@ class Perl(Fundamental):
'perl.string.end': lo_green,
'perl.string.data': hi_green,
'perl.string.null': hi_green,
'perl.string.escaped': hi_magenta,
'perl.string.deref': hi_yellow,
# `` strings
'evalstring.start': lo_cyan,
'evalstring.end': lo_cyan,
'evalstring.data': hi_cyan,
'evalstring.null': hi_cyan,
'evalstring.escaped': hi_magenta,
'evalstring.deref': hi_yellow,
# quoted region
'perl.quoted.start': lo_cyan,
'perl.quoted.end': lo_cyan,
'perl.quoted.data': hi_cyan,
'perl.quoted.null': hi_cyan,
'perl.quoted.escaped': hi_magenta,
'perl.quoted.deref': hi_yellow,
# match regex
'match.start': lo_cyan,
@ -858,8 +864,6 @@ class Perl(Fundamental):
'replace.end': lo_cyan,
'replace.data': hi_cyan,
'replace.null': hi_cyan,
'replace.escaped': hi_magenta,
'replace.deref': hi_yellow,
# translate regex
'translate.start': lo_magenta,
@ -870,11 +874,12 @@ class Perl(Fundamental):
}
config = {}
lconfig = {'perl.libs': []}
actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup,
PerldocModule, PerldocWord, Perldoc, PerldocF,
PerlWrapParagraph, PerlInitFunctions, PerlGotoFunction,
PerlWhichFunction, PerlListFunctions, PerlOpenModule,
PerlOpenModuleWord, PerlSemanticComplete]
actions = [
PerlSetLib, PerlCheckSyntax, PerlHashCleanup, PerldocModule,
PerldocWord, Perldoc, PerldocF, PerlWrapParagraph, PerlInitFunctions,
PerlGotoFunction, PerlWhichFunction, PerlListFunctions, PerlOpenModule,
PerlOpenModuleWord, PerlSemanticComplete,
]
completers = {
'perlfunction': PerlFunctionCompleter(None),
}
@ -896,7 +901,6 @@ class Perl(Fundamental):
}
def __init__(self, w):
Fundamental.__init__(self, w)
self.context = PerlContext(self)
self.functions = None
self.funclines = None
@ -930,10 +934,12 @@ class Perl(Fundamental):
self.perlinc = data.split('\n')
return self.perlinc
def get_functions(self): return self.context.get_names()
def get_function_names(self): return self.context.get_name_list()
def get_line_function(self, y): return self.context.get_line_name(y)
def get_functions(self):
return self.context.get_names()
def get_function_names(self):
return self.context.get_name_list()
def get_line_function(self, y):
return self.context.get_line_name(y)
def get_status_names(self):
names = Fundamental.get_status_names(self)
c = self.window.logical_cursor()