Add a lang/builtin package.

This commit is contained in:
Nigel Tao committed 2017-10-07 11:37:10 +11:00
1 parent 010c4db54f
commit 2efdf5fab6
5 files changed
+80 -67

No files matched your search

+2 -14
View File
@@ -11,6 +11,7 @@ import (
"math/big"
"github.com/google/puffs/lang/base38"
"github.com/google/puffs/lang/builtin"
a "github.com/google/puffs/lang/ast"
t "github.com/google/puffs/lang/token"
@@ -47,13 +48,6 @@ func (e *Error) Error() string {
return string(b)
}
func trimQuotes(s string) string {
if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' {
return s[1 : len(s)-1]
}
return s
}
// typeExprFoo is an *ast.Node MType (implicit type).
var (
typeExprBool = a.NewTypeExpr(0, t.IDBool, nil, nil, nil)
@@ -95,12 +89,6 @@ type Struct struct {
Struct *a.Struct
}
var builtInStatuses = map[string]t.ID{
// TODO: fill in the rest of the built in statuses.
"short read": t.IDSuspension,
"short write": t.IDSuspension,
}
func Check(tm *t.Map, files ...*a.File) (*Checker, error) {
for _, f := range files {
if f == nil {
@@ -242,7 +230,7 @@ func (c *Checker) checkStatus(node *a.Node) error {
id := n.Message()
if other, ok := c.statuses[id]; ok {
return &Error{
Err: fmt.Errorf("check: duplicate status %q", trimQuotes(id.String(c.tm))),
Err: fmt.Errorf("check: duplicate status %q", builtin.TrimQuotes(id.String(c.tm))),
Filename: n.Filename(),
Line: n.Line(),
OtherFilename: other.Status.Filename(),