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

dsl for real numbers #85

Open
facontidavide opened this issue Sep 3, 2022 · 11 comments
Open

dsl for real numbers #85

facontidavide opened this issue Sep 3, 2022 · 11 comments
Labels
enhancement New feature or request

Comments

@facontidavide
Copy link

I am new to the library so I apologize if I am missing something.

Exploring the examples I can't find anything similar to dsl::integer for real numbers.
O course I understand that parsing real numbers is complicated having a lot of different representations, but I would need something simple such as 5.67 to start with.

My application is an AST similar to the calculator example.

@foonathan
Copy link
Owner

I plan on adding that in the future.

What I'm doing right now as a workaround is to manually parse digits + period + digits, capture that and call std::stod/std::from_chars on the lexeme.

@foonathan foonathan changed the title Question: dsl for real numbers? dsl for real numbers Sep 3, 2022
@foonathan foonathan added the enhancement New feature or request label Sep 3, 2022
@facontidavide

This comment was marked as off-topic.

@foonathan

This comment was marked as off-topic.

@facontidavide

This comment was marked as off-topic.

@foonathan
Copy link
Owner

I'm reopening this as I do want to add it properly.

@foonathan foonathan reopened this Sep 3, 2022
@facontidavide

This comment was marked as off-topic.

@facontidavide

This comment was marked as off-topic.

@foonathan

This comment was marked as off-topic.

@foonathan
Copy link
Owner

@jokoon
Copy link

jokoon commented Sep 27, 2023

Are you planning to parse those as valid?
.3
0.
43.

I think I managed to parse those at one point, but it was 2 additional rules, so it was not very efficient.

I don't know what ISO or other standard say about this, but to me it seems that something like .003 should not be standard, but as soon as it's valid code somewhere, people are going to ask for it.

@foonathan
Copy link
Owner

The interface I'm imagining is similar to the split between dsl::digits and dsl::integer.

I'm envisioning a dsl::number rule that takes token rules. One for matching the integer part, one for matching a fractional part, and one for matching the exponent.

So you can completely define what's considered to be valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants