[−][src]Module ucum::parser
Parser for UCUM units and UCUM quantities (i.e. value + unit).
See http://unitsofmeasure.org/ucum.html#section-Grammar-of-Units-and-Unit-Terms.
Such a parser is usually used transparently through
UnitSystem.parse
but can be build with
UnitSystem.parser
in order to configure it prior to use.
Configuration methods
These methods can only be called before any of the parsing method (see below) are called.
-
exhaustive(flag: bool)
: determines whether the parser expects to parse the whole of its underlying text (true, default) or accepts to leave the end of the text unparsed (false).The remaining text can be accessed after parsing with the
remaining
method. -
ignore_ws(flag: bool)
: determines whether the parser will ignore white spaces (true, default); otherwise (false), whitespaces will not be accepted as part of the UCUM string (causing the parser to stop or issue an error, depending on theexhaustive
setting).
Parsing methods
Only one of these parsing methods can be called. After that, the parser is considered "consummed".
-
parse_value()
: parse the underlying text, expecting a value followed by a unit, and returns the correspondingQuantity
. -
parse_unit()
: parse the underlying text, expecting a single unit (not preceded by a value), and returns the correspondingQuantity
. -
parse_to_ast()
: parse the underlying text, expecting a single unit, and returns an Abstract Syntax Tree (AST) (for debugging or complex post-processing).
Structs
Parser | A parser for UCUM units and UCUM quantities. |