Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Parse integers #2

wants to merge 1 commit into from

Conversation

emilywoods
Copy link
Owner

No description provided.

@emilywoods emilywoods requested a review from lpil February 19, 2017 17:05
pattern = /\A[a-zA-Z\-]+/
when /\d+/
pattern = /\d+/
end
atom_value = pattern.match(source).to_s
Copy link
Owner Author

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?

Copy link
Collaborator

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)
Copy link
Collaborator

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.

Emerald::Atom.new("World")])
end

it "parses two atoms: a string and an integer" do
Copy link
Collaborator

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 :)

@emilywoods emilywoods closed this Feb 19, 2017
@emilywoods emilywoods deleted the chore/parse-number branch February 19, 2017 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants