goccmack / gocc

Parser / Scanner Generator
Other
604 stars 48 forks source link

What's different between token.Token.IdValue() and token.Token.StringValue() #95

Open OhYee opened 5 years ago

OhYee commented 5 years ago

It seems that when I want to get the token's content text, I should use token.Token.IdValue() instead of token.Token.StringValue() ?

token.Token.StringValue() will return the string without first and last letter, and may cause panic when the length of word is 1.

For example, in the README.demo

test.go

input := []byte("hello g")

ast.go

func NewWorld(id Attrib) (*World, error) {
    return &World{id.(*token.Token).StringValue()}, nil
}