quantities.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²" (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 SupInteger


Base:
Symbol
Prefix Symbol
( Units )


Symbol:
The symbol of a valid unit


Prefix:
The symbol of a valid prefix


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


SupInteger:
Superscript version of Integer

Members

Aliases

NumberParser
alias NumberParser(N) = N function(ref string s) pure @(safe)

Type of a function that can parse a string for a numeric value of type N.

Classes

DimensionException
class DimensionException

Exception thrown when operating on two units that are not interconvertible.

ParsingException
class ParsingException

Exception thrown when parsing encounters an unexpected token.

Structs

Parser
struct Parser(N)

A quantity parser

SymbolList
struct SymbolList(N)

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

Templates

compileTimeParser
template compileTimeParser(N, alias symbolList, alias numberParser)

Creates a compile-time parser that parses a string for a quantity and automatically deduces the quantity type.

Meta

Authors

Nicolas Sicard