Parse the "!" in "foo!()", meaning impure.

This commit is contained in:
Nigel Tao committed 2017-05-27 10:38:19 +10:00
1 parent 0819a42ab8
commit 849f885993
3 files changed
+28 -11

No files matched your search

+12 -4
View File
@@ -87,8 +87,12 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
return nil, fmt.Errorf(`parse: built-in %q used for func name at %s:%d`,
p.m.ByID(id1), p.filename, p.line())
}
if p.peek1().Key() == t.KeyQuestion {
flags |= a.FlagsSuspendible
switch p.peek1().Key() {
case t.KeyExclam:
flags |= a.FlagsImpure
p.src = p.src[1:]
case t.KeyQuestion:
flags |= a.FlagsImpure | a.FlagsSuspendible
p.src = p.src[1:]
}
inFields, err := p.parseList(t.KeyCloseParen, (*parser).parseFieldNode)
@@ -667,9 +671,13 @@ func (p *parser) parseOperand() (*a.Expr, error) {
default:
return lhs, nil
case t.KeyQuestion:
case t.KeyExclam, t.KeyQuestion:
if p.src[0].Key() == t.KeyExclam {
flags |= a.FlagsImpure
} else {
flags |= a.FlagsImpure | a.FlagsSuspendible
}
p.src = p.src[1:]
flags |= a.FlagsSuspendible
fallthrough
case t.KeyOpenParen: