Skip to content

Commit

Permalink
syntax: properly tokenize ) after a test regexp
Browse files Browse the repository at this point in the history
We weren't consuming its rune, which could lead to us seeing duplicate
"right parenthesis" tokens. In the added test case, this resulted in an
incorrect syntax error.

Fixes #470.
  • Loading branch information
mvdan committed Jan 3, 2020
1 parent 23f86c8 commit c11932a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions syntax/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ skipSpace:
} else {
p.tok = rightParen
p.quote = noState
p.rune() // we are tokenizing manually
}
default: // including '(', '|'
p.advanceLitRe(r)
Expand Down
1 change: 1 addition & 0 deletions syntax/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ var printTests = []printCase{
samePrint("case a in b) [[ x =~ y ]] ;; esac"),
samePrint("case a in b) [[ a =~ b$ || c =~ d$ ]] ;; esac"),
samePrint("case a in b) [[ a =~ (b) ]] ;; esac"),
samePrint("[[ (a =~ b$) ]]"),
{
"a=(\nb\nc\n) b=c",
"a=(\n\tb\n\tc\n) b=c",
Expand Down

0 comments on commit c11932a

Please sign in to comment.