mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 00:38:14 +01:00
Tweak io_bind syntax
This commit is contained in:
1 parent
e992921dce
commit
badbdfc487
7 files changed
+62
-88
No files matched your search
+31
-35
@@ -669,18 +669,7 @@ func (p *parser) parseAsserts() ([]*a.Node, error) {
|
||||
}
|
||||
|
||||
func (p *parser) parseIOBindNode() (*a.Node, error) {
|
||||
if p.peek1() == t.IDIOBind {
|
||||
p.src = p.src[1:]
|
||||
in_fields, err := p.parseList(t.IDCloseParen, (*parser).parseIOBindExprNode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body, err := p.parseBlock()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return a.NewIOBind(t.IDIOBind, nil, nil, in_fields, body).AsNode(), nil
|
||||
}
|
||||
keyword := p.peek1()
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDOpenParen {
|
||||
@@ -710,31 +699,38 @@ func (p *parser) parseIOBindNode() (*a.Node, error) {
|
||||
io.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
|
||||
if x := p.peek1(); x != t.IDComma {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ",", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
limit := (*a.Expr)(nil)
|
||||
if keyword == t.IDIOBind {
|
||||
// No-op.
|
||||
|
||||
if x := p.peek1(); x != t.IDLimit {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected "limit", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
} else {
|
||||
if x := p.peek1(); x != t.IDComma {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ",", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDColon {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ":", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if x := p.peek1(); x != t.IDLimit {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected "limit", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
limit, err := p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if limit.Effect() != 0 {
|
||||
return nil, fmt.Errorf(`parse: argument %q is not effect-free at %s:%d`,
|
||||
io.Str(p.tm), p.filename, p.line())
|
||||
if x := p.peek1(); x != t.IDColon {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ":", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
var err error
|
||||
limit, err = p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if limit.Effect() != 0 {
|
||||
return nil, fmt.Errorf(`parse: argument %q is not effect-free at %s:%d`,
|
||||
io.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
}
|
||||
|
||||
if x := p.peek1(); x != t.IDCloseParen {
|
||||
@@ -748,7 +744,7 @@ func (p *parser) parseIOBindNode() (*a.Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return a.NewIOBind(t.IDIOLimit, io, limit, nil, body).AsNode(), nil
|
||||
return a.NewIOBind(keyword, io, limit, body).AsNode(), nil
|
||||
}
|
||||
|
||||
func (p *parser) parseIf() (*a.If, error) {
|
||||
|
||||
Reference in new issue
Block a user