Remove token ID/Key distinction, part 8 of N

This commit is contained in:
Nigel Tao committed 2018-04-15 15:22:09 +10:00
1 parent 81e02e7db6
commit 1717d5befd
4 files changed
+16 -16

No files matched your search

+2 -2
View File
@@ -375,7 +375,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
switch n.Operator().Key() {
case 0:
id1 := n.Ident()
if id1.IsNumLiteral() {
if id1.IsNumLiteral(q.tm) {
z := big.NewInt(0)
s := id1.Str(q.tm)
if _, ok := z.SetString(s, 0); !ok {
@@ -385,7 +385,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
n.SetMType(typeExprIdeal)
return nil
} else if id1.IsIdent() {
} else if id1.IsIdent(q.tm) {
if q.localVars != nil {
if typ, ok := q.localVars[id1]; ok {
n.SetMType(typ)
+7 -7
View File
@@ -105,7 +105,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
case t.KeyPackageID, t.KeyUse:
p.src = p.src[1:]
path := p.peek1()
if !path.IsStrLiteral() {
if !path.IsStrLiteral(p.tm) {
got := p.tm.ByID(path)
return nil, fmt.Errorf(`parse: expected string literal, got %q at %s:%d`, got, p.filename, p.line())
}
@@ -239,7 +239,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
keyword := p.src[0].ID
p.src = p.src[1:]
message := p.peek1()
if !message.IsStrLiteral() {
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())
}
@@ -309,7 +309,7 @@ func (p *parser) parseIdent() (t.ID, error) {
return 0, fmt.Errorf(`parse: expected identifier at %s:%d`, p.filename, p.line())
}
x := p.src[0]
if !x.ID.IsIdent() {
if !x.ID.IsIdent(p.tm) {
got := p.tm.ByToken(x)
return 0, fmt.Errorf(`parse: expected identifier, got %q at %s:%d`, got, p.filename, p.line())
}
@@ -561,7 +561,7 @@ func (p *parser) parseAssertNode() (*a.Node, error) {
if p.peek1().Key() == t.KeyVia {
p.src = p.src[1:]
reason = p.peek1()
if !reason.IsStrLiteral() {
if !reason.IsStrLiteral(p.tm) {
got := p.tm.ByID(reason)
return nil, fmt.Errorf(`parse: expected string literal, got %q at %s:%d`, got, p.filename, p.line())
}
@@ -633,7 +633,7 @@ func (p *parser) parseStatement1() (*a.Node, error) {
// TODO: allow expressions, not just literals, as unroll counts?
unrollID := p.peek1()
unrollStr := p.tm.ByKey(unrollID.Key())
if !unrollID.IsLiteral() {
if !unrollID.IsLiteral(p.tm) {
return nil, fmt.Errorf(`parse: expected literal unroll count, got %q at %s:%d`,
unrollStr, p.filename, p.line())
}
@@ -930,7 +930,7 @@ func (p *parser) parseOperand() (*a.Expr, error) {
}
return a.NewExpr(0, op, 0, 0, nil, nil, rhs.Node(), nil), nil
case x.IsLiteral():
case x.IsLiteral(p.tm):
p.src = p.src[1:]
return a.NewExpr(0, 0, 0, x, nil, nil, nil, nil), nil
@@ -955,7 +955,7 @@ func (p *parser) parseOperand() (*a.Expr, error) {
message := p.peek1()
// TODO: parse the "pkg" in `error pkg."foo"`.
statusPkg := t.ID(0)
if !message.IsStrLiteral() {
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())
}
+6 -6
View File
@@ -73,10 +73,10 @@ func (x ID) IsAssociativeOp() bool {
return minOpKey <= x.Key() && x.Key() <= maxOpKey && x.AssociativeForm() != 0
}
func (x ID) IsLiteral() bool { return Flags(x)&FlagsLiteral != 0 }
func (x ID) IsNumLiteral() bool { return Flags(x)&FlagsNumLiteral != 0 }
func (x ID) IsStrLiteral() bool { return Flags(x)&FlagsStrLiteral != 0 }
func (x ID) IsIdent() bool { return Flags(x)&FlagsIdent != 0 }
func (x ID) IsLiteral(m *Map) bool { return Flags(x)&FlagsLiteral != 0 }
func (x ID) IsNumLiteral(m *Map) bool { return Flags(x)&FlagsNumLiteral != 0 }
func (x ID) IsStrLiteral(m *Map) bool { return Flags(x)&FlagsStrLiteral != 0 }
func (x ID) IsIdent(m *Map) bool { return Flags(x)&FlagsIdent != 0 }
func (x ID) IsOpen() bool { return x.Key() < Key(len(isOpen)) && isOpen[x.Key()] }
func (x ID) IsClose() bool { return x.Key() < Key(len(isClose)) && isClose[x.Key()] }
@@ -86,8 +86,8 @@ func (x ID) IsTightRight() bool { return x.Key() < Key(len(isTightRight)) && isT
func (x ID) IsAssign() bool { return minAssignKey <= x.Key() && x.Key() <= maxAssignKey }
func (x ID) IsNumType() bool { return minNumTypeKey <= x.Key() && x.Key() <= maxNumTypeKey }
func (x ID) IsImplicitSemicolon() bool {
return x.IsLiteral() || x.IsIdent() ||
func (x ID) IsImplicitSemicolon(m *Map) bool {
return x.IsLiteral(m) || x.IsIdent(m) ||
(x.Key() < Key(len(isImplicitSemicolon)) && isImplicitSemicolon[x.Key()])
}
+1 -1
View File
@@ -132,7 +132,7 @@ loop:
if c <= ' ' {
if c == '\n' {
if len(tokens) > 0 && tokens[len(tokens)-1].ID.IsImplicitSemicolon() {
if len(tokens) > 0 && tokens[len(tokens)-1].ID.IsImplicitSemicolon(m) {
tokens = append(tokens, Token{IDSemicolon, line})
}
if line == maxLine {