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
|
|
Parses a BigRational from a float
A float that
ExampleExample: "1.2" |> run pBigRat -> Success: 6/5 |
|
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.
Example
"stuk[General]" |> run pGeneralUnit -> Success: General ("stuk", 1N) |
|
Parses a Unit
Example"mg" |> run pUnit -> Success: (MilliGram 1N |> Mass) |
Full Usage:
pUnitGroup u g
Parameters:
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.
Example
Example: "kg" |> run (pUnitGroup "kg" "mass") -> Success: "kg" |
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.
Example
"mg/kg[Weight]" |> run parseUnit -> Success: CombiUnit (Mass (MilliGram 1N), OpPer, Weight (WeightKiloGram 1N)) |
|
Full Usage:
pnumber
Returns: Parser<float, unit>
|
Parser for a float Note also parses nan!
Example
Example: "1.2" |> run pfloat -> Success: 1.2 |
|
Set the value of a unit.
ExamplesetUnitValue (KiloGram 1N |> Mass) 2N = (KiloGram 2N |> Mass) |
Full Usage:
str_ws s
Parameters:
string
Returns: Parser<unit, 'a>
Type parameters: 'a |
A parser that parses a string and then any nmber of white space
Example
Example: "abc " |> run (str_ws "abc") -> Success: "abc" |
Full Usage:
ws
Returns: Parser<unit, 'a>
Type parameters: 'a |
White spaces parser, skips over any number of white spaces
Example
- Example: " " |> run ws -> Success: () |
GenPRES