-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON: use enums instead of symbols #7966
Conversation
Even the |
I'm not so sure about the symbol compatibility using |
You mean it might cause a breaking change after all? |
Maybe? The only way to tell would be to find a corpus of projects which use these classes |
Even if it's not completely backwards compatibile I'd move forward with this. Upgrading it should be relatively straight forward. |
This changes
JSON::Lexer
andJSON::PullParser
to expose enums instead of symbols for token kinds and pull parser state kinds. Symbols work but they are not type-safe. Plus enums gives enumerate (duh) all possible states.The PullParser has already proven to be very useful but moving forward I wouldn't like to keep the Symbols interface so it's better now or never.
This is a breaking change:
JSON::Lexer::Token#type : Symbol
is replaced byJSON::Lexer::Token#kind : JSON::Lexer::Token::Kind
JSON::PullParser#kind : Symbol
is replaced byJSON::PullParser#kind : JSON::PullParser::Kind
To make it easy to upgrade I kept
JSON::Lexer::Token#type : Symbol
as deprecated and also madeJSON::PullParser::Kind
be comparable to symbols, with a deprecation notice. That way we don't actually break anything but if you run the compiler with--warnings=all
then you can fix things at your time.Once merged, in a subsequent PR I'll try to document all of these types, including the ones in the YAML module.
I also added
JSON::Builder#next_is_object_key?
because I think it's useful and I at least needed it for optimizing one thing in https://github.com/Blacksmoke16/oq (though I didn't send a PR there yet).