Repository: benhoyt/goawk (go)

Issue:
Allow line break between `}` and `while`
See:
```
$ goawk 'BEGIN{do{}
while(0)}'
<cmdline>:1:11: expected while instead of <newline>
BEGIN{do{}
          ^
$
```
POSIX allows line breaks after every closing brace, the one terminating a `do` group is no exception.

Pull request description:
Allow optional newline between "do {}" and "while"
Fixes #219. Thanks @oguz-ismail for the report.

Patch:
diff --git a/parser/parser.go b/parser/parser.go
index 33b1e5f..c5db54a 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -379,6 +379,7 @@ func (p *parser) stmt() ast.Stmt {
 		p.next()
 		p.optionalNewlines()
 		body := p.loopStmts()
+		p.optionalNewlines()
 		p.expect(WHILE)
 		p.expect(LPAREN)
 		cond := p.expr()


Test patch:
diff --git a/interp/interp_test.go b/interp/interp_test.go
index a2208b9..630aff0 100644
--- a/interp/interp_test.go
+++ b/interp/interp_test.go
@@ -155,6 +155,7 @@ NR==3, NR==5 { print NR }
 	{`BEGIN { s="x"; while (s=="x") { print s; s="y" } }`, "", "x\n", "", ""},
 	{`BEGIN { s="x"; while (s!="") { print s; s="" } }`, "", "x\n", "", ""},
 	{`BEGIN { s="x"; while (s) { print s; s="" } }`, "", "x\n", "", ""},
+	{"BEGIN { do { print 1 }\nwhile (0) }", "", "1\n", "", ""},
 	// regression tests for break and continue with nested loops
 	{`
 BEGIN {