mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
Remove token ID/Key distinction, part 8 of N
This commit is contained in:
1 parent
81e02e7db6
commit
1717d5befd
4 files changed
+16
-16
No files matched your search
+2
-2
@@ -375,7 +375,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
switch n.Operator().Key() {
|
switch n.Operator().Key() {
|
||||||
case 0:
|
case 0:
|
||||||
id1 := n.Ident()
|
id1 := n.Ident()
|
||||||
if id1.IsNumLiteral() {
|
if id1.IsNumLiteral(q.tm) {
|
||||||
z := big.NewInt(0)
|
z := big.NewInt(0)
|
||||||
s := id1.Str(q.tm)
|
s := id1.Str(q.tm)
|
||||||
if _, ok := z.SetString(s, 0); !ok {
|
if _, ok := z.SetString(s, 0); !ok {
|
||||||
@@ -385,7 +385,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
n.SetMType(typeExprIdeal)
|
n.SetMType(typeExprIdeal)
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
} else if id1.IsIdent() {
|
} else if id1.IsIdent(q.tm) {
|
||||||
if q.localVars != nil {
|
if q.localVars != nil {
|
||||||
if typ, ok := q.localVars[id1]; ok {
|
if typ, ok := q.localVars[id1]; ok {
|
||||||
n.SetMType(typ)
|
n.SetMType(typ)
|
||||||
|
|||||||
+7
-7
@@ -105,7 +105,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
|||||||
case t.KeyPackageID, t.KeyUse:
|
case t.KeyPackageID, t.KeyUse:
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
path := p.peek1()
|
path := p.peek1()
|
||||||
if !path.IsStrLiteral() {
|
if !path.IsStrLiteral(p.tm) {
|
||||||
got := p.tm.ByID(path)
|
got := p.tm.ByID(path)
|
||||||
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())
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ func (p *parser) parseTopLevelDecl() (*a.Node, error) {
|
|||||||
keyword := p.src[0].ID
|
keyword := p.src[0].ID
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
message := p.peek1()
|
message := p.peek1()
|
||||||
if !message.IsStrLiteral() {
|
if !message.IsStrLiteral(p.tm) {
|
||||||
got := p.tm.ByID(message)
|
got := p.tm.ByID(message)
|
||||||
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())
|
||||||
}
|
}
|
||||||
@@ -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())
|
return 0, fmt.Errorf(`parse: expected identifier at %s:%d`, p.filename, p.line())
|
||||||
}
|
}
|
||||||
x := p.src[0]
|
x := p.src[0]
|
||||||
if !x.ID.IsIdent() {
|
if !x.ID.IsIdent(p.tm) {
|
||||||
got := p.tm.ByToken(x)
|
got := p.tm.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())
|
||||||
}
|
}
|
||||||
@@ -561,7 +561,7 @@ func (p *parser) parseAssertNode() (*a.Node, error) {
|
|||||||
if p.peek1().Key() == t.KeyVia {
|
if p.peek1().Key() == t.KeyVia {
|
||||||
p.src = p.src[1:]
|
p.src = p.src[1:]
|
||||||
reason = p.peek1()
|
reason = p.peek1()
|
||||||
if !reason.IsStrLiteral() {
|
if !reason.IsStrLiteral(p.tm) {
|
||||||
got := p.tm.ByID(reason)
|
got := p.tm.ByID(reason)
|
||||||
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())
|
||||||
}
|
}
|
||||||
@@ -633,7 +633,7 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
|||||||
// TODO: allow expressions, not just literals, as unroll counts?
|
// TODO: allow expressions, not just literals, as unroll counts?
|
||||||
unrollID := p.peek1()
|
unrollID := p.peek1()
|
||||||
unrollStr := p.tm.ByKey(unrollID.Key())
|
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`,
|
return nil, fmt.Errorf(`parse: expected literal unroll count, got %q at %s:%d`,
|
||||||
unrollStr, p.filename, p.line())
|
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
|
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:]
|
p.src = p.src[1:]
|
||||||
return a.NewExpr(0, 0, 0, x, nil, nil, nil, nil), nil
|
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()
|
message := p.peek1()
|
||||||
// TODO: parse the "pkg" in `error pkg."foo"`.
|
// TODO: parse the "pkg" in `error pkg."foo"`.
|
||||||
statusPkg := t.ID(0)
|
statusPkg := t.ID(0)
|
||||||
if !message.IsStrLiteral() {
|
if !message.IsStrLiteral(p.tm) {
|
||||||
got := p.tm.ByID(message)
|
got := p.tm.ByID(message)
|
||||||
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())
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -73,10 +73,10 @@ func (x ID) IsAssociativeOp() bool {
|
|||||||
return minOpKey <= x.Key() && x.Key() <= maxOpKey && x.AssociativeForm() != 0
|
return minOpKey <= x.Key() && x.Key() <= maxOpKey && x.AssociativeForm() != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x ID) IsLiteral() bool { return Flags(x)&FlagsLiteral != 0 }
|
func (x ID) IsLiteral(m *Map) bool { return Flags(x)&FlagsLiteral != 0 }
|
||||||
func (x ID) IsNumLiteral() bool { return Flags(x)&FlagsNumLiteral != 0 }
|
func (x ID) IsNumLiteral(m *Map) bool { return Flags(x)&FlagsNumLiteral != 0 }
|
||||||
func (x ID) IsStrLiteral() bool { return Flags(x)&FlagsStrLiteral != 0 }
|
func (x ID) IsStrLiteral(m *Map) bool { return Flags(x)&FlagsStrLiteral != 0 }
|
||||||
func (x ID) IsIdent() bool { return Flags(x)&FlagsIdent != 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) 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()] }
|
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) IsAssign() bool { return minAssignKey <= x.Key() && x.Key() <= maxAssignKey }
|
||||||
func (x ID) IsNumType() bool { return minNumTypeKey <= x.Key() && x.Key() <= maxNumTypeKey }
|
func (x ID) IsNumType() bool { return minNumTypeKey <= x.Key() && x.Key() <= maxNumTypeKey }
|
||||||
|
|
||||||
func (x ID) IsImplicitSemicolon() bool {
|
func (x ID) IsImplicitSemicolon(m *Map) bool {
|
||||||
return x.IsLiteral() || x.IsIdent() ||
|
return x.IsLiteral(m) || x.IsIdent(m) ||
|
||||||
(x.Key() < Key(len(isImplicitSemicolon)) && isImplicitSemicolon[x.Key()])
|
(x.Key() < Key(len(isImplicitSemicolon)) && isImplicitSemicolon[x.Key()])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -132,7 +132,7 @@ loop:
|
|||||||
|
|
||||||
if c <= ' ' {
|
if c <= ' ' {
|
||||||
if c == '\n' {
|
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})
|
tokens = append(tokens, Token{IDSemicolon, line})
|
||||||
}
|
}
|
||||||
if line == maxLine {
|
if line == maxLine {
|
||||||
|
|||||||
Reference in new issue
Block a user