FsLexYacc
FsLexYacc copied to clipboard
Not an issue more like an optimization
In the code generated by the parser generator we see a function "tagOfToken" this can be deleted and replaced with GetHash(), which as far as I can see for all "empty" disjoint union types without attribute values just gives back the position (byte/integer) encoding just like an enum.
Havn't tested it, but I'm quit sure that a reference to some data is en general more effecient than a jump table/branching.
Hello, GetHashCode()
does not exactly do what we want. Take the following type as an example:
type MyToken =
| STRING of string
| INT of int
| NULL
We want the tag of STRING "foo"
to be zero, just like the tag of STRING "bar"
; in other words we only care about the kind of the token, not its content. GetHashCode()
does not ignore the content. Additionally, there is no guarantee that it would return zero for STRING
s, one for INT
s and two for NULL
s. Nor there is a guarantee that there would be no collisions. That's why we need a specialized function to get the tag of a token.
What we can do however is use reflection to more efficiently implement tagOfToken
, specificaly functions of the FSharp.Reflection.FSharpValue
class. If you want to try it, feel free to submit a PR or I will do it myself.
I see now. did not take into account that they could carry data. forgot about %token token(s).