parent
b39b121a4b
commit
014b931f16
|
@ -7,12 +7,12 @@ import util, window2
|
||||||
from point2 import Point
|
from point2 import Point
|
||||||
|
|
||||||
# modes
|
# modes
|
||||||
# TODO: mode_c mode_nasm mode_sh mode_sql mode_javascript mode_tt
|
# TODO: mode_c mode_nasm mode_sql mode_javascript mode_tt
|
||||||
import mode2
|
import mode2
|
||||||
import mode_mini, mode_search, mode_replace, mode_which
|
import mode_mini, mode_search, mode_replace, mode_which
|
||||||
import mode_console, mode_consolemini
|
import mode_console, mode_consolemini
|
||||||
import mode_blame, mode_diff
|
import mode_blame, mode_diff
|
||||||
import mode_python, mode_perl, mode_xml, mode_nasm
|
import mode_python, mode_perl, mode_xml, mode_nasm, mode_sh
|
||||||
import mode_life, mode_text, mode_mutt
|
import mode_life, mode_text, mode_mutt
|
||||||
|
|
||||||
def run(buffers, jump_to_line=None, init_mode=None):
|
def run(buffers, jump_to_line=None, init_mode=None):
|
||||||
|
@ -93,7 +93,7 @@ class Application(object):
|
||||||
'python': mode_python.Python,
|
'python': mode_python.Python,
|
||||||
'replace': mode_replace.Replace,
|
'replace': mode_replace.Replace,
|
||||||
'search': mode_search.Search,
|
'search': mode_search.Search,
|
||||||
# 'sh': mode_sh.Sh,
|
'sh': mode_sh.Sh,
|
||||||
'text': mode_text.Text,
|
'text': mode_text.Text,
|
||||||
'which': mode_which.Which,
|
'which': mode_which.Which,
|
||||||
'xml': mode_xml.XML,
|
'xml': mode_xml.XML,
|
||||||
|
@ -107,12 +107,12 @@ class Application(object):
|
||||||
# these are used in this order to determine which mode to open certain
|
# these are used in this order to determine which mode to open certain
|
||||||
# kinds of files
|
# kinds of files
|
||||||
self.mode_paths = {
|
self.mode_paths = {
|
||||||
#'/etc/profile': 'sh',
|
'/etc/profile': 'sh',
|
||||||
}
|
}
|
||||||
self.mode_basenames = {
|
self.mode_basenames = {
|
||||||
#'.bashrc': 'sh',
|
'.bashrc': 'sh',
|
||||||
#'.bash_profile': 'sh',
|
'.bash_profile': 'sh',
|
||||||
#'.profile': 'sh',
|
'.profile': 'sh',
|
||||||
}
|
}
|
||||||
self.mode_extensions = {
|
self.mode_extensions = {
|
||||||
'.py': 'python',
|
'.py': 'python',
|
||||||
|
@ -122,8 +122,8 @@ class Application(object):
|
||||||
# '.c': 'c',
|
# '.c': 'c',
|
||||||
'.txt': 'text',
|
'.txt': 'text',
|
||||||
'.s': 'nasm',
|
'.s': 'nasm',
|
||||||
# '.sh': 'sh',
|
'.sh': 'sh',
|
||||||
# '.bash': 'sh',
|
'.bash': 'sh',
|
||||||
'.xml': 'xml',
|
'.xml': 'xml',
|
||||||
'.xml.in': 'xml',
|
'.xml.in': 'xml',
|
||||||
'.html': 'xml',
|
'.html': 'xml',
|
||||||
|
@ -135,8 +135,8 @@ class Application(object):
|
||||||
self.mode_detection = {
|
self.mode_detection = {
|
||||||
'python': 'python',
|
'python': 'python',
|
||||||
'perl': 'perl',
|
'perl': 'perl',
|
||||||
# 'sh': 'sh',
|
'sh': 'sh',
|
||||||
# 'bash': 'sh',
|
'bash': 'sh',
|
||||||
}
|
}
|
||||||
|
|
||||||
# initialize our methods
|
# initialize our methods
|
||||||
|
|
7
lex2.py
7
lex2.py
|
@ -130,11 +130,6 @@ class RegionRule(Rule):
|
||||||
self.end = end
|
self.end = end
|
||||||
self.start_re = re.compile(start)
|
self.start_re = re.compile(start)
|
||||||
|
|
||||||
for rule in self.grammar.rules:
|
|
||||||
if not hasattr(rule, 'match'):
|
|
||||||
print 'DAMN %r' % name
|
|
||||||
raise Exception, repr(rule)
|
|
||||||
|
|
||||||
def resume(self, lexer, toresume):
|
def resume(self, lexer, toresume):
|
||||||
#raise Exception, "%r %r" % (lexer, toresume) #XYZ
|
#raise Exception, "%r %r" % (lexer, toresume) #XYZ
|
||||||
assert toresume, "can't resume without tokens to resume!"
|
assert toresume, "can't resume without tokens to resume!"
|
||||||
|
@ -464,8 +459,6 @@ class Grammar:
|
||||||
rules = []
|
rules = []
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
for rule in self.rules:
|
for rule in self.rules:
|
||||||
if type(rule) in (type(tuple()), type(list())):
|
|
||||||
print self.rules
|
|
||||||
if hasattr(rule, 'grammar') and rule.grammar is None:
|
if hasattr(rule, 'grammar') and rule.grammar is None:
|
||||||
rule.grammar = self
|
rule.grammar = self
|
||||||
|
|
||||||
|
|
81
mode_sh.py
81
mode_sh.py
|
@ -1,36 +1,59 @@
|
||||||
import commands, os.path, sets, sys
|
import color, mode2
|
||||||
|
from lex2 import Grammar, PatternRule, RegionRule
|
||||||
|
|
||||||
import color, default, mode, lex, lex_sh, method, tab_sh
|
class StringGrammar(Grammar):
|
||||||
|
rules = [
|
||||||
|
PatternRule(name=r'escaped', pattern=r'\\.'),
|
||||||
|
PatternRule(name=r'variable', pattern=r"(?:^|(?<= ))[a-zA-Z_][a-zA-Z_][a-zA-Z0-9_]*(?==)"),
|
||||||
|
PatternRule(name=r'variable', pattern=r"\${(?:[a-zA-Z0-9_]+|\?\$)}"),
|
||||||
|
PatternRule(name=r"variable", pattern=r"\$[^({][a-zA-Z0-9_]*"),
|
||||||
|
PatternRule(name=r'variable', pattern=r"\$(?=\()"),
|
||||||
|
]
|
||||||
|
|
||||||
class Sh(mode.Fundamental):
|
class ShGrammar(Grammar):
|
||||||
|
rules = [
|
||||||
|
PatternRule(name=r'function', pattern=r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\(\))'),
|
||||||
|
PatternRule(name=r'reserved', pattern=r"(?:case|done|do|elif|else|esac|fi|for|function|if|in|select|then|until|while|time)(?![a-zA-Z0-9_=/])"),
|
||||||
|
PatternRule(name=r'builtin', pattern=r"(?:source|alias|bg|bind|break|builtin|cd|command|compgen|complete|declare|dirs|disown|echo|enable|eval|exec|exit|export|fc|fg|getops|hash|help|history|jobs|kill|let|local|logout|popd|printf|pushd|pwd|readonly|read|return|set|shift|shopt|suspend|test|times|trap|type|ulimit|umask|unalias|unset|wait)(?![a-zA-Z0-9_=/])"),
|
||||||
|
PatternRule(name=r'operator', pattern=r"(?:-eq|-ne|-gt|-lt|-ge|-le| = | != )"),
|
||||||
|
PatternRule(name=r'delimiter', pattern=r"[][\(\);\{\}|&><]"),
|
||||||
|
RegionRule(name=r'eval2', start=r'\$\(', grammar=None, end=r'\)'),
|
||||||
|
PatternRule(name=r'variable', pattern=r"(?:^|(?<= ))[a-zA-Z_][a-zA-Z_][a-zA-Z0-9_]*(?==)"),
|
||||||
|
PatternRule(name=r'variable', pattern=r"\${(?:[a-zA-Z0-9_]+|\?\$)}"),
|
||||||
|
PatternRule(name=r"variable", pattern=r"\$[^({][a-zA-Z0-9_]*"),
|
||||||
|
PatternRule(name=r'variable', pattern=r"\$(?=\()"),
|
||||||
|
RegionRule(name=r'eval', start='`', grammar=StringGrammar(), end='`'),
|
||||||
|
RegionRule(name=r'string', start="'", grammar=Grammar(), end="'"),
|
||||||
|
RegionRule(name=r'string', start='"', grammar=StringGrammar(), end='"'),
|
||||||
|
PatternRule(name=r'continuation', pattern=r'\\(?= *$)'),
|
||||||
|
PatternRule(name=r'comment', pattern=r'#.*$'),
|
||||||
|
PatternRule(name=r'bareword', pattern=r'[a-zA-Z0-9_-]+'),
|
||||||
|
]
|
||||||
|
|
||||||
|
class Sh(mode2.Fundamental):
|
||||||
|
grammar = ShGrammar()
|
||||||
def __init__(self, w):
|
def __init__(self, w):
|
||||||
mode.Fundamental.__init__(self, w)
|
mode2.Fundamental.__init__(self, w)
|
||||||
|
|
||||||
self.grammar = lex_sh.ShGrammar()
|
|
||||||
self.lexer = lex.Lexer(self.grammar)
|
|
||||||
|
|
||||||
self.colors = {
|
self.colors = {
|
||||||
'builtin': color.build('cyan', 'default', 'bold'),
|
'builtin': color.build('cyan', 'default', 'bold'),
|
||||||
'method': color.build('magenta', 'default', 'bold'),
|
'function': color.build('magenta', 'default', 'bold'),
|
||||||
'reserved': color.build('magenta', 'default', 'bold'),
|
'reserved': color.build('magenta', 'default', 'bold'),
|
||||||
#'delimiter': color.build('magenta', 'default', 'bold'),
|
'variable': color.build('yellow', 'default', 'bold'),
|
||||||
'delimiter': color.build('default', 'default', 'bold'),
|
'delimiter': color.build('default', 'default', 'bold'),
|
||||||
'operator': color.build('magenta', 'default', 'bold'),
|
'operator': color.build('magenta', 'default', 'bold'),
|
||||||
'redirection': color.build('blue', 'default', 'bold'),
|
'redirection': color.build('blue', 'default', 'bold'),
|
||||||
'string1': color.build('green', 'default'),
|
'string.start': color.build('green', 'default'),
|
||||||
'string2': color.build('green', 'default'),
|
'string.variable': color.build('yellow', 'default'),
|
||||||
'eval': color.build('cyan', 'default', 'bold'),
|
'string.null': color.build('green', 'default'),
|
||||||
'comment': color.build('red', 'default'),
|
'string.end': color.build('green', 'default'),
|
||||||
'continuation': color.build('red', 'default'),
|
'eval.start': color.build('cyan', 'default'),
|
||||||
'variable0': color.build('yellow', 'default', 'bold'),
|
'eval.variable': color.build('yellow', 'default'),
|
||||||
'variable1': color.build('yellow', 'default', 'bold'),
|
'eval.null': color.build('cyan', 'default'),
|
||||||
'variable2': color.build('yellow', 'default', 'bold'),
|
'eval.end': color.build('cyan', 'default'),
|
||||||
'variable3': color.build('yellow', 'default', 'bold'),
|
'eval2.start': color.build('cyan', 'default'),
|
||||||
|
'eval2.end': color.build('cyan', 'default'),
|
||||||
|
'comment': color.build('red', 'default'),
|
||||||
|
'continuation': color.build('red', 'default'),
|
||||||
}
|
}
|
||||||
|
|
||||||
#self.highlighter.lex_buffer()
|
|
||||||
#self.get_regions()
|
|
||||||
self.tabber = tab_sh.ShTabber(self)
|
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return "Sh"
|
return "Sh"
|
||||||
|
|
Loading…
Reference in New Issue