Logo GenPRES

Parser Module

Holds the FParsec parsers for a number, a known unit, a General unit and a combination of units.

Functions and values

Function or value Description

pBigRat

Full Usage: pBigRat

Returns: Parser<BigRational, unit>

Parses a BigRational from a float

A float that BigRational.fromFloat cannot convert (e.g. infinity) silently parses to 0N rather than failing the parser. This is kept intentionally; callers must not rely on the parser to reject such values.

Returns: Parser<BigRational, unit>
Example

Example: "1.2" |> run pBigRat -> Success: 6/5

pGeneralUnit

Full Usage: pGeneralUnit

Returns: Parser<Unit, unit>

Parse a General unit with the format: name[General] or just name When parsing without the [General] annotation, it will match any text that is not a known unit. Known units are checked first with proper word boundaries to avoid partial matches.

Returns: Parser<Unit, unit>
Example

"stuk[General]" |> run pGeneralUnit -> Success: General ("stuk", 1N)
"stuk" |> run pGeneralUnit -> Success: General ("stuk", 1N)
"120 stuk" |> run pGeneralUnit -> Success: General ("stuk", 1N)

pUnit

Full Usage: pUnit

Returns: CharStream<unit> -> Reply<Unit>

Parses a Unit

Returns: CharStream<unit> -> Reply<Unit>
Example

"mg" |> run pUnit -> Success: (MilliGram 1N |> Mass)

pUnitGroup u g

Full Usage: pUnitGroup u g

Parameters:
    u : string
    g : string

Returns: Parser<string, 'a>
Type parameters: 'a

Parse a unit with an optional group annotation. Uses word boundaries to ensure complete unit matches and prevent partial matches. For example, "stuk" won't match "s" (seconds) because 'tuk' follows.

u : string
g : string
Returns: Parser<string, 'a>
Example

Example: "kg" |> run (pUnitGroup "kg" "mass") -> Success: "kg"
Example: "kg[Mass]" |> run (pUnitGroup "kg" "mass") -> Success: "kg"
Example: "stuk" will not match "s" (seconds) due to word boundary check

parseUnit

Full Usage: parseUnit

Returns: Parser<Unit, unit> Parser of Unit, unit

Parse a complex unit using FParsec's OperatorPrecedenceParser. Tries to match known units first (pUnit), then falls back to general units (pGeneralUnit). This ensures known units take precedence while allowing arbitrary general unit names.

Returns: Parser<Unit, unit>

Parser of Unit, unit

Example

"mg/kg[Weight]" |> run parseUnit -> Success: CombiUnit (Mass (MilliGram 1N), OpPer, Weight (WeightKiloGram 1N))
"stuk" |> run parseUnit -> Success: General ("stuk", 1N)

pnumber

Full Usage: pnumber

Returns: Parser<float, unit>

Parser for a float Note also parses nan!

Returns: Parser<float, unit>
Example

Example: "1.2" |> run pfloat -> Success: 1.2
Example "nan" |> run pfloat -> Success: nan

setUnitValue u v

Full Usage: setUnitValue u v

Parameters:
Returns: Unit

Set the value of a unit.

u : Unit
v : BigRational
Returns: Unit
Example

setUnitValue (KiloGram 1N |> Mass) 2N = (KiloGram 2N |> Mass)

str_ws s

Full Usage: str_ws s

Parameters:
    s : string

Returns: Parser<unit, 'a>
Type parameters: 'a

A parser that parses a string and then any nmber of white space

s : string
Returns: Parser<unit, 'a>
Example

Example: "abc " |> run (str_ws "abc") -> Success: "abc"
Example: "abc" |> run (str_ws "abc") -> Success: "abc"

ws

Full Usage: ws

Returns: Parser<unit, 'a>
Type parameters: 'a

White spaces parser, skips over any number of white spaces

Returns: Parser<unit, 'a>
Example

- Example: " " |> run ws -> Success: ()
- Example: "" |> run ws -> Success: ()

Type something to start searching.