diff --git a/mode/sh.py b/mode/sh.py index 781fb35..6be7b5b 100644 --- a/mode/sh.py +++ b/mode/sh.py @@ -11,6 +11,16 @@ class StringGrammar(Grammar): PatternRule(r'variable', r"\$(?=\()"), ] +class EvalGrammar(Grammar): + rules = [ + RegionRule(r'string', "'", Grammar, "'"), + RegionRule(r'string', '"', StringGrammar, '"'), + PatternRule(r'escaped', r'\\.'), + PatternRule(r'variable', r"\${(?:[a-zA-Z0-9_]+|\?\$)}"), + PatternRule(r"variable", r"\$[^({][a-zA-Z0-9_]*"), + PatternRule(r'variable', r"\$(?=\()"), + ] + class CaseGrammar(Grammar): rules = [ RegionRule(r'stanza', r'.+\)', Grammar, r';;'), @@ -44,8 +54,10 @@ class ShGrammar(Grammar): RegionRule(r'test', r'test', TestGrammar, r'\n'), RegionRule(r'test2', r'\[', TestGrammar, r'\]'), PatternRule(r'delimiter', r";;|[();{}|&><]"), - RegionRule(r'eval', r'`', StringGrammar, r'`'), - RegionRule(r'neval', r'\$\(', StringGrammar, r'\)'), + #RegionRule(r'eval', r'`', StringGrammar, r'`'), + #RegionRule(r'neval', r'\$\(', StringGrammar, r'\)'), + RegionRule(r'eval', 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-Z0-9_]+|\?\$)}"), PatternRule(r"variable", r"\$[^({][a-zA-Z0-9_]*"),