sci-ratio-0.2.1.0: Rational numbers in scientific notation.

Description

The functions here parse numbers in a variety of formats. Examples:

````>>> ````readSciRational "-0.0e+3"         -- result: Just ((0 % 1) .^ 0)
````>>> ````readSciRational "0.25e+2"         -- result: Just ((25 % 1) .^ 0)
````>>> ````readSciRational "-1.0e-1"         -- result: Just (((-1) % 1) .^ (-1))
````>>> ````readSciRational "5.0e+20/6.e0"    -- result: Just ((25 % 3) .^ 19)
````>>> ````readSciRational "0xfeedface"      -- result: Just ((4277009102 % 1) .^ 0)
````>>> ````readSciRational "1e99999999"      -- result: Just ((1 % 1) .^ 99999999)
``````

All the `ReadP` parsers here can be safely used with `gather` as they do not contain any occurences of `readS_to_P`.

For writing lexers, a simple regular expression to detect numbers would be:

`[-+]? [.]? [0-9] [-+/.0-9a-zA-Z]*`

Note that this is more lenient than what the grammar of `readNumber` accepts. If Unicode is supported, one can also include:

• `U+23E8` (DECIMAL EXPONENT SYMBOL)
• `U+2044` (FRACTION SLASH) and `U+2215` (DIVISION SLASH)
• `U+2212` (MINUS SIGN)

Synopsis

# Simple parsers

Read a number (see `readNumberP`).

Read a number (see `readNumberP`).

readSign :: Num a => Char -> Maybe a Source

Interpret a sign:

`sign = [-+]`

Note: `U+2212` (MINUS SIGN) is also accepted.

# `ReadP` parsers

Read a rational number in scientific notation:

```number = [0] [bB] [0-1]+
| [0] [oO] [0-7]+
| [0] [xX] [0-9a-fA-F]+
| scientific ( fraction_slash scientific )?```

Read a number (see `readNumberP`).

Read a decimal fraction in scientific notation:

`scientific = decimal (decimal_exponent_symbol sign? dec)?`

```decimal = sign? ( [0-9]+ [.]? [0-9]*
| [.] [0-9]+ )```

Read a signed integer in base 10.

`integer = sign? [0-9]+`

Read an unsigned number in either binary (`0b`), octal (`0o`), decimal, or hexadecimal (`0x`) format:

```unsigned = [0] [bB] [0-1]+
| [0] [oO] [0-7]+
| [0] [xX] [0-9a-fA-F]+
| dec```

`hex = [0-9A-Fa-f]+`

Read an unsigned integer in base 10.

`dec = [0-9]+`

Note: Although similar functions exist in `Lex`, the versions here do not require `Eq`.

Read an unsigned integer in octal notation:

`oct = [0-7]+`

Read an unsigned integer in binary notation:

`bin = [01]+`

# Character predicates

Whether the character is a binary digit:

`bin_digit = [01]`

Whether the character can be used as an exponent symbol in scientific notation:

`decimal_exponent_symbol = [eE]`

Note: `U+23E8` (DECIMAL EXPONENT SYMBOL) is also accepted.

Whether the character is a fraction slash:

`fraction_slash = [/]`

Note: `U+2044` (FRACTION SLASH) and `U+2215` (DIVISION SLASH) are also accepted.