Skip to content

[Question] How to create a standalone parser for floating-point values? #218

Answered by j-mie6
willowell asked this question in Q&A
Discussion options

You must be logged in to vote

The Lexer is absolutely the simplest way to do this in terms of LOC:

val lexer = new Lexer(LexicalDesc.plain)
val double: Parsley[Double] = lexer.nonlexeme.numeric.floating.doubleRounded // or just `double` if you want it to ensure it's a valid Java Double

Even with the default configuration this is probably good for most needs (nonlexeme here to not consume any whitespace).
If you don't want that, you'd just have to implement your own floating point parser, which isn't too hard but is more work than this solution for sure 😛

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@j-mie6
Comment options

@willowell
Comment options

Answer selected by willowell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #217 on October 05, 2023 19:18.