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
Parse integers #2
Conversation
pattern = /\A[a-zA-Z\-]+/ | ||
when /\d+/ | ||
pattern = /\d+/ | ||
end | ||
atom_value = pattern.match(source).to_s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this could be done in a nicer way, instead of another switch statement. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a bit muddled because numbers and atoms are parsed by the same method. How about a parse_atom
and parse_number
? We already know if it's an atom or number in the function above so it knows what one to pick.
The latter could return an Emerald::Number
@@ -23,7 +23,9 @@ def parse_node(source) | |||
when " " | |||
parse_whitespace(source) | |||
when /[a-zA-Z\-]/ | |||
parse_atom(source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably keep the parser functions always taking the source as an arg, they can pull the first character off themselves if they want to.
4684e8a
to
6af1375
Compare
Emerald::Atom.new("World")]) | ||
end | ||
|
||
it "parses two atoms: a string and an integer" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first one is an atom, not a string. Atoms are just names.
The second is a number, which isn't an atom :)
No description provided.