We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
It seems the parsing utilities in Text.Megaparsec.Char.Lexer do not support parsing hexadecimal floats out of the box:
Text.Megaparsec.Char.Lexer
0x0.1E 0xA23p-4 0X1.921FB54442D18P
Given how complex these are to parse efficiently and correctly, it seems like it would be a worthy addition to megaparsec.
Let me know if I am missing something obvious and there is an easy way to use the existing functions to parse these.
The text was updated successfully, but these errors were encountered:
This is what I ended up going with using FloatingHex:
hexfloat = do zerox <- try $ char '0' >> char' 'x' <&> \x -> "0" ++ [x] whole <- hexdigits frac <- option "" $ liftA2 (:) (char '.') hexdigits exp <- option "p0" $ do p <- char' 'p' sign <- optional $ satisfy (\c -> c == '+' || c == '-') val <- digits return $ [p] ++ maybe "" (:[]) sign ++ val let literal = concat [zerox, whole, frac, exp] case readHFloat literal of Nothing -> unexpected $ Tokens $ fromList literal Just f -> return f digits = T.unpack <$> takeWhile1P (Just "digit") isDigit hexdigits = T.unpack <$> takeWhile1P (Just "hex digit") isHexDigit
Definitely not the cleanest/most performant, documenting for others who might need it or might be able to suggest improvements.
Sorry, something went wrong.
No branches or pull requests
It seems the parsing utilities in
Text.Megaparsec.Char.Lexer
do not support parsing hexadecimal floats out of the box:Given how complex these are to parse efficiently and correctly, it seems like it would be a worthy addition to megaparsec.
Let me know if I am missing something obvious and there is an easy way to use the existing functions to parse these.
The text was updated successfully, but these errors were encountered: