parent
488d808e22
commit
017f79e888
32
mode/sh.py
32
mode/sh.py
|
@ -7,7 +7,7 @@ class StringGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'escaped', r'\\.'),
|
PatternRule(r'escaped', r'\\.'),
|
||||||
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_]*"),
|
||||||
PatternRule(r'variable', r"\$(?=\()"),
|
PatternRule(r'variable', r"\$(?=\()"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -17,12 +17,20 @@ class EvalGrammar(Grammar):
|
||||||
RegionRule(r'string', '"', StringGrammar, '"'),
|
RegionRule(r'string', '"', StringGrammar, '"'),
|
||||||
PatternRule(r'escaped', r'\\.'),
|
PatternRule(r'escaped', r'\\.'),
|
||||||
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_]*"),
|
||||||
PatternRule(r'variable', r"\$(?=\()"),
|
PatternRule(r'variable', r"\$(?=\()"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
class StanzaGrammar(Grammar):
|
||||||
|
rules = [
|
||||||
|
PatternRule(r'ws', r' +'),
|
||||||
|
PatternRule(r'start_cont', r'.+\\'),
|
||||||
|
]
|
||||||
class CaseGrammar(Grammar):
|
class CaseGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
|
PatternRule(r'comment', r'#.*$'),
|
||||||
|
PatternRule(r'ws', r' +'),
|
||||||
|
RegionRule(r'stanza', r'.+\\', StanzaGrammar, r'.+\)', Grammar, r';;'),
|
||||||
RegionRule(r'stanza', r'.+\)', Grammar, r';;'),
|
RegionRule(r'stanza', r'.+\)', Grammar, r';;'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -38,7 +46,7 @@ class TestGrammar(Grammar):
|
||||||
RegionRule(r'neval', r'\$\(', StringGrammar, r'\)'),
|
RegionRule(r'neval', r'\$\(', StringGrammar, r'\)'),
|
||||||
PatternRule(r'variable', r"(?:^|(?<= ))[a-zA-Z_][a-zA-Z0-9_]*(?==)"),
|
PatternRule(r'variable', r"(?:^|(?<= ))[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_]*"),
|
||||||
PatternRule(r'variable', r"\$(?=\()"),
|
PatternRule(r'variable', r"\$(?=\()"),
|
||||||
RegionRule(r'string', "'", Grammar, "'"),
|
RegionRule(r'string', "'", Grammar, "'"),
|
||||||
RegionRule(r'string', '"', StringGrammar, '"'),
|
RegionRule(r'string', '"', StringGrammar, '"'),
|
||||||
|
@ -47,11 +55,12 @@ class TestGrammar(Grammar):
|
||||||
|
|
||||||
class ShGrammar(Grammar):
|
class ShGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
RegionRule(r'heredoc', r"<<(?P<heredoc>[a-zA-Z][a-zA-Z0-9_]*)", None, "\n", StringGrammar, r'^%(heredoc)s$'),
|
RegionRule(r'heredoc', r"<<<?(?P<heredoc>[a-zA-Z][a-zA-Z0-9_]*)", None, "\n", StringGrammar, r'^%(heredoc)s$'),
|
||||||
|
RegionRule(r'heredoc', r"<<-(?P<heredoc>[a-zA-Z][a-zA-Z0-9_]*)", None, "\n", StringGrammar, r'^ *%(heredoc)s$'),
|
||||||
PatternRule(r'sh_function', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\(\))'),
|
PatternRule(r'sh_function', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\(\))'),
|
||||||
PatternRule(r'sh_reserved', r"(?:done|do|elif|else|esac|fi|for|function|if|in|select|then|until|while|time)(?![a-zA-Z0-9_=/])"),
|
PatternRule(r'sh_reserved', r"(?:done|do|elif|else|esac|fi|for|function|if|in|select|then|until|while|time)(?![a-zA-Z0-9_=/])"),
|
||||||
RegionRule(r'case', r'case', Grammar, 'in', CaseGrammar, r'esac'),
|
RegionRule(r'case', r'case', None, 'in', CaseGrammar, r'esac'),
|
||||||
PatternRule(r'sh_builtin', 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|times|trap|type|ulimit|umask|unalias|unset|wait)(?![a-zA-Z0-9_=/])"),
|
PatternRule(r'sh_builtin', r"(?<![-a-zA-Z0-9_])(?: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|times|trap|type|ulimit|umask|unalias|unset|wait)(?![a-zA-Z0-9_=/])(?![-a-zA-Z0-9_])"),
|
||||||
RegionRule(r'test', r'test', TestGrammar, r'\n'),
|
RegionRule(r'test', r'test', TestGrammar, r'\n'),
|
||||||
RegionRule(r'test2', r'\[', TestGrammar, r'\]'),
|
RegionRule(r'test2', r'\[', TestGrammar, r'\]'),
|
||||||
PatternRule(r'delimiter', r";;|[();{}|&><]"),
|
PatternRule(r'delimiter', r";;|[();{}|&><]"),
|
||||||
|
@ -61,7 +70,7 @@ class ShGrammar(Grammar):
|
||||||
RegionRule(r'neval', r'\$\(', EvalGrammar, r'\)'),
|
RegionRule(r'neval', r'\$\(', EvalGrammar, r'\)'),
|
||||||
PatternRule(r'variable', r"(?:^|(?<= ))[a-zA-Z_][a-zA-Z0-9_]*(?==)"),
|
PatternRule(r'variable', r"(?:^|(?<= ))[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_]*"),
|
||||||
PatternRule(r'variable', r"\$(?=\()"),
|
PatternRule(r'variable', r"\$(?=\()"),
|
||||||
RegionRule(r'string', "'", Grammar, "'"),
|
RegionRule(r'string', "'", Grammar, "'"),
|
||||||
RegionRule(r'string', '"', StringGrammar, '"'),
|
RegionRule(r'string', '"', StringGrammar, '"'),
|
||||||
|
@ -73,8 +82,10 @@ class ShGrammar(Grammar):
|
||||||
]
|
]
|
||||||
|
|
||||||
# hacks to get some circular grammar refs
|
# hacks to get some circular grammar refs
|
||||||
CaseGrammar.rules[0].pairs[0] = (ShGrammar, CaseGrammar.rules[0].pairs[0][1])
|
rule = CaseGrammar.rules[2]
|
||||||
#ShGrammar.rules[2].pairs[0] = (ShGrammar, ShGrammar.rules[0].pairs[0][1])
|
rule.pairs[1] = (ShGrammar, rule.pairs[1][1])
|
||||||
|
rule = CaseGrammar.rules[3]
|
||||||
|
rule.pairs[0] = (ShGrammar, rule.pairs[0][1])
|
||||||
|
|
||||||
class ShTabber(tab.StackTabber):
|
class ShTabber(tab.StackTabber):
|
||||||
def is_base(self, y):
|
def is_base(self, y):
|
||||||
|
@ -125,6 +136,9 @@ class Sh(mode.Fundamental):
|
||||||
|
|
||||||
# case statements
|
# case statements
|
||||||
'case.start': ('magenta', 'default', 'bold'),
|
'case.start': ('magenta', 'default', 'bold'),
|
||||||
|
'case.stanza.start': ('cyan', 'default', 'bold'),
|
||||||
|
'case.stanza.start_cont': ('cyan', 'default', 'bold'),
|
||||||
|
'case.stanza.middle0': ('cyan', 'default', 'bold'),
|
||||||
'case.middle0': ('magenta', 'default', 'bold'),
|
'case.middle0': ('magenta', 'default', 'bold'),
|
||||||
'case.end': ('magenta', 'default', 'bold'),
|
'case.end': ('magenta', 'default', 'bold'),
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue