Closed romshark closed 4 years ago
Currently, llparser.PrintFragment prints the token kind as a number in a non human-readable way:
llparser.PrintFragment
2(test.boolexp: 1:1-1:5 'true') { 3(test.boolexp: 1:1-1:5 'true') }
llparser.PrintFragment should take an optional lambda function as an additional parameter mapping kind-identifiers to their corresponding names:
func PrintFragment( fragment Fragment, out io.Writer, indent string, kindTranslator func(FragmentKind) string, ) (bytesWritten int, err error)
If kindTranslator != nil then the returned string should be used for the token kind instead of the numeric id:
kindTranslator != nil
func PrintFragment( frag, os.Stdout, " ", func(kind FragmentKind) string { switch kind { case 2: return "Second" case 3: return "Third" } return "" }, )
Should print:
Second (test.boolexp: 1:1-1:5 'true') { Third (test.boolexp: 1:1-1:5 'true') }
Currently,
llparser.PrintFragment
prints the token kind as a number in a non human-readable way:Proposal
llparser.PrintFragment
should take an optional lambda function as an additional parameter mapping kind-identifiers to their corresponding names:If
kindTranslator != nil
then the returned string should be used for the token kind instead of the numeric id:Should print: