goccmack / gocc

Parser / Scanner Generator
Other
618 stars 48 forks source link

Token: Literal string #117

Closed kfsone closed 3 years ago

kfsone commented 3 years ago

token.Token inlines Pos rather than having it as a member:

type Token struct {
  Type
  Lit []byte
  Pos
}

This means that in the absence of it's own String() method, token.String() is actually Pos.String(), which means that printing a token actually prints its position?

  t := &token.Token{ Type: 100, Lit: []byte("fubar"), Pos: token.Pos{ 0, 0, 0 } }
  fmt.Printf("%s %s\n", t, t.String())

outputs:

Pos(offset=0, line=0, column=0) Pos(offset=0, line=0, column=0)

but what the user probably expected would have been

fubar fubar

This could be fixed:

I've only been using go for a year or two, so I thought the go style was to put inheritances at the top and totally missed Pos vs Pos Pos.

kfsone commented 3 years ago

I guess this is what IDValue is for :)