1-- SPDX-FileCopyrightText: 2025 Sören Tempel <soeren+git@soeren-tempel.net>2--3-- SPDX-License-Identifier: GPL-3.0-only4{-# OPTIONS_GHC -Wno-x-partial #-}56module Language.QBE.Util where78import Data.Word (Word64)9import Language.QBE.Numbers10 ( decimal,11 fractExponent,12 hexnum,13 octnum,14 sign,15 )16import Text.ParserCombinators.Parsec17 ( Parser,18 char,19 oneOf,20 skipMany,21 string,22 (<|>),23 )2425bind :: String -> a -> Parser a26bind str val = val <$ string str2728decNumber :: Parser Word6429decNumber = do30 -- TODO: QBE probably doesn't support a '+' sign prefix31 s <- sign32 s <$> decimal3334octNumber :: Parser Word6435octNumber = do36 char '0' >> octnum3738-- A float parser that tries to be compatible with strtod(3).39float :: (Floating f, Read f) => Parser f40float = do41 _ <- skipSpace42 s <- sign43 -- TODO: Support infininty and NaN44 (decimal <|> hexnum) >>= fractExponent . s45 where46 -- See musl's isspace(3) implementation.47 skipSpace :: Parser ()48 skipSpace = skipMany $ oneOf " \t\n\v\f\r"