quantities.runtime.parsing

This module defines functions to parse units and quantities.

The text input is parsed according to the following grammar. For example:

Prefixes and unit symbols must be joined:
"1 mm" = 1 millimeter
"1 m m" = 1 square meter


Standalone units are preferred over prefixed ones:
"1 cd" = 1 candela, not 1 centiday


Powers of units:
"1 m^2"
"1 m^-1/2" (rational exponent)
"1 m²" (superscript integer)


Multiplication of to units:
"1 N m" (whitespace)
"1 N . m"
"1 N ⋅ m" (centered dot)
"1 N * m"
"1 N × m" (times sign)


Division of to units:
"1 mol / s"
"1 mol ÷ s"


Grouping of units with parentheses:
"1 kg/(m.s^2)" = 1 kg m⁻¹ s⁻²

Grammar: (whitespace not significant)

Quantity:
Units
Number Units


Number:
Numeric value parsed by std.conv.parse!double


Units:
Unit
Unit Units
Unit Operator Units


Operator:
*
.
×
/
÷


Unit:
Base
Base ^ Integer
Base ^ Rational
Base SupInteger


Base:
Symbol
Prefix Symbol
( Units )


Symbol:
The symbol of a valid unit


Prefix:
The symbol of a valid prefix


Rational:
Integer / Integer


Integer:
Integer value parsed by std.conv.parse!int


SupInteger:
Superscript version of Integer

Members

Classes

ParsingException
class ParsingException

Exception thrown when parsing encounters an unexpected token.

Structs

Parser
struct Parser(N, alias numberParser)

A quantity parser.

SymbolList
struct SymbolList(N)

Contains the symbols of the units and the prefixes that a parser can handle.

Meta

Authors

Nicolas Sicard