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

Classes

ParsingException
class ParsingException

Exception thrown when parsing encounters an unexpected token.

Enums

Tok
enum Tok
Undocumented in source.

Functions

advance
void advance(Token[] tokens, Types types)
Undocumented in source. Be warned that the author may not have intended to support it.
binop
int[string] binop(int[string] dim1, int[string] dim2)
Undocumented in source. Be warned that the author may not have intended to support it.
check
void check(Token[] tokens, Types types)
Undocumented in source. Be warned that the author may not have intended to support it.
exp
int[string] exp(int[string] dim, int value)
Undocumented in source. Be warned that the author may not have intended to support it.
expInv
int[string] expInv(int[string] dim, int value)
Undocumented in source. Be warned that the author may not have intended to support it.
lex
Token[] lex(string input)
Undocumented in source. Be warned that the author may not have intended to support it.
makeSymbolList
SymbolList!N makeSymbolList(Sym list)

Helps build a SymbolList at compile-time.

parseRTQuantity
RTQuantity!N parseRTQuantity(S str, SL symbolList)
Undocumented in source. Be warned that the author may not have intended to support it.
toRT
auto toRT(Q quantity)
Undocumented in source. Be warned that the author may not have intended to support it.
withPrefix
auto withPrefix(string symbol, N factor)

Creates a prefix that can be added to a SymbolList via the SymbolList constuctor.

withUnit
auto withUnit(string symbol, Q unit)

Creates a unit that can be added to a SymbolList via the SymbolList constuctor.

Manifest constants

ctSupIntegerMap
enum ctSupIntegerMap;
Undocumented in source.

Static variables

supIntegerMap
dchar[dchar] supIntegerMap;
Undocumented in source.

Structs

QuantityParser
struct QuantityParser(N)
Undocumented in source.
RTQuantity
struct RTQuantity(N)
Undocumented in source.
SymbolList
struct SymbolList(N)

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

Token
struct Token
Undocumented in source.
WithPrefix
struct WithPrefix(N)
Undocumented in source.
WithUnit
struct WithUnit(Q)
Undocumented in source.

Templates

ctQuantityParser
template ctQuantityParser(N, alias symbolList, alias parseFun = (ref string s) => parse!N(s))

Creates a compile-time parser capable of working on user-defined units and prefixes.

rtQuantityParser
template rtQuantityParser(N, alias symbolList, alias parseFun = (ref string s) => parse!N(s))

Creates a runtime parser capable of working on user-defined units and prefixes.

Meta

Authors

Nicolas Sicard