mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Add ByID and ByToken to token.IDMap.
This commit is contained in:
1 parent
f744089e9c
commit
cf8167a648
4 files changed
+20
-17
No files matched your search
+1
-1
@@ -288,7 +288,7 @@ func (c *Checker) checkType(n *a.Node) error {
|
||||
return nil
|
||||
}
|
||||
// TODO: see if n.ID1 refers to a struct type.
|
||||
return fmt.Errorf("check: %q is not a type", c.idMap.ByKey(n.ID1.Key()))
|
||||
return fmt.Errorf("check: %q is not a type", c.idMap.ByID(n.ID1))
|
||||
|
||||
case t.IDPtr:
|
||||
n = n.RHS
|
||||
|
||||
+15
-15
@@ -88,7 +88,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
if x := p.peekID(); x != t.IDSemicolon {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return nil, fmt.Errorf("parse: expected (implicit) \";\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -120,7 +120,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
if x := p.peekID(); x != t.IDSemicolon {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return nil, fmt.Errorf("parse: expected (implicit) \";\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -137,12 +137,12 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
||||
p.src = p.src[1:]
|
||||
id1 := p.peekID()
|
||||
if !id1.IsStrLiteral() {
|
||||
got := p.m.ByKey(id1.Key())
|
||||
got := p.m.ByID(id1)
|
||||
return nil, fmt.Errorf("parse: expected string literal, got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
if x := p.peekID(); x != t.IDSemicolon {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return nil, fmt.Errorf("parse: expected (implicit) \";\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -182,7 +182,7 @@ func (p *parser) parseIdent() (t.ID, error) {
|
||||
}
|
||||
x := p.src[0]
|
||||
if !x.IsIdent() {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByToken(x)
|
||||
return 0, fmt.Errorf("parse: expected identifier, got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -191,7 +191,7 @@ func (p *parser) parseIdent() (t.ID, error) {
|
||||
|
||||
func (p *parser) parseList(parseFunc func(*parser) (*a.Node, error)) ([]*a.Node, error) {
|
||||
if x := p.peekID(); x != t.IDOpenParen {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return nil, fmt.Errorf("parse: expected \"(\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -216,7 +216,7 @@ func (p *parser) parseList(parseFunc func(*parser) (*a.Node, error)) ([]*a.Node,
|
||||
case t.IDComma:
|
||||
p.src = p.src[1:]
|
||||
default:
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return nil, fmt.Errorf("parse: expected \")\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
}
|
||||
@@ -261,7 +261,7 @@ func (p *parser) parseType() (*a.Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
if x := p.peekID(); x != t.IDCloseBracket {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return nil, fmt.Errorf("parse: expected \"]\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -304,7 +304,7 @@ func (p *parser) parseType() (*a.Node, error) {
|
||||
// t.IDOpenBracket for an index.
|
||||
func (p *parser) parseRangeOrIndex(allowIndex bool) (op t.ID, mhs *a.Node, rhs *a.Node, err error) {
|
||||
if x := p.peekID(); x != t.IDOpenBracket {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return 0, nil, nil, fmt.Errorf("parse: expected \"[\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -329,7 +329,7 @@ func (p *parser) parseRangeOrIndex(allowIndex bool) (op t.ID, mhs *a.Node, rhs *
|
||||
if allowIndex {
|
||||
expected = `":" or "]"`
|
||||
}
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return 0, nil, nil, fmt.Errorf("parse: expected %s, got %q at %s:%d", expected, got, p.filename, p.line())
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ func (p *parser) parseRangeOrIndex(allowIndex bool) (op t.ID, mhs *a.Node, rhs *
|
||||
}
|
||||
|
||||
if x := p.peekID(); x != t.IDCloseBracket {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return 0, nil, nil, fmt.Errorf("parse: expected \"]\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -351,7 +351,7 @@ func (p *parser) parseRangeOrIndex(allowIndex bool) (op t.ID, mhs *a.Node, rhs *
|
||||
|
||||
func (p *parser) parseBlock() ([]*a.Node, error) {
|
||||
if x := p.peekID(); x != t.IDOpenCurly {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return nil, fmt.Errorf("parse: expected \"{\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -370,7 +370,7 @@ func (p *parser) parseBlock() ([]*a.Node, error) {
|
||||
block = append(block, s)
|
||||
|
||||
if x := p.peekID(); x != t.IDSemicolon {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return nil, fmt.Errorf("parse: expected (implicit) \";\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -477,7 +477,7 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
|
||||
func (p *parser) parseIf() (*a.Node, error) {
|
||||
if x := p.peekID(); x != t.IDIf {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return nil, fmt.Errorf("parse: expected \"if\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
@@ -573,7 +573,7 @@ func (p *parser) parseOperand() (*a.Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
if x := p.peekID(); x != t.IDCloseParen {
|
||||
got := p.m.ByKey(x.Key())
|
||||
got := p.m.ByID(x)
|
||||
return nil, fmt.Errorf("parse: expected \")\", got %q at %s:%d", got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
@@ -109,7 +109,7 @@ func RenderFile(w io.Writer, src []token.Token, comments []string, m *token.IDMa
|
||||
}
|
||||
}
|
||||
|
||||
buf = append(buf, m.ByKey(t.Key())...)
|
||||
buf = append(buf, m.ByToken(t)...)
|
||||
|
||||
if t.ID == token.IDOpenCurly {
|
||||
if indent == maxIndent {
|
||||
|
||||
@@ -57,6 +57,9 @@ func (m *IDMap) ByName(name string) ID {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *IDMap) ByID(x ID) string { return m.ByKey(Key(x >> KeyShift)) }
|
||||
func (m *IDMap) ByToken(t Token) string { return m.ByKey(Key(t.ID >> KeyShift)) }
|
||||
|
||||
func (m *IDMap) ByKey(k Key) string {
|
||||
if k < nBuiltInKeys {
|
||||
return builtInsByKey[k].name
|
||||
|
||||
Reference in new issue
Block a user