Skip to content

Commit

Permalink
[oil-language] Better error message when there's a trailing comma.
Browse files Browse the repository at this point in the history
Although honestly I feel like I want the trailing comma?  It's harder to
parse, but more familiar to Python and Go programmers.

Have to think about it.

Related to #1135.
  • Loading branch information
Andy C committed May 22, 2022
1 parent 43b9b5b commit 4bc02d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion osh/cmd_parse.py
Expand Up @@ -1178,7 +1178,10 @@ def _ParseForEachLoop(self, for_spid):
if not ok or quoted: # error: for $x
p_die('Expected loop variable (a constant word)', word=self.cur_word)
if not match.IsValidVarName(iter_name): # error: for -
p_die("Invalid loop variable name", word=self.cur_word)
# TODO: consider commas?
if iter_name.endswith(','):
p_die('Remove comma; loop variables are separated by spaces', word=self.cur_word)
p_die('Invalid loop variable name %r', iter_name, word=self.cur_word)

node.iter_names.append(iter_name)
num_iter_names += 1
Expand Down
14 changes: 14 additions & 0 deletions test/parse-errors.sh
Expand Up @@ -1164,6 +1164,20 @@ oil_for() {
done
'

# NO COMMA!
_oil-parse-error '
for x, y in SPAM EGGS; do
echo $x
done
'

# Bad loop variable name
_oil-parse-error '
for x-y in SPAM EGGS; do
echo $x
done
'

_oil-parse-error '
for x y z in SPAM EGGS; do
echo $x
Expand Down

0 comments on commit 4bc02d4

Please sign in to comment.