mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 16:47:28 +01:00
Change error "?foo" to status "?foo"
This commit is contained in:
1 parent
203b45e869
commit
eec0fce647
18 files changed
+196
-231
No files matched your search
+3
-6
@@ -277,11 +277,8 @@ func (n *Raw) SetPackage(tm *t.Map, pkg t.ID) error {
|
||||
// No-op.
|
||||
|
||||
case KExpr:
|
||||
switch o.id0 {
|
||||
default:
|
||||
if o.id0 != t.IDStatus {
|
||||
return nil
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
// No-op.
|
||||
}
|
||||
|
||||
case KTypeExpr:
|
||||
@@ -337,8 +334,8 @@ const MaxExprDepth = 255
|
||||
//
|
||||
// For lists, like "$(0, 1, 2)", ID0 is IDDollar.
|
||||
//
|
||||
// For statuses, like `error "foo"` and `suspension bar."baz"`, ID0 is the
|
||||
// keyword, ID1 is the package and ID2 is the message.
|
||||
// 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) }
|
||||
|
||||
+2
-9
@@ -78,15 +78,8 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
|
||||
|
||||
} else {
|
||||
switch n.id0 {
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
switch n.id0 {
|
||||
case t.IDError:
|
||||
buf = append(buf, "error "...)
|
||||
case t.IDStatus:
|
||||
buf = append(buf, "status "...)
|
||||
case t.IDSuspension:
|
||||
buf = append(buf, "suspension "...)
|
||||
}
|
||||
case t.IDStatus:
|
||||
buf = append(buf, "status "...)
|
||||
if n.id1 != 0 {
|
||||
buf = append(buf, tm.ByID(n.id1)...)
|
||||
buf = append(buf, '.')
|
||||
|
||||
+18
-37
@@ -19,48 +19,29 @@ import (
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
)
|
||||
|
||||
type Status struct {
|
||||
Keyword t.ID
|
||||
Value int8
|
||||
Message string
|
||||
var StatusList = [...]string{
|
||||
"?bad wuffs version",
|
||||
"?bad sizeof receiver",
|
||||
"?bad receiver",
|
||||
"?bad argument",
|
||||
"?bad argument (length too short)",
|
||||
|
||||
"?check_wuffs_version missing",
|
||||
"?check_wuffs_version called twice",
|
||||
"?invalid call sequence",
|
||||
|
||||
"?cannot return a suspension",
|
||||
|
||||
"$end of data",
|
||||
"$short read",
|
||||
"$short write",
|
||||
}
|
||||
|
||||
func (z Status) String() string {
|
||||
prefix := "status "
|
||||
switch z.Keyword {
|
||||
case t.IDError:
|
||||
prefix = "error "
|
||||
case t.IDSuspension:
|
||||
prefix = "suspension "
|
||||
}
|
||||
return prefix + z.Message
|
||||
}
|
||||
|
||||
var StatusList = [...]Status{
|
||||
{0, 0x00, "+ok"},
|
||||
|
||||
{t.IDError, -0x01, "?bad wuffs version"},
|
||||
{t.IDError, -0x02, "?bad sizeof receiver"},
|
||||
{t.IDError, -0x03, "?bad receiver"},
|
||||
{t.IDError, -0x04, "?bad argument"},
|
||||
{t.IDError, -0x05, "?bad argument (length too short)"},
|
||||
|
||||
{t.IDError, -0x10, "?check_wuffs_version missing"},
|
||||
{t.IDError, -0x11, "?check_wuffs_version called twice"},
|
||||
{t.IDError, -0x12, "?invalid call sequence"},
|
||||
|
||||
{t.IDError, -0x20, "?cannot return a suspension"},
|
||||
|
||||
{t.IDSuspension, +0x01, "$end of data"},
|
||||
{t.IDSuspension, +0x02, "$short read"},
|
||||
{t.IDSuspension, +0x03, "$short write"},
|
||||
}
|
||||
|
||||
var StatusMap = map[string]Status{}
|
||||
var StatusMap = map[string]bool{}
|
||||
|
||||
func init() {
|
||||
for _, s := range StatusList {
|
||||
StatusMap[s.Message] = s
|
||||
StatusMap[s] = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -866,7 +866,7 @@ 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.IDError, t.IDStatus, t.IDSuspension:
|
||||
case t.IDStatus:
|
||||
// No-op.
|
||||
|
||||
case t.IDDollar:
|
||||
|
||||
+1
-2
@@ -489,8 +489,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
case t.IDDot:
|
||||
return q.tcheckDot(n, depth)
|
||||
|
||||
// TODO: remove all but t.IDStatus.
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
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 {
|
||||
|
||||
+2
-3
@@ -1022,8 +1022,7 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
||||
p.src = p.src[1:]
|
||||
return expr, nil
|
||||
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
keyword := x
|
||||
case t.IDStatus:
|
||||
p.src = p.src[1:]
|
||||
message := p.peek1()
|
||||
// TODO: parse the "pkg" in `error pkg."foo"`.
|
||||
@@ -1033,7 +1032,7 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
||||
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, keyword, statusPkg, message, nil, nil, nil, nil), nil
|
||||
return a.NewExpr(0, t.IDStatus, statusPkg, message, nil, nil, nil, nil), nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+46
-50
@@ -331,31 +331,29 @@ const (
|
||||
maxKeyword = 0x9F
|
||||
|
||||
// TODO: sort these by name, when the list has stabilized.
|
||||
IDFunc = ID(0x80)
|
||||
IDAssert = ID(0x81)
|
||||
IDWhile = ID(0x82)
|
||||
IDIf = ID(0x83)
|
||||
IDElse = ID(0x84)
|
||||
IDReturn = ID(0x85)
|
||||
IDBreak = ID(0x86)
|
||||
IDContinue = ID(0x87)
|
||||
IDStruct = ID(0x88)
|
||||
IDUse = ID(0x89)
|
||||
IDVar = ID(0x8A)
|
||||
IDPre = ID(0x8B)
|
||||
IDInv = ID(0x8C)
|
||||
IDPost = ID(0x8D)
|
||||
IDVia = ID(0x8E)
|
||||
IDPub = ID(0x8F)
|
||||
IDPri = ID(0x90)
|
||||
IDError = ID(0x91)
|
||||
IDSuspension = ID(0x92)
|
||||
IDPackageID = ID(0x93)
|
||||
IDConst = ID(0x94)
|
||||
IDTry = ID(0x95)
|
||||
IDIterate = ID(0x96)
|
||||
IDYield = ID(0x97)
|
||||
IDIOBind = ID(0x98)
|
||||
IDFunc = ID(0x80)
|
||||
IDAssert = ID(0x81)
|
||||
IDWhile = ID(0x82)
|
||||
IDIf = ID(0x83)
|
||||
IDElse = ID(0x84)
|
||||
IDReturn = ID(0x85)
|
||||
IDBreak = ID(0x86)
|
||||
IDContinue = ID(0x87)
|
||||
IDStruct = ID(0x88)
|
||||
IDUse = ID(0x89)
|
||||
IDVar = ID(0x8A)
|
||||
IDPre = ID(0x8B)
|
||||
IDInv = ID(0x8C)
|
||||
IDPost = ID(0x8D)
|
||||
IDVia = ID(0x8E)
|
||||
IDPub = ID(0x8F)
|
||||
IDPri = ID(0x90)
|
||||
IDPackageID = ID(0x91)
|
||||
IDConst = ID(0x92)
|
||||
IDTry = ID(0x93)
|
||||
IDIterate = ID(0x94)
|
||||
IDYield = ID(0x95)
|
||||
IDIOBind = ID(0x96)
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -621,31 +619,29 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDRef: "ref",
|
||||
IDDeref: "deref",
|
||||
|
||||
IDFunc: "func",
|
||||
IDAssert: "assert",
|
||||
IDWhile: "while",
|
||||
IDIf: "if",
|
||||
IDElse: "else",
|
||||
IDReturn: "return",
|
||||
IDBreak: "break",
|
||||
IDContinue: "continue",
|
||||
IDStruct: "struct",
|
||||
IDUse: "use",
|
||||
IDVar: "var",
|
||||
IDPre: "pre",
|
||||
IDInv: "inv",
|
||||
IDPost: "post",
|
||||
IDVia: "via",
|
||||
IDPub: "pub",
|
||||
IDPri: "pri",
|
||||
IDError: "error",
|
||||
IDSuspension: "suspension",
|
||||
IDPackageID: "packageid",
|
||||
IDConst: "const",
|
||||
IDTry: "try",
|
||||
IDIterate: "iterate",
|
||||
IDYield: "yield",
|
||||
IDIOBind: "io_bind",
|
||||
IDFunc: "func",
|
||||
IDAssert: "assert",
|
||||
IDWhile: "while",
|
||||
IDIf: "if",
|
||||
IDElse: "else",
|
||||
IDReturn: "return",
|
||||
IDBreak: "break",
|
||||
IDContinue: "continue",
|
||||
IDStruct: "struct",
|
||||
IDUse: "use",
|
||||
IDVar: "var",
|
||||
IDPre: "pre",
|
||||
IDInv: "inv",
|
||||
IDPost: "post",
|
||||
IDVia: "via",
|
||||
IDPub: "pub",
|
||||
IDPri: "pri",
|
||||
IDPackageID: "packageid",
|
||||
IDConst: "const",
|
||||
IDTry: "try",
|
||||
IDIterate: "iterate",
|
||||
IDYield: "yield",
|
||||
IDIOBind: "io_bind",
|
||||
|
||||
IDArray: "array",
|
||||
IDNptr: "nptr",
|
||||
|
||||
Reference in new issue
Block a user