Klip
Klip copied to clipboard
Use enum intead of strings
Hey, nice project.
I want to suggest to use the enum values in the Parser
instead of comparing strings.
You have everything in place, but you .toString()
and compare it to string.
See Parser.cs
line 34:
if (tok.TokenName.ToString() == "Import")
This is slow and fragile. If you have a typo in the string the compiler will not cover your back. You will only see the parser failing. As you want to place this project as a learning experience, I suggest to promote good practices.
if (tok.TokenName == Lexer.Token.Import)
It is not even longer, has less brackets and all around a bit better 😎
Thanks for the tip, I've just updated my parser to use enums instead of strings :)
It looks much better now. 👍
Left a comment in the commit, but RightBrace got turned into RightParan and broke compilation of functions.