-
Notifications
You must be signed in to change notification settings - Fork 2
/
ucum_grammar.lark
81 lines (75 loc) · 4.23 KB
/
ucum_grammar.lark
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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: UNIT_METRIC
| PREFIX_SHORT UNIT_METRIC
| PREFIX_LONG UNIT_METRIC
| UNIT_NON_METRIC
| FACTOR
ANNOTATION: "{" STRING "}"
STRING: /[!-z|~]*/ # ASCII chars 33-126 without curly braces
OPERATOR: "." | DIVIDE
DIVIDE: "/"
PREFIX_SHORT: "Y" |"Z" |"E" |"P" |"T" |"G" |"M" |"k" |"h" |"d" |"c" |"m" |"u"
|"n" |"p" |"f" |"a" |"z" |"y"
PREFIX_LONG: "da" |"Ki" |"Mi" |"Gi" |"Ti"
UNIT_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"
UNIT_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