jinquantities-0.1.0: Unit conversion and manipulation library.

Safe HaskellSafe
LanguageHaskell2010

Data.Quantities.ExprParser

Description

Parse expressions with numbers and units.

This module provides a basic expression grammar that parses numbers and units.

Synopsis

Documentation

spaces' :: Parser String Source #

Alternate definition for spaces. Just actual spaces.

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.

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.

parseSymbolNum :: Parser (Quantity Double) Source #

Parse either a symbol or a number.

parseSymbol' :: Parser (Quantity Double) Source #

Parse a symbol with an optional negative sign. A symbol can contain alphanumeric characters and the character '_'.

parseNum :: Parser (Quantity Double) Source #

Parent function for parseNum' to parse a number.

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".

timesSign :: String -> Double -> Double Source #

Negate a number if the first argument is a negative sign.