-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep grammar in lark file; add pint-ucum-unit-definitions file
- Loading branch information
Showing
5 changed files
with
181 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Units definition file to extend Pints default.txt with UCUM units | ||
# Language: english | ||
|
||
# Syntax | ||
# ====== | ||
# Units | ||
# ----- | ||
# <canonical name> = <relation to another unit or dimension> [= <symbol>] [= <alias>] [ = <alias> ] [...] | ||
# | ||
# The canonical name and aliases should be expressed in singular form. | ||
# Pint automatically deals with plurals built by adding 's' to the singular form; plural | ||
# forms that don't follow this rule should be instead explicitly listed as aliases. | ||
# | ||
# If a unit has no symbol and one wants to define aliases, then the symbol should be | ||
# conventionally set to _. | ||
# | ||
# Example: | ||
# millennium = 1e3 * year = _ = millennia | ||
# | ||
# | ||
# Prefixes | ||
# -------- | ||
# <prefix>- = <amount> [= <symbol>] [= <alias>] [ = <alias> ] [...] | ||
# | ||
# Example: | ||
# deca- = 1e+1 = da- = deka- | ||
# | ||
# | ||
# Additional aliases | ||
# ------------------ | ||
# @alias <canonical name or previous alias> = <alias> [ = <alias> ] [...] | ||
# | ||
# Used to add aliases to already existing unit definitions. | ||
# Particularly useful when one wants to enrich definitions | ||
# from defaults_en.txt with custom aliases. | ||
# | ||
# Example: | ||
# @alias meter = my_meter | ||
|
||
# See also: https://pint.readthedocs.io/en/stable/advanced/defining.html | ||
|
||
|
||
#### UNITS #### | ||
# Common and less common, grouped by quantity. | ||
|
||
|
||
#### UNIT GROUPS #### | ||
|
||
|
||
#### Additional aliases #### | ||
|
||
@alias degree_Celsius = Cel | ||
@alias millimeter_Hg = mm[Hg] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Based on UCUM specification (Version 2.1, 2017-11-21) | ||
# Includes ucumvert-specific fixes to handle all common UCUM units | ||
# and some edge cases not present in the official examples. | ||
# This file is auto-created by parser.update_lark_ucum_grammar_file | ||
|
||
main_term: DIVIDE term | ||
| term | ||
?term: term OPERATOR component | ||
| component | ||
?component: annotatable ANNOTATION | ||
| annotatable | ||
?annotatable: simple_unit EXPONENT | ||
| ANNOTATION | ||
| simple_unit | ||
| "(" main_term ")" | ||
| "(" term ")" | ||
| "(" component ")" | ||
simple_unit: METRIC | ||
| SHORT_PREFIX METRIC | ||
| LONG_PREFIX METRIC | ||
| NON_METRIC | ||
| FACTOR | ||
|
||
ANNOTATION: "{" STRING "}" | ||
STRING: /[!-z|~]*/ # ASCII chars 33-126 without curly braces | ||
OPERATOR: "." | DIVIDE | ||
DIVIDE: "/" | ||
SHORT_PREFIX: "Y" |"Z" |"E" |"P" |"T" |"G" |"M" |"k" |"h" |"d" |"c" |"m" |"u" | ||
|"n" |"p" |"f" |"a" |"z" |"y" | ||
LONG_PREFIX: "da" |"Ki" |"Mi" |"Gi" |"Ti" | ||
METRIC: "m" |"s" |"g" |"rad" |"K" |"C" |"cd" |"mol" |"sr" |"Hz" |"N" |"Pa" | ||
|"J" |"W" |"A" |"V" |"F" |"Ohm" |"S" |"Wb" |"Cel" |"T" |"H" |"lm" | ||
|"lx" |"Bq" |"Gy" |"Sv" |"l" |"L" |"ar" |"t" |"bar" |"u" |"eV" |"pc" | ||
|"[c]" |"[h]" |"[k]" |"[eps_0]" |"[mu_0]" |"[e]" |"[m_e]" |"[m_p]" | ||
|"[G]" |"[g]" |"[ly]" |"gf" |"Ky" |"Gal" |"dyn" |"erg" |"P" |"Bi" | ||
|"St" |"Mx" |"G" |"Oe" |"Gb" |"sb" |"Lmb" |"ph" |"Ci" |"R" |"RAD" | ||
|"REM" |"cal_[15]" |"cal_[20]" |"cal_m" |"cal_IT" |"cal_th" |"cal" | ||
|"tex" |"m[H2O]" |"m[Hg]" |"eq" |"osm" |"g%" |"kat" |"U" |"[iU]" | ||
|"[IU]" |"Np" |"B" |"B[SPL]" |"B[V]" |"B[mV]" |"B[uV]" |"B[10.nV]" | ||
|"B[W]" |"B[kW]" |"st" |"mho" |"bit" |"By" |"Bd" | ||
NON_METRIC: "10*" |"10^" |"[pi]" |"%" |"[ppth]" |"[ppm]" |"[ppb]" |"[pptr]" | ||
|"gon" |"deg" |"'" |"''" |"min" |"h" |"d" |"a_t" |"a_j" |"a_g" |"a" | ||
|"wk" |"mo_s" |"mo_j" |"mo_g" |"mo" |"AU" |"atm" |"[lbf_av]" |"[in_i]" | ||
|"[ft_i]" |"[yd_i]" |"[mi_i]" |"[fth_i]" |"[nmi_i]" |"[kn_i]" | ||
|"[sin_i]" |"[sft_i]" |"[syd_i]" |"[cin_i]" |"[cft_i]" |"[cyd_i]" | ||
|"[bf_i]" |"[cr_i]" |"[mil_i]" |"[cml_i]" |"[hd_i]" |"[ft_us]" | ||
|"[yd_us]" |"[in_us]" |"[rd_us]" |"[ch_us]" |"[lk_us]" |"[rch_us]" | ||
|"[rlk_us]" |"[fth_us]" |"[fur_us]" |"[mi_us]" |"[acr_us]" |"[srd_us]" | ||
|"[smi_us]" |"[sct]" |"[twp]" |"[mil_us]" |"[in_br]" |"[ft_br]" | ||
|"[rd_br]" |"[ch_br]" |"[lk_br]" |"[fth_br]" |"[pc_br]" |"[yd_br]" | ||
|"[mi_br]" |"[nmi_br]" |"[kn_br]" |"[acr_br]" |"[gal_us]" |"[bbl_us]" | ||
|"[qt_us]" |"[pt_us]" |"[gil_us]" |"[foz_us]" |"[fdr_us]" |"[min_us]" | ||
|"[crd_us]" |"[bu_us]" |"[gal_wi]" |"[pk_us]" |"[dqt_us]" |"[dpt_us]" | ||
|"[tbs_us]" |"[tsp_us]" |"[cup_us]" |"[foz_m]" |"[cup_m]" |"[tsp_m]" | ||
|"[tbs_m]" |"[gal_br]" |"[pk_br]" |"[bu_br]" |"[qt_br]" |"[pt_br]" | ||
|"[gil_br]" |"[foz_br]" |"[fdr_br]" |"[min_br]" |"[gr]" |"[lb_av]" | ||
|"[oz_av]" |"[dr_av]" |"[scwt_av]" |"[lcwt_av]" |"[ston_av]" | ||
|"[lton_av]" |"[stone_av]" |"[pwt_tr]" |"[oz_tr]" |"[lb_tr]" | ||
|"[sc_ap]" |"[dr_ap]" |"[oz_ap]" |"[lb_ap]" |"[oz_m]" |"[lne]" | ||
|"[pnt]" |"[pca]" |"[pnt_pr]" |"[pca_pr]" |"[pied]" |"[pouce]" | ||
|"[ligne]" |"[didot]" |"[cicero]" |"[degF]" |"[degR]" |"[degRe]" | ||
|"[Cal]" |"[Btu_39]" |"[Btu_59]" |"[Btu_60]" |"[Btu_m]" |"[Btu_IT]" | ||
|"[Btu_th]" |"[Btu]" |"[HP]" |"[den]" |"[in_i'H2O]" |"[in_i'Hg]" | ||
|"[PRU]" |"[wood'U]" |"[diop]" |"[p'diop]" |"%[slope]" |"[mesh_i]" | ||
|"[Ch]" |"[drp]" |"[hnsf'U]" |"[MET]" |"[hp'_X]" |"[hp'_C]" |"[hp'_M]" | ||
|"[hp'_Q]" |"[hp_X]" |"[hp_C]" |"[hp_M]" |"[hp_Q]" |"[kp_X]" |"[kp_C]" | ||
|"[kp_M]" |"[kp_Q]" |"[pH]" |"[S]" |"[HPF]" |"[LPF]" |"[arb'U]" | ||
|"[USP'U]" |"[GPL'U]" |"[MPL'U]" |"[APL'U]" |"[beth'U]" |"[anti'Xa'U]" | ||
|"[todd'U]" |"[dye'U]" |"[smgy'U]" |"[bdsk'U]" |"[ka'U]" |"[knk'U]" | ||
|"[mclg'U]" |"[tb'U]" |"[CCID_50]" |"[TCID_50]" |"[EID_50]" |"[PFU]" | ||
|"[FFU]" |"[CFU]" |"[IR]" |"[BAU]" |"[AU]" |"[Amb'a'1'U]" |"[PNU]" | ||
|"[Lf]" |"[D'ag'U]" |"[FEU]" |"[ELU]" |"[EU]" |"Ao" |"b" |"att" | ||
|"[psi]" |"circ" |"sph" |"[car_m]" |"[car_Au]" |"[smoot]" | ||
|"[m/s2/Hz^(1/2)]" |"bit_s" | ||
EXPONENT : ["+"|"-"] NON_ZERO_DIGITS | ||
FACTOR: NON_ZERO_DIGITS | ||
NON_ZERO_DIGITS : /[1-9][0-9]*/ # positive integers > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters