improved perl grammar and some clean up
--HG-- branch : pmacs2
This commit is contained in:
parent
e3b2818038
commit
34f81cdb0d
|
@ -214,13 +214,12 @@ class Application(object):
|
||||||
|
|
||||||
def _load_config_defaults(self):
|
def _load_config_defaults(self):
|
||||||
self.config['ignore_suffix'] = ['~', '-', 'CVS', '.svn', '.git', '.hg']
|
self.config['ignore_suffix'] = ['~', '-', 'CVS', '.svn', '.git', '.hg']
|
||||||
|
|
||||||
self.config['error_timeout'] = -1
|
self.config['error_timeout'] = -1
|
||||||
self.config['max_error_len'] = 192
|
self.config['max_error_len'] = 192
|
||||||
self.config['max_num_kills'] = 64
|
self.config['max_num_kills'] = 64
|
||||||
self.config['word_letters'] = string.ascii_letters + string.digits
|
self.config['word_letters'] = string.ascii_letters + string.digits
|
||||||
self.config['default_color'] = ('default', 'default',)
|
self.config['default_color'] = ('default', 'default',)
|
||||||
self.config['margin'] = 80
|
self.config['margin'] = 79
|
||||||
self.config['margin_color'] = 'blue'
|
self.config['margin_color'] = 'blue'
|
||||||
self.config['use_last_replace'] = False
|
self.config['use_last_replace'] = False
|
||||||
|
|
||||||
|
|
112
mode/perl.py
112
mode/perl.py
|
@ -16,6 +16,8 @@ from tab import StackTabber, StackTabber2
|
||||||
from parse import Any, And, Or, Optional, Name, Match, Matchs
|
from parse import Any, And, Or, Optional, Name, Match, Matchs
|
||||||
import term
|
import term
|
||||||
|
|
||||||
|
class PerlGrammar(Grammar): pass
|
||||||
|
|
||||||
class WhitespaceGrammar(Grammar):
|
class WhitespaceGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule('spaces', ' +'),
|
PatternRule('spaces', ' +'),
|
||||||
|
@ -49,16 +51,21 @@ def _make_string_rules(forbidden):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule('octal', r'\\[0-7]{3}'),
|
PatternRule('octal', r'\\[0-7]{3}'),
|
||||||
PatternRule('escaped', r'\\.'),
|
PatternRule('escaped', r'\\.'),
|
||||||
PatternRule('perl.deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" +
|
#PatternRule('perl.deref', r"\$+" + word2 + "(?:" + "(?:->)?{\$?(?:" +
|
||||||
hword + "|" + strg1 + "|" + strg2 + ")}|" +
|
# hword + "|" + strg1 + "|" + strg2 + ")}|" +
|
||||||
"(?:->)?\[\$?"+hword+"\]"+ ")+"),
|
# "(?:->)?\[\$?"+hword+"\]"+ ")+"),
|
||||||
PatternRule('perl.length', r"\$#" + word2),
|
PatternRule('perl.length', r"\$#" + word2),
|
||||||
PatternRule('perl.array', r"\$\$*" + word2 + '(?= *\[)'),
|
PatternRule('perl.array', r"\$\$*" + word2 + '(?= *\[)'),
|
||||||
PatternRule('perl.hash', r"\$\$*" + word2 + '(?= *\{)'),
|
PatternRule('perl.hash', r"\$\$*" + word2 + '(?= *\{)'),
|
||||||
PatternRule('perl.scalar', r"\$\$*" + word2),
|
|
||||||
PatternRule('perl.scalar', r"\$[0-9]+"),
|
PatternRule('perl.scalar', r"\$[0-9]+"),
|
||||||
PatternRule('perl.array', r"@\$*" + word2),
|
PatternRule('perl.array', r"@\$*" + word2),
|
||||||
PatternRule('perl.hash', 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 == ')':
|
if forbidden == ')':
|
||||||
rules.append(PatternRule('data', r"\([^$%@\(\)]*\)"))
|
rules.append(PatternRule('data', r"\([^$%@\(\)]*\)"))
|
||||||
|
@ -87,7 +94,7 @@ class StrictStringGrammar(Grammar): rules = [
|
||||||
PatternRule('data', r"[^\\']+"),
|
PatternRule('data', r"[^\\']+"),
|
||||||
]
|
]
|
||||||
class StringGrammar(Grammar):
|
class StringGrammar(Grammar):
|
||||||
rules = _make_string_rules('"') + [PatternRule('data', r'[^$%@\\"]+')]
|
rules = _make_string_rules('"') #+ [PatternRule('data', r'[^$%@\\"]+')]
|
||||||
class EvalGrammar(Grammar):
|
class EvalGrammar(Grammar):
|
||||||
rules = _make_string_rules('`') + [PatternRule('data', r'[^$%@\\`]+')]
|
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 QuotedGrammar3(Grammar): rules = _make_string_rules('>')
|
||||||
class QuotedGrammar4(Grammar): rules = _make_string_rules(']')
|
class QuotedGrammar4(Grammar): rules = _make_string_rules(']')
|
||||||
|
|
||||||
class PerlGrammar(Grammar):
|
PerlGrammar.rules = [
|
||||||
rules = [
|
|
||||||
RegionRule('perl.heredoc', r"<<(?P<heredoc>" + word1 + ")", None,
|
RegionRule('perl.heredoc', r"<<(?P<heredoc>" + word1 + ")", None,
|
||||||
r';\n', StringGrammar, r'^%(heredoc)s$'),
|
r';\n', StringGrammar, r'^%(heredoc)s$'),
|
||||||
RegionRule('perl.heredoc', r'<< *"(?P<heredoc>[^"]+)"', None,
|
RegionRule('perl.heredoc', r'<< *"(?P<heredoc>[^"]+)"', None,
|
||||||
|
@ -201,13 +207,13 @@ class PerlGrammar(Grammar):
|
||||||
r'\>', WhitespaceGrammar, '\<', MatchGrammar6, r'\>[a-z]*'),
|
r'\>', WhitespaceGrammar, '\<', MatchGrammar6, r'\>[a-z]*'),
|
||||||
|
|
||||||
# replace regexes; standard delimiters
|
# replace regexes; standard delimiters
|
||||||
RegionRule('perl.replace', 's *(?P<delim>/)', MatchGrammar1,
|
RegionRule('perl.replace', 's(?P<delim>#)',
|
||||||
'/', MatchGrammar1, '/[a-z]*'),
|
MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'),
|
||||||
|
RegionRule('perl.replace', 's *(?P<delim>/)',
|
||||||
|
MatchGrammar1, '/', MatchGrammar1, '/[a-z]*'),
|
||||||
RegionRule('perl.replace', 's *(?P<delim>[^ a-zA-Z0-9_])',
|
RegionRule('perl.replace', 's *(?P<delim>[^ a-zA-Z0-9_])',
|
||||||
MatchGrammar0, '%(delim)s',
|
MatchGrammar0, '%(delim)s',
|
||||||
MatchGrammar0, '%(delim)s[a-z]*'),
|
MatchGrammar0, '%(delim)s[a-z]*'),
|
||||||
RegionRule('perl.replace', 's(?P<delim>#)',
|
|
||||||
MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'),
|
|
||||||
|
|
||||||
# translate operator
|
# translate operator
|
||||||
RegionRule('perl.translate', '(?:y|tr) *(?P<delim>/)',
|
RegionRule('perl.translate', '(?:y|tr) *(?P<delim>/)',
|
||||||
|
@ -263,7 +269,7 @@ class PerlGrammar(Grammar):
|
||||||
|
|
||||||
PatternRule('spaces', ' +'),
|
PatternRule('spaces', ' +'),
|
||||||
PatternRule('eol', r"\n$"),
|
PatternRule('eol', r"\n$"),
|
||||||
]
|
]
|
||||||
|
|
||||||
class PerlTabber(StackTabber2):
|
class PerlTabber(StackTabber2):
|
||||||
is_ignored_tokens = ('spaces', 'eol', 'perl.comment')
|
is_ignored_tokens = ('spaces', 'eol', 'perl.comment')
|
||||||
|
@ -731,6 +737,22 @@ class PerlContext(context.Context):
|
||||||
# white is for delimiters, operators, numbers
|
# white is for delimiters, operators, numbers
|
||||||
default = ('default', 'default', 'bold')
|
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
|
# green is for strings and hash keys
|
||||||
lo_green = ('green020', 'default', 'bold')
|
lo_green = ('green020', 'default', 'bold')
|
||||||
hi_green = ('green050', 'default', 'bold')
|
hi_green = ('green050', 'default', 'bold')
|
||||||
|
@ -739,19 +761,6 @@ hi_green = ('green050', 'default', 'bold')
|
||||||
lo_cyan = ('cyan022', 'default', 'bold')
|
lo_cyan = ('cyan022', 'default', 'bold')
|
||||||
hi_cyan = ('cyan255', '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
|
# blue is unused
|
||||||
lo_blue = ('blue113', 'default', 'bold')
|
lo_blue = ('blue113', 'default', 'bold')
|
||||||
hi_blue = ('blue225', 'default', 'bold')
|
hi_blue = ('blue225', 'default', 'bold')
|
||||||
|
@ -770,10 +779,6 @@ class Perl(Fundamental):
|
||||||
colors = {
|
colors = {
|
||||||
# comments
|
# comments
|
||||||
'perl.comment': hi_red,
|
'perl.comment': hi_red,
|
||||||
'endblock.start': lo_red,
|
|
||||||
'endblock.end': hi_red,
|
|
||||||
'endblock.data': hi_red,
|
|
||||||
'endblock.null': hi_red,
|
|
||||||
|
|
||||||
# pod
|
# pod
|
||||||
'pod.start': hi_red,
|
'pod.start': hi_red,
|
||||||
|
@ -786,18 +791,19 @@ class Perl(Fundamental):
|
||||||
'pod.entry.null': hi_magenta,
|
'pod.entry.null': hi_magenta,
|
||||||
|
|
||||||
# basic stuff
|
# basic stuff
|
||||||
'perl.sub': hi_cyan,
|
'perl.glob': hi_magenta,
|
||||||
'perl.prototype': hi_yellow,
|
|
||||||
'perl.noperator': hi_magenta,
|
'perl.noperator': hi_magenta,
|
||||||
'perl.keyword': hi_magenta,
|
'perl.keyword': hi_magenta,
|
||||||
'perl.builtin': hi_magenta,
|
'perl.builtin': hi_magenta,
|
||||||
'perl.reserved': hi_magenta,
|
'perl.reserved': hi_magenta,
|
||||||
|
'perl.prototype': hi_yellow,
|
||||||
'perl.scalar': hi_yellow,
|
'perl.scalar': hi_yellow,
|
||||||
'perl.length': hi_yellow,
|
'perl.length': hi_yellow,
|
||||||
'perl.deref': hi_yellow,
|
#'perl.deref': hi_yellow,
|
||||||
'perl.array': lo_yellow,
|
'perl.array': hi_orange,
|
||||||
'perl.hash': lo_orange,
|
'perl.hash': lo_orange,
|
||||||
'perl.hashkey': hi_green,
|
'perl.hashkey': hi_green,
|
||||||
|
'perl.sub': hi_cyan,
|
||||||
'perl.method': hi_cyan,
|
'perl.method': hi_cyan,
|
||||||
'perl.function': hi_cyan,
|
'perl.function': hi_cyan,
|
||||||
'perl.label': hi_cyan,
|
'perl.label': hi_cyan,
|
||||||
|
@ -805,14 +811,20 @@ class Perl(Fundamental):
|
||||||
'perl.class': hi_cyan,
|
'perl.class': hi_cyan,
|
||||||
'perl.use': hi_cyan,
|
'perl.use': hi_cyan,
|
||||||
'perl.require': 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.start': lo_green,
|
||||||
'heredoc.end': lo_green,
|
'heredoc.end': lo_green,
|
||||||
'heredoc.data': hi_green,
|
'heredoc.data': hi_green,
|
||||||
'heredoc.null': hi_green,
|
'heredoc.null': hi_green,
|
||||||
|
|
||||||
|
# evaldoc
|
||||||
'evaldoc.start': lo_cyan,
|
'evaldoc.start': lo_cyan,
|
||||||
'evaldoc.end': lo_cyan,
|
'evaldoc.end': lo_cyan,
|
||||||
'evaldoc.data': hi_cyan,
|
'evaldoc.data': hi_cyan,
|
||||||
|
@ -826,24 +838,18 @@ class Perl(Fundamental):
|
||||||
'perl.string.end': lo_green,
|
'perl.string.end': lo_green,
|
||||||
'perl.string.data': hi_green,
|
'perl.string.data': hi_green,
|
||||||
'perl.string.null': hi_green,
|
'perl.string.null': hi_green,
|
||||||
'perl.string.escaped': hi_magenta,
|
|
||||||
'perl.string.deref': hi_yellow,
|
|
||||||
|
|
||||||
# `` strings
|
# `` strings
|
||||||
'evalstring.start': lo_cyan,
|
'evalstring.start': lo_cyan,
|
||||||
'evalstring.end': lo_cyan,
|
'evalstring.end': lo_cyan,
|
||||||
'evalstring.data': hi_cyan,
|
'evalstring.data': hi_cyan,
|
||||||
'evalstring.null': hi_cyan,
|
'evalstring.null': hi_cyan,
|
||||||
'evalstring.escaped': hi_magenta,
|
|
||||||
'evalstring.deref': hi_yellow,
|
|
||||||
|
|
||||||
# quoted region
|
# quoted region
|
||||||
'perl.quoted.start': lo_cyan,
|
'perl.quoted.start': lo_cyan,
|
||||||
'perl.quoted.end': lo_cyan,
|
'perl.quoted.end': lo_cyan,
|
||||||
'perl.quoted.data': hi_cyan,
|
'perl.quoted.data': hi_cyan,
|
||||||
'perl.quoted.null': hi_cyan,
|
'perl.quoted.null': hi_cyan,
|
||||||
'perl.quoted.escaped': hi_magenta,
|
|
||||||
'perl.quoted.deref': hi_yellow,
|
|
||||||
|
|
||||||
# match regex
|
# match regex
|
||||||
'match.start': lo_cyan,
|
'match.start': lo_cyan,
|
||||||
|
@ -858,8 +864,6 @@ class Perl(Fundamental):
|
||||||
'replace.end': lo_cyan,
|
'replace.end': lo_cyan,
|
||||||
'replace.data': hi_cyan,
|
'replace.data': hi_cyan,
|
||||||
'replace.null': hi_cyan,
|
'replace.null': hi_cyan,
|
||||||
'replace.escaped': hi_magenta,
|
|
||||||
'replace.deref': hi_yellow,
|
|
||||||
|
|
||||||
# translate regex
|
# translate regex
|
||||||
'translate.start': lo_magenta,
|
'translate.start': lo_magenta,
|
||||||
|
@ -870,11 +874,12 @@ class Perl(Fundamental):
|
||||||
}
|
}
|
||||||
config = {}
|
config = {}
|
||||||
lconfig = {'perl.libs': []}
|
lconfig = {'perl.libs': []}
|
||||||
actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup,
|
actions = [
|
||||||
PerldocModule, PerldocWord, Perldoc, PerldocF,
|
PerlSetLib, PerlCheckSyntax, PerlHashCleanup, PerldocModule,
|
||||||
PerlWrapParagraph, PerlInitFunctions, PerlGotoFunction,
|
PerldocWord, Perldoc, PerldocF, PerlWrapParagraph, PerlInitFunctions,
|
||||||
PerlWhichFunction, PerlListFunctions, PerlOpenModule,
|
PerlGotoFunction, PerlWhichFunction, PerlListFunctions, PerlOpenModule,
|
||||||
PerlOpenModuleWord, PerlSemanticComplete]
|
PerlOpenModuleWord, PerlSemanticComplete,
|
||||||
|
]
|
||||||
completers = {
|
completers = {
|
||||||
'perlfunction': PerlFunctionCompleter(None),
|
'perlfunction': PerlFunctionCompleter(None),
|
||||||
}
|
}
|
||||||
|
@ -896,7 +901,6 @@ class Perl(Fundamental):
|
||||||
}
|
}
|
||||||
def __init__(self, w):
|
def __init__(self, w):
|
||||||
Fundamental.__init__(self, w)
|
Fundamental.__init__(self, w)
|
||||||
|
|
||||||
self.context = PerlContext(self)
|
self.context = PerlContext(self)
|
||||||
self.functions = None
|
self.functions = None
|
||||||
self.funclines = None
|
self.funclines = None
|
||||||
|
@ -930,10 +934,12 @@ class Perl(Fundamental):
|
||||||
self.perlinc = data.split('\n')
|
self.perlinc = data.split('\n')
|
||||||
return self.perlinc
|
return self.perlinc
|
||||||
|
|
||||||
def get_functions(self): return self.context.get_names()
|
def get_functions(self):
|
||||||
def get_function_names(self): return self.context.get_name_list()
|
return self.context.get_names()
|
||||||
def get_line_function(self, y): return self.context.get_line_name(y)
|
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):
|
def get_status_names(self):
|
||||||
names = Fundamental.get_status_names(self)
|
names = Fundamental.get_status_names(self)
|
||||||
c = self.window.logical_cursor()
|
c = self.window.logical_cursor()
|
||||||
|
|
Loading…
Reference in New Issue