Permalink
Browse files

Tighten up the parser by adding expected errors.

- for something like 'echo a(b)'.
- for something like 'do echo hi'

This fixed spec tests in more than one file.
  • Loading branch information...
Andy Chu
Andy Chu committed Sep 8, 2018
1 parent fedbf4c commit 894b8959bfc9b2d023a2c262777b6d50e581ce64
Showing with 17 additions and 10 deletions.
  1. +13 −5 osh/cmd_parse.py
  2. +4 −5 test/spec.sh
View
@@ -249,6 +249,12 @@ def _MakeSimpleCommand(prefix_bindings, suffix_words, redirects):
return node
NOT_FIRST_WORDS = (
Id.KW_Do, Id.KW_Done, Id.KW_Then, Id.KW_Fi, Id.KW_Elif,
Id.KW_Else, Id.KW_Esac
)
class CommandParser(object):
"""
Args:
@@ -1325,6 +1331,9 @@ def ParseCommand(self, cur_aliases=None):
self._Peek()
if self.c_id in NOT_FIRST_WORDS:
p_die('Unexpected word when parsing cmomand', word=self.cur_word)
if self.c_id == Id.KW_Function:
return self.ParseKshFunctionDef()
@@ -1508,8 +1517,9 @@ def _ParseCommandLine(self):
done = True
else:
# Shouldn't happen?
assert False, '_ParseCommandLine: Unexpected word %s' % self.cur_word
# e.g. echo a(b)
p_die('Unexpected word while parsing command line',
word=self.cur_word)
children.append(child)
@@ -1552,9 +1562,7 @@ def _ParseCommandTerm(self):
# Most keywords are valid "first words". But do/done/then do not BEGIN
# commands, so they are not valid.
if self.c_id in (
Id.KW_Do, Id.KW_Done, Id.KW_Then, Id.KW_Fi, Id.KW_Elif, Id.KW_Else,
Id.KW_Esac):
if self.c_id in NOT_FIRST_WORDS:
break
child = self.ParseAndOr()
View
@@ -250,9 +250,8 @@ word-eval() {
${REF_SHELLS[@]} $OSH_LIST "$@"
}
# 'do' -- detected statically as syntax error? hm.
assign() {
sh-spec spec/assign.test.sh --osh-failures-allowed 3 \
sh-spec spec/assign.test.sh --osh-failures-allowed 2 \
${REF_SHELLS[@]} $OSH_LIST "$@"
}
@@ -370,7 +369,7 @@ arith() {
}
command-sub() {
sh-spec spec/command-sub.test.sh --osh-failures-allowed 2 \
sh-spec spec/command-sub.test.sh --osh-failures-allowed 1 \
${REF_SHELLS[@]} $OSH_LIST "$@"
}
@@ -389,7 +388,7 @@ explore-parsing() {
}
parse-errors() {
sh-spec spec/parse-errors.test.sh --osh-failures-allowed 4 \
sh-spec spec/parse-errors.test.sh --osh-failures-allowed 1 \
${REF_SHELLS[@]} $OSH_LIST "$@"
}
@@ -405,7 +404,7 @@ here-doc() {
}
redirect() {
sh-spec spec/redirect.test.sh --osh-failures-allowed 5 \
sh-spec spec/redirect.test.sh --osh-failures-allowed 4 \
${REF_SHELLS[@]} $OSH_LIST "$@"
}

0 comments on commit 894b895

Please sign in to comment.