more sh improvements

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-09-24 18:42:26 +00:00
parent 11b0b69bd9
commit faf00c2db6
3 changed files with 26 additions and 6 deletions

View File

@ -10,6 +10,12 @@
#
# by Erik Osheim
case $FOO in
a) blarg;;
b) blarg;;
*) flarg;;
esac
# Print usage
helpusage() {
echo "usage: wfault [-halbtu]"

View File

@ -11,6 +11,11 @@ class StringGrammar(Grammar):
PatternRule(r'variable', r"\$(?=\()"),
]
class CaseGrammar(Grammar):
rules = [
RegionRule(r'stanza', r'.+\)', Grammar, r';;'),
]
class TestGrammar(Grammar):
rules = [
PatternRule(r'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_=/])"),
@ -33,7 +38,9 @@ class TestGrammar(Grammar):
class ShGrammar(Grammar):
rules = [
PatternRule(r'function', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\(\))'),
PatternRule(r'reserved', r"(?:case|done|do|elif|else|esac|fi|for|function|if|in|select|then|until|while|time)(?![a-zA-Z0-9_=/])"),
#PatternRule(r'reserved', r"(?:case|done|do|elif|else|esac|fi|for|function|if|in|select|then|until|while|time)(?![a-zA-Z0-9_=/])"),
PatternRule(r'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'),
#PatternRule(r'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'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'operator', r"(?:-eq|-ne|-gt|-lt|-ge|-le| = | != )(?![a-zA-Z0-9_])"),
@ -86,10 +93,11 @@ class ShTabber(tab2.StackTabber):
class Sh(mode2.Fundamental):
grammar = ShGrammar
tabbercls = ShTabber
opentokens = ('delimiter', 'reserved',)
opentokens = ('delimiter', 'reserved', 'case.start')
#opentokens = ('delimiter', 'reserved', 'start')
opentags = {'(': ')', '[': ']', '{': '}',
'do': 'done', 'then': 'fi', 'case': 'esac'}
closetokens = ('delimiter', 'reserved',)
closetokens = ('delimiter', 'reserved', 'case.end')
closetags = {')': '(', ']': '[', '}': '{',
'done': 'do', 'fi': 'then', 'esac': 'case'}
colors = {
@ -98,6 +106,11 @@ class Sh(mode2.Fundamental):
'reserved': ('magenta', 'default', 'bold'),
'variable': ('yellow', 'default', 'bold'),
# case statements
'case.start': ('magenta', 'default', 'bold'),
'case.middle0': ('magenta', 'default', 'bold'),
'case.end': ('magenta', 'default', 'bold'),
'delimiter': ('default', 'default', 'bold'),
'test.start': ('cyan', 'default', 'bold'),
'binop': ('magenta', 'default', 'bold'),

View File

@ -29,7 +29,7 @@ class Tabber:
return token.fqname() in self.wst and self.wsre.match(token.string)
def token_is_space(self, y, i):
token = self.get_token(y, i)
return token.name in self.st and self.sre.match(token.string)
return token.fqname() in self.st and self.sre.match(token.string)
def get_next_left_token(self, y, i):
tokens = self.get_tokens(y)
@ -141,10 +141,11 @@ class StackTabber(Tabber):
def _handle_token(self, currlvl, y, i):
token = self.get_token(y, i)
s = token.string
fqname = token.fqname()
if token.name in self.mode.closetokens and s in self.mode.closetags:
if fqname in self.mode.closetokens and s in self.mode.closetags:
currlvl = self._handle_close_token(currlvl, y, i)
elif token.name in self.mode.opentokens and s in self.mode.opentags:
elif fqname in self.mode.opentokens and s in self.mode.opentags:
currlvl = self._handle_open_token(currlvl, y, i)
else:
currlvl = self._handle_other_token(currlvl, y, i)