mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +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
|
return nil
|
||||||
}
|
}
|
||||||
// TODO: see if n.ID1 refers to a struct type.
|
// 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:
|
case t.IDPtr:
|
||||||
n = n.RHS
|
n = n.RHS
|
||||||
|
|||||||
+15
-15
@@ -88,7 +88,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if x := p.peekID(); x != t.IDSemicolon {
|
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())
|
return nil, fmt.Errorf("parse: expected (implicit) \";\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
@@ -120,7 +120,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if x := p.peekID(); x != t.IDSemicolon {
|
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())
|
return nil, fmt.Errorf("parse: expected (implicit) \";\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
@@ -137,12 +137,12 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
|||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
id1 := p.peekID()
|
id1 := p.peekID()
|
||||||
if !id1.IsStrLiteral() {
|
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())
|
return nil, fmt.Errorf("parse: expected string literal, got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
if x := p.peekID(); x != t.IDSemicolon {
|
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())
|
return nil, fmt.Errorf("parse: expected (implicit) \";\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
@@ -182,7 +182,7 @@ func (p *parser) parseIdent() (t.ID, error) {
|
|||||||
}
|
}
|
||||||
x := p.src[0]
|
x := p.src[0]
|
||||||
if !x.IsIdent() {
|
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())
|
return 0, fmt.Errorf("parse: expected identifier, got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
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) {
|
func (p *parser) parseList(parseFunc func(*parser) (*a.Node, error)) ([]*a.Node, error) {
|
||||||
if x := p.peekID(); x != t.IDOpenParen {
|
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())
|
return nil, fmt.Errorf("parse: expected \"(\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
@@ -216,7 +216,7 @@ func (p *parser) parseList(parseFunc func(*parser) (*a.Node, error)) ([]*a.Node,
|
|||||||
case t.IDComma:
|
case t.IDComma:
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
default:
|
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())
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
if x := p.peekID(); x != t.IDCloseBracket {
|
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())
|
return nil, fmt.Errorf("parse: expected \"]\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
@@ -304,7 +304,7 @@ func (p *parser) parseType() (*a.Node, error) {
|
|||||||
// t.IDOpenBracket for an index.
|
// t.IDOpenBracket for an index.
|
||||||
func (p *parser) parseRangeOrIndex(allowIndex bool) (op t.ID, mhs *a.Node, rhs *a.Node, err error) {
|
func (p *parser) parseRangeOrIndex(allowIndex bool) (op t.ID, mhs *a.Node, rhs *a.Node, err error) {
|
||||||
if x := p.peekID(); x != t.IDOpenBracket {
|
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())
|
return 0, nil, nil, fmt.Errorf("parse: expected \"[\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
@@ -329,7 +329,7 @@ func (p *parser) parseRangeOrIndex(allowIndex bool) (op t.ID, mhs *a.Node, rhs *
|
|||||||
if allowIndex {
|
if allowIndex {
|
||||||
expected = `":" or "]"`
|
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())
|
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 {
|
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())
|
return 0, nil, nil, fmt.Errorf("parse: expected \"]\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
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) {
|
func (p *parser) parseBlock() ([]*a.Node, error) {
|
||||||
if x := p.peekID(); x != t.IDOpenCurly {
|
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())
|
return nil, fmt.Errorf("parse: expected \"{\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
@@ -370,7 +370,7 @@ func (p *parser) parseBlock() ([]*a.Node, error) {
|
|||||||
block = append(block, s)
|
block = append(block, s)
|
||||||
|
|
||||||
if x := p.peekID(); x != t.IDSemicolon {
|
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())
|
return nil, fmt.Errorf("parse: expected (implicit) \";\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
@@ -477,7 +477,7 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
|||||||
|
|
||||||
func (p *parser) parseIf() (*a.Node, error) {
|
func (p *parser) parseIf() (*a.Node, error) {
|
||||||
if x := p.peekID(); x != t.IDIf {
|
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())
|
return nil, fmt.Errorf("parse: expected \"if\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
@@ -573,7 +573,7 @@ func (p *parser) parseOperand() (*a.Node, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if x := p.peekID(); x != t.IDCloseParen {
|
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())
|
return nil, fmt.Errorf("parse: expected \")\", got %q at %s:%d", got, p.filename, p.line())
|
||||||
}
|
}
|
||||||
p.src = p.src[1:]
|
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 t.ID == token.IDOpenCurly {
|
||||||
if indent == maxIndent {
|
if indent == maxIndent {
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ func (m *IDMap) ByName(name string) ID {
|
|||||||
return 0
|
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 {
|
func (m *IDMap) ByKey(k Key) string {
|
||||||
if k < nBuiltInKeys {
|
if k < nBuiltInKeys {
|
||||||
return builtInsByKey[k].name
|
return builtInsByKey[k].name
|
||||||
|
|||||||
Reference in new issue
Block a user