parent
59acc62072
commit
5e5e9b87c2
16
mode/sh.py
16
mode/sh.py
|
@ -30,17 +30,20 @@ class CaseGrammar(Grammar):
|
|||
rules = [
|
||||
PatternRule(r'comment', r'#.*$'),
|
||||
PatternRule(r'ws', r' +'),
|
||||
RegionRule(r'stanza', r'.+\\', StanzaGrammar, r'.+\)', Grammar, r';;'),
|
||||
RegionRule(r'stanza', r'.+\\\n$', StanzaGrammar, r'.+\)', Grammar, r';;'),
|
||||
RegionRule(r'stanza', r'.+\)', Grammar, r';;'),
|
||||
]
|
||||
|
||||
class TestGrammar(Grammar):
|
||||
rules = [
|
||||
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|test|times|trap|type|ulimit|umask|unalias|unset|wait)(?![a-zA-Z0-9_=/])"),
|
||||
PatternRule(r'binop', r'==|=|!=|<|>'),
|
||||
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|test|times|trap|type|ulimit|umask|unalias|unset|wait)(?![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'binop', r'==|=|!=|<|>'),
|
||||
PatternRule(r'binop', r'==|=|!='),
|
||||
PatternRule(r'binop', r'-(?:nt|ot|ef|eq|ne|lt|gt|le|ge)(?![a-zA-Z0-9_])'),
|
||||
PatternRule(r'unop', r'-[a-zA-Z](?![a-zA-Z0-9_])'),
|
||||
PatternRule(r'continuation', r'\\\n$'),
|
||||
PatternRule(r'redirect', r'<|>'),
|
||||
PatternRule(r'delimiter', r";;|[();{}|&><]"),
|
||||
RegionRule(r'eval', r'`', StringGrammar, r'`'),
|
||||
RegionRule(r'neval', r'\$\(', StringGrammar, r'\)'),
|
||||
|
@ -55,14 +58,15 @@ class TestGrammar(Grammar):
|
|||
|
||||
class ShGrammar(Grammar):
|
||||
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$'),
|
||||
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_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', None, 'in', CaseGrammar, r'esac'),
|
||||
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'\]'),
|
||||
PatternRule(r'redirect', r'<|>'),
|
||||
PatternRule(r'delimiter', r";;|[();{}|&><]"),
|
||||
RegionRule(r'eval', r'`', EvalGrammar, r'`'),
|
||||
RegionRule(r'neval', r'\$\(', EvalGrammar, r'\)'),
|
||||
|
|
Loading…
Reference in New Issue