mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
Change status "?foo" to just "?foo"
This commit is contained in:
1 parent
5f9d007b1c
commit
875362ea07
14 files changed
+136
-152
No files matched your search
+3
-4
@@ -307,7 +307,9 @@ const MaxExprDepth = 255
|
||||
// - RHS: <nil|Expr|TypeExpr>
|
||||
// - List0: <Arg|Expr> function call args, assoc. op args or list members.
|
||||
//
|
||||
// A zero ID0 means an identifier or literal in ID2, like "foo" or "42".
|
||||
// A zero ID0 means an identifier or literal in ID2, like `foo`, `42` or a
|
||||
// status literal like `"?foo"` or `pkg."$bar"`. For status literals, ID1 is
|
||||
// the package.
|
||||
//
|
||||
// For unary operators, ID0 is the operator and RHS is the operand.
|
||||
//
|
||||
@@ -329,9 +331,6 @@ const MaxExprDepth = 255
|
||||
// For selectors, like "LHS.ID2", ID0 is IDDot.
|
||||
//
|
||||
// For lists, like "[0, 1, 2]", ID0 is IDComma.
|
||||
//
|
||||
// For statuses like "?foo" and bar."$baz", ID0 is IDStatus, ID1 is the package
|
||||
// and ID2 is the message.
|
||||
type Expr Node
|
||||
|
||||
func (n *Expr) AsNode() *Node { return (*Node)(n) }
|
||||
|
||||
@@ -872,9 +872,6 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (a.Bounds, error) {
|
||||
n.Ident().Str(q.tm), lTyp.QID().Str(q.tm), n.Str(q.tm))
|
||||
}
|
||||
|
||||
case t.IDStatus:
|
||||
// No-op.
|
||||
|
||||
case t.IDComma:
|
||||
for _, o := range n.Args() {
|
||||
if _, err := q.bcheckExpr(o.AsExpr(), depth); err != nil {
|
||||
|
||||
+10
-10
@@ -383,6 +383,16 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
n.SetMType(typeExprIdeal)
|
||||
return nil
|
||||
|
||||
} else if id1.IsStrLiteral(q.tm) {
|
||||
if _, ok := q.c.statuses[n.StatusQID()]; !ok {
|
||||
msg, _ := t.Unescape(n.Ident().Str(q.tm))
|
||||
if _, ok := builtin.StatusMap[msg]; !ok {
|
||||
return fmt.Errorf("check: no error or status with message %q", msg)
|
||||
}
|
||||
}
|
||||
n.SetMType(typeExprStatus)
|
||||
return nil
|
||||
|
||||
} else if id1.IsIdent(q.tm) {
|
||||
if q.localVars != nil {
|
||||
if typ, ok := q.localVars[id1]; ok {
|
||||
@@ -489,16 +499,6 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
case t.IDDot:
|
||||
return q.tcheckDot(n, depth)
|
||||
|
||||
case t.IDStatus:
|
||||
if _, ok := q.c.statuses[n.StatusQID()]; !ok {
|
||||
msg, _ := t.Unescape(n.Ident().Str(q.tm))
|
||||
if _, ok := builtin.StatusMap[msg]; !ok {
|
||||
return fmt.Errorf("check: no error or status with message %q", msg)
|
||||
}
|
||||
}
|
||||
n.SetMType(typeExprStatus)
|
||||
return nil
|
||||
|
||||
case t.IDComma:
|
||||
for _, o := range n.Args() {
|
||||
o := o.AsExpr()
|
||||
|
||||
@@ -1008,18 +1008,6 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
return expr, nil
|
||||
|
||||
case t.IDStatus:
|
||||
p.src = p.src[1:]
|
||||
message := p.peek1()
|
||||
// TODO: parse the "pkg" in `error pkg."foo"`.
|
||||
statusPkg := t.ID(0)
|
||||
if !message.IsStrLiteral(p.tm) {
|
||||
got := p.tm.ByID(message)
|
||||
return nil, fmt.Errorf(`parse: expected string literal, got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
return a.NewExpr(0, t.IDStatus, statusPkg, message, nil, nil, nil, nil), nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user