Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Parse expressions with numbers and units.
This module provides a basic expression grammar that parses numbers and units.
Synopsis
- spaces' :: Parser String
- parseExprQuant :: Definitions -> String -> Either (QuantityError Double) (Quantity Double)
- type EQuant = Either (QuantityError Double) (Quantity Double)
- parseExpr :: Definitions -> Parser EQuant
- parseConvertExpr :: Definitions -> Parser EQuant
- parseExpr' :: Definitions -> Parser EQuant
- parseTerm :: Definitions -> Parser EQuant
- parseFactor :: Definitions -> Parser EQuant
- parseExpt :: Definitions -> Parser EQuant
- parseNestedExpr :: Definitions -> Parser EQuant
- parseExptOp :: Definitions -> Parser EQuant
- parseTermOp :: Definitions -> Parser EQuant
- parseFactorOp :: Definitions -> Parser EQuant
- exptOp :: Parser (EQuant -> EQuant -> EQuant)
- addOp :: Parser (EQuant -> EQuant -> EQuant)
- mulOp :: Parser (EQuant -> EQuant -> EQuant)
- addEQuants :: EQuant -> EQuant -> EQuant
- subtractEQuants :: EQuant -> EQuant -> EQuant
- multiplyEQuants :: EQuant -> EQuant -> EQuant
- divideEQuants :: EQuant -> EQuant -> EQuant
- exptEQuants :: EQuant -> EQuant -> EQuant
- parseESymbolNum :: Definitions -> Parser EQuant
- parseESymbol :: Definitions -> Parser EQuant
- parseENum :: Definitions -> Parser EQuant
- preprocessQuantity :: Definitions -> Quantity Double -> EQuant
- preprocessUnit :: Definitions -> SimpleUnit -> Either (QuantityError Double) SimpleUnit
- prefixParser :: Definitions -> String -> (String, String)
- prefixParser' :: Definitions -> Parser String
- parseMultExpr :: Parser (Quantity Double)
- parseMultExpr' :: Parser (Quantity Double)
- parseMultFactor :: Parser (Quantity Double)
- parseMultExpt :: Parser (Quantity Double)
- parseMultNestedExpr :: Parser (Quantity Double)
- parseMultExptOp :: Parser (Quantity Double)
- parseMultFactorOp :: Parser (Quantity Double)
- exptMultOp :: Parser (Quantity Double -> Quantity Double -> Quantity Double)
- mulMultOp :: Parser (Quantity Double -> Quantity Double -> Quantity Double)
- exptMultQuants' :: Quantity Double -> Quantity Double -> Quantity Double
- parseSymbolNum :: Parser (Quantity Double)
- parseSymbol' :: Parser (Quantity Double)
- parseNum :: Parser (Quantity Double)
- parseNum' :: Parser Double
- parseExponential :: Parser String
- timesSign :: String -> Double -> Double
Documentation
parseExprQuant :: Definitions -> String -> Either (QuantityError Double) (Quantity Double) Source #
Parse quantity expression; addition and subtraction allowed.
type EQuant = Either (QuantityError Double) (Quantity Double) Source #
Simple type used for shorthand
parseExpr :: Definitions -> Parser EQuant Source #
Using already compiled definitions, parse expression. Also allows for expressions like "exp1 => exp2" in the middle, which converts the quantity exp1 into the units of the quantity exp2.
parseConvertExpr :: Definitions -> Parser EQuant Source #
Parser that accepts "=>" in between two expressions.
parseExpr' :: Definitions -> Parser EQuant Source #
parseFactor :: Definitions -> Parser EQuant Source #
parseExptOp :: Definitions -> Parser EQuant Source #
parseTermOp :: Definitions -> Parser EQuant Source #
parseFactorOp :: Definitions -> Parser EQuant Source #
addEQuants :: EQuant -> EQuant -> EQuant Source #
Modification of addQuants to account for Either QuantityError Quantity.
subtractEQuants :: EQuant -> EQuant -> EQuant Source #
Modification of subtractQuants to account for Either QuantityError Quantity.
multiplyEQuants :: EQuant -> EQuant -> EQuant Source #
Modification of multiplyQuants to account for Either QuantityError Quantity.
divideEQuants :: EQuant -> EQuant -> EQuant Source #
Modification of divideQuants to account for Either QuantityError Quantity.
exptEQuants :: EQuant -> EQuant -> EQuant Source #
Modification of exptQuants to account for Either QuantityError Quantity. Returns error if dimensional quantity used in exponent.
parseESymbolNum :: Definitions -> Parser EQuant Source #
Modification of parseSymbolNum to handle parsing errors.
parseESymbol :: Definitions -> Parser EQuant Source #
Parses a symbol and then parses a prefix form that symbol.
parseENum :: Definitions -> Parser EQuant Source #
Parse a number and insert the given definitions into the CompoundUnit.
preprocessQuantity :: Definitions -> Quantity Double -> EQuant Source #
Parses out prefixes and aliases from quantity's units.
preprocessUnit :: Definitions -> SimpleUnit -> Either (QuantityError Double) SimpleUnit Source #
Parses prefix and alias, if applicable, from a SimpleUnit.
prefixParser :: Definitions -> String -> (String, String) Source #
Try to parse a prefix from a symbol. Otherwise, just return the symbol.
prefixParser' :: Definitions -> Parser String Source #
Helper function for prefixParser that is a Parsec parser.
parseMultExpr :: Parser (Quantity Double) Source #
Converts string to a Quantity using an expression grammar parser. This parser does not parser addition or subtraction, and is used for unit definitions.
parseSymbol' :: Parser (Quantity Double) Source #
Parse a symbol with an optional negative sign. A symbol can contain alphanumeric characters and the character '_'.
parseNum' :: Parser Double Source #
Meat of number parser. Parse digits with an optional negative sign and optional exponential. For example, -5.2e4.
parseExponential :: Parser String Source #
Parses just the exponential part of a number. For example, parses "4" from "-5.2e4".