pub struct Parser<K, T> where
    K: AsRef<str>,
    T: AsRef<[(K, (Conv, DynDim))]>, 
{ /* private fields */ }
Expand description

Unit string parser.

Syntax of unit string

You can write unit string as you always write it.

Syntax
Unit :
   Compound ( [ Modifier ] )?

Modifier :
   abs | dif | gage

Compound :
   Product ( Slash Delimiter* Product )?

Slash :
      / | ÷\u{00F7} | \u{2044}
   | \u{2215} | \u{27CB} | \u{29F8}    | \u{6BCE}}

Delimiter :
      WhiteSpace1 | ZeroWidthSpace2 | *
   | ·\u{00B7} | ×\u{00D7} | \u{2022}
   | \u{2219} | \u{22C5} | \u{2715}
   | \u{2716} | \u{30FB} | \u{FF65}

Product :
   ( Element Delimiter* )+

Element :
   Term Exponent?

Exponent :
   -? [0-9]+

Term :
      Prefix Name
   | Name

The unit string is divided into numerator and denominator by Slash. The denominator is optional. The numerator and denominator are composed as a product of Element s. Each Element s in the product need to be delimited explicitly. Each Element s are composed of Name with SI Prefix and Exponent. SI Prefix and Exponent are optional.

Name

Name consists of any Unicode char except the followings.

  • chars composing Delimiter.
  • chars composing Slash.
  • chars composing Exponent.
  • parentheses
    • [ ]
    • ( )
    • { }
    • < >
      Square brackets mark up Modifier. Any other parentheses have no meanings in this syntax. So, these parentheses should not appear in the unit string.

Parser looks up this Name in the array set to tbl member.

Prefix

Even if it is not an SI unit, any Name may be promoted to Term with an Prefix.

In addition to the formal SI prefix, following CJK-compatible characters with the same meaning can be used for the prefix.

  • \u{3310}: giga (G)
  • \u{334B}: mega (M)
  • \u{3314}: kilo (k)
  • \u{3372}: deca (da)
  • \u{3325}: deci (d)
  • \u{3322}: centi (c)
  • \u{3349}: milli (m)
  • μ\u{00B5}, μ\u{03BC}, \u{3343}: micro
  • \u{3328}: nano (n)
  • \u{3330}: pico (p)

Term

Whether Name has Prefix or not is first parsed as if it has a Prefix. For example, when the foot (ft) and ton (t) defined the definition table, ft matches femto ton (same as nano gram (ng))!! Therefore, the foot is defined as ft. in the default definition. The period can compose of Name.

Modifier

Ummm…


  1. char which char::is_whitespace() returns true. 

  2. \u{200B}, \u{200C}, \u{200D} 

Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.