Currently I have a parser:
pScientific :: Parser Scientific
pScientific = lexeme L.scientific
This is able to easily parse something like 4087.00
but fails when then number 4,087.00 Is there a way to make megaparsec parse number with comma?
PS: I am very new to haskell, so apologize if this is a stupid question
The reason this is not parsed is because the
scientifictype is mainly defined for JSON parsing, and JSON does not allow this, and a comma is used to separate elements in arrays and objects.We can take a look at the implementation of
scientific[src]:The main thing to change is the
decimal0part, that captures a sequence of zero or more decimal numbers. We can for example implement this with:and then use that one with:
This does not take into account that the comma is placed after every three digits, so that will require extra logic, but this is a basic implementation to work accept commas in the integral part of the
Scientific.