asciiunits 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,502 @@
1
+ {
2
+ "format": "asciiunits-oracle/v1",
3
+ "source": "unitsml 0.6.9",
4
+ "cases": [
5
+ {
6
+ "input": "m",
7
+ "kind": "accept"
8
+ },
9
+ {
10
+ "input": "mm",
11
+ "kind": "accept"
12
+ },
13
+ {
14
+ "input": "um",
15
+ "kind": "accept"
16
+ },
17
+ {
18
+ "input": "degK",
19
+ "kind": "accept"
20
+ },
21
+ {
22
+ "input": "kg",
23
+ "kind": "accept"
24
+ },
25
+ {
26
+ "input": "mm*s^-2",
27
+ "kind": "accept"
28
+ },
29
+ {
30
+ "input": "sqrt(Hz)",
31
+ "kind": "accept"
32
+ },
33
+ {
34
+ "input": "K/(kg*m)",
35
+ "kind": "accept"
36
+ },
37
+ {
38
+ "input": "cal_th/cm^2",
39
+ "kind": "accept"
40
+ },
41
+ {
42
+ "input": "Hz^10*darcy^100",
43
+ "kind": "accept"
44
+ },
45
+ {
46
+ "input": "A*C^3",
47
+ "kind": "accept"
48
+ },
49
+ {
50
+ "input": "A/C^-3",
51
+ "kind": "accept"
52
+ },
53
+ {
54
+ "input": "J/kg*K",
55
+ "kind": "accept"
56
+ },
57
+ {
58
+ "input": "dim_Theta*dim_L^2",
59
+ "kind": "accept"
60
+ },
61
+ {
62
+ "input": "kg^-2",
63
+ "kind": "accept"
64
+ },
65
+ {
66
+ "input": "mW*cm^(-2)",
67
+ "kind": "accept"
68
+ },
69
+ {
70
+ "input": "p-",
71
+ "kind": "accept"
72
+ },
73
+ {
74
+ "input": "k-",
75
+ "kind": "accept"
76
+ },
77
+ {
78
+ "input": "1",
79
+ "kind": "accept"
80
+ },
81
+ {
82
+ "input": "(m)(s)",
83
+ "kind": "accept"
84
+ },
85
+ {
86
+ "input": "m(s)",
87
+ "kind": "accept"
88
+ },
89
+ {
90
+ "input": "m s",
91
+ "kind": "accept"
92
+ },
93
+ {
94
+ "input": "m *s",
95
+ "kind": "accept"
96
+ },
97
+ {
98
+ "input": "m* s",
99
+ "kind": "accept"
100
+ },
101
+ {
102
+ "input": "m s",
103
+ "kind": "accept"
104
+ },
105
+ {
106
+ "input": "m * s",
107
+ "kind": "accept"
108
+ },
109
+ {
110
+ "input": "km//s",
111
+ "kind": "accept"
112
+ },
113
+ {
114
+ "input": "s^-2//m",
115
+ "kind": "accept"
116
+ },
117
+ {
118
+ "input": "m sqrt(Hz)",
119
+ "kind": "accept"
120
+ },
121
+ {
122
+ "input": "(m^2*s^-1)//kg",
123
+ "kind": "accept"
124
+ },
125
+ {
126
+ "input": "dim_L",
127
+ "kind": "accept"
128
+ },
129
+ {
130
+ "input": "(dim_L*dim_M)/dim_T^2",
131
+ "kind": "accept"
132
+ },
133
+ {
134
+ "input": "sqrt(dim_M)",
135
+ "kind": "accept"
136
+ },
137
+ {
138
+ "input": "sqrt(m*s)",
139
+ "kind": "accept"
140
+ },
141
+ {
142
+ "input": "sqrt((m))",
143
+ "kind": "accept"
144
+ },
145
+ {
146
+ "input": "(sqrt(m))",
147
+ "kind": "accept"
148
+ },
149
+ {
150
+ "input": "sqrt(m)s",
151
+ "kind": "accept"
152
+ },
153
+ {
154
+ "input": "m^2*s",
155
+ "kind": "accept"
156
+ },
157
+ {
158
+ "input": "m^-1/2",
159
+ "kind": "accept"
160
+ },
161
+ {
162
+ "input": "m^(-1/2)",
163
+ "kind": "accept"
164
+ },
165
+ {
166
+ "input": "m^(1/2)",
167
+ "kind": "accept"
168
+ },
169
+ {
170
+ "input": "(m)(s)(A)",
171
+ "kind": "accept"
172
+ },
173
+ {
174
+ "input": "1m",
175
+ "kind": "accept"
176
+ },
177
+ {
178
+ "input": "1*m",
179
+ "kind": "accept"
180
+ },
181
+ {
182
+ "input": "m*1",
183
+ "kind": "accept"
184
+ },
185
+ {
186
+ "input": "((m))",
187
+ "kind": "accept"
188
+ },
189
+ {
190
+ "input": "dim_L dim_M",
191
+ "kind": "accept"
192
+ },
193
+ {
194
+ "input": "(dim_L)(dim_M)",
195
+ "kind": "accept"
196
+ },
197
+ {
198
+ "input": "(dim_L)*dim_M",
199
+ "kind": "accept"
200
+ },
201
+ {
202
+ "input": "mm*",
203
+ "kind": "accept"
204
+ },
205
+ {
206
+ "input": "k-",
207
+ "kind": "accept"
208
+ },
209
+ {
210
+ "input": "da-",
211
+ "kind": "accept"
212
+ },
213
+ {
214
+ "input": "M-",
215
+ "kind": "accept"
216
+ },
217
+ {
218
+ "input": "s^2/m^2",
219
+ "kind": "accept"
220
+ },
221
+ {
222
+ "input": "m/s^2",
223
+ "kind": "accept"
224
+ },
225
+ {
226
+ "input": "K*kg^0",
227
+ "kind": "accept"
228
+ },
229
+ {
230
+ "input": "Hz^-10",
231
+ "kind": "accept"
232
+ },
233
+ {
234
+ "input": "um^3",
235
+ "kind": "accept"
236
+ },
237
+ {
238
+ "input": "mmol",
239
+ "kind": "accept"
240
+ },
241
+ {
242
+ "input": "nm",
243
+ "kind": "accept"
244
+ },
245
+ {
246
+ "input": "kat",
247
+ "kind": "accept"
248
+ },
249
+ {
250
+ "input": "Bq*Sv^2",
251
+ "kind": "accept"
252
+ },
253
+ {
254
+ "input": "ft*lb/s^2",
255
+ "kind": "accept"
256
+ },
257
+ {
258
+ "input": "mu*s",
259
+ "kind": "accept"
260
+ },
261
+ {
262
+ "input": "m*s^-3*K^4",
263
+ "kind": "accept"
264
+ },
265
+ {
266
+ "input": "sqrt(m*s^-1)",
267
+ "kind": "accept"
268
+ },
269
+ {
270
+ "input": "cm^(3)",
271
+ "kind": "accept"
272
+ },
273
+ {
274
+ "input": "cal_th/cm^2 h",
275
+ "kind": "accept"
276
+ },
277
+ {
278
+ "input": "(a_year*s^-1)",
279
+ "kind": "accept"
280
+ },
281
+ {
282
+ "input": "m*s/",
283
+ "kind": "accept"
284
+ },
285
+ {
286
+ "input": "sqrt(sqrt(m))",
287
+ "kind": "accept"
288
+ },
289
+ {
290
+ "input": "ton-force (2000 lb)",
291
+ "kind": "accept"
292
+ },
293
+ {
294
+ "input": "ton-force (2000 lb)*m",
295
+ "kind": "accept"
296
+ },
297
+ {
298
+ "input": "ton-force (2000 lb)^2",
299
+ "kind": "accept"
300
+ },
301
+ {
302
+ "input": "m//s//kg",
303
+ "kind": "accept"
304
+ },
305
+ {
306
+ "input": "m/s/kg",
307
+ "kind": "accept"
308
+ },
309
+ {
310
+ "input": "m^2^3",
311
+ "kind": "reject"
312
+ },
313
+ {
314
+ "input": "m^(2)^3",
315
+ "kind": "reject"
316
+ },
317
+ {
318
+ "input": "m^(2^3)",
319
+ "kind": "reject"
320
+ },
321
+ {
322
+ "input": "m^(-2)^2",
323
+ "kind": "reject"
324
+ },
325
+ {
326
+ "input": "m*s^(1)",
327
+ "kind": "accept"
328
+ },
329
+ {
330
+ "input": "m*s^(-1)",
331
+ "kind": "accept"
332
+ },
333
+ {
334
+ "input": "m*s^(+1)",
335
+ "kind": "reject"
336
+ },
337
+ {
338
+ "input": "m*1/2",
339
+ "kind": "reject"
340
+ },
341
+ {
342
+ "input": "m/2",
343
+ "kind": "reject"
344
+ },
345
+ {
346
+ "input": "Mt",
347
+ "kind": "accept"
348
+ },
349
+ {
350
+ "input": "EiB",
351
+ "kind": "reject"
352
+ },
353
+ {
354
+ "input": "que?",
355
+ "kind": "reject"
356
+ },
357
+ {
358
+ "input": "m2",
359
+ "kind": "reject"
360
+ },
361
+ {
362
+ "input": "m^",
363
+ "kind": "reject"
364
+ },
365
+ {
366
+ "input": "sqrt",
367
+ "kind": "reject"
368
+ },
369
+ {
370
+ "input": "dim_Ldim_M",
371
+ "kind": "reject"
372
+ },
373
+ {
374
+ "input": "mm**",
375
+ "kind": "reject"
376
+ },
377
+ {
378
+ "input": "*m",
379
+ "kind": "reject"
380
+ },
381
+ {
382
+ "input": "()",
383
+ "kind": "reject"
384
+ },
385
+ {
386
+ "input": "sqrt()",
387
+ "kind": "reject"
388
+ },
389
+ {
390
+ "input": "m**",
391
+ "kind": "reject"
392
+ },
393
+ {
394
+ "input": "s-2",
395
+ "kind": "reject"
396
+ },
397
+ {
398
+ "input": "m^-1/2 (spaced)",
399
+ "kind": "reject"
400
+ },
401
+ {
402
+ "input": "m ^2",
403
+ "kind": "reject"
404
+ },
405
+ {
406
+ "input": "s ^ -2",
407
+ "kind": "reject"
408
+ },
409
+ {
410
+ "input": "m)s",
411
+ "kind": "reject"
412
+ },
413
+ {
414
+ "input": "m(s",
415
+ "kind": "reject"
416
+ },
417
+ {
418
+ "input": "(m",
419
+ "kind": "reject"
420
+ },
421
+ {
422
+ "input": "((m)",
423
+ "kind": "reject"
424
+ },
425
+ {
426
+ "input": "(m))",
427
+ "kind": "reject"
428
+ },
429
+ {
430
+ "input": "ki-",
431
+ "kind": "reject"
432
+ },
433
+ {
434
+ "input": "degK-",
435
+ "kind": "reject"
436
+ },
437
+ {
438
+ "input": "m 2",
439
+ "kind": "reject"
440
+ },
441
+ {
442
+ "input": "m^2 3",
443
+ "kind": "reject"
444
+ },
445
+ {
446
+ "input": "sqrt(m)^2",
447
+ "kind": "reject"
448
+ },
449
+ {
450
+ "input": "dim_L*",
451
+ "kind": "reject"
452
+ },
453
+ {
454
+ "input": "micro*s",
455
+ "kind": "reject"
456
+ },
457
+ {
458
+ "input": "(cm)^3",
459
+ "kind": "reject"
460
+ },
461
+ {
462
+ "input": "m1",
463
+ "kind": "reject"
464
+ },
465
+ {
466
+ "input": "-",
467
+ "kind": "reject"
468
+ },
469
+ {
470
+ "input": "--",
471
+ "kind": "reject"
472
+ },
473
+ {
474
+ "input": "^",
475
+ "kind": "reject"
476
+ },
477
+ {
478
+ "input": "*",
479
+ "kind": "reject"
480
+ },
481
+ {
482
+ "input": "^2m",
483
+ "kind": "reject"
484
+ },
485
+ {
486
+ "input": "k",
487
+ "kind": "reject"
488
+ },
489
+ {
490
+ "input": "TON",
491
+ "kind": "reject"
492
+ },
493
+ {
494
+ "input": "SQRT(m)",
495
+ "kind": "reject"
496
+ },
497
+ {
498
+ "input": "Sqrt(m)",
499
+ "kind": "reject"
500
+ }
501
+ ]
502
+ }
@@ -0,0 +1,129 @@
1
+ # UnitsML expression corpus inputs.
2
+ # One per line: ACCEPT or REJECT, TAB, then the expression (the content
3
+ # inside unitsml(...)). Declared kinds are verified against the parslet
4
+ # parser by scripts/gen_oracle.rb — the oracle wins, fix declarations here
5
+ # if they disagree.
6
+ ACCEPT m
7
+ ACCEPT mm
8
+ ACCEPT um
9
+ ACCEPT degK
10
+ ACCEPT kg
11
+ ACCEPT mm*s^-2
12
+ ACCEPT sqrt(Hz)
13
+ ACCEPT K/(kg*m)
14
+ ACCEPT cal_th/cm^2
15
+ ACCEPT Hz^10*darcy^100
16
+ ACCEPT A*C^3
17
+ ACCEPT A/C^-3
18
+ ACCEPT J/kg*K
19
+ ACCEPT dim_Theta*dim_L^2
20
+ ACCEPT kg^-2
21
+ ACCEPT mW*cm^(-2)
22
+ ACCEPT p-
23
+ ACCEPT k-
24
+ ACCEPT 1
25
+ ACCEPT (m)(s)
26
+ ACCEPT m(s)
27
+ ACCEPT m s
28
+ ACCEPT m *s
29
+ ACCEPT m* s
30
+ ACCEPT m s
31
+ ACCEPT m * s
32
+ ACCEPT km//s
33
+ ACCEPT s^-2//m
34
+ ACCEPT m sqrt(Hz)
35
+ ACCEPT (m^2*s^-1)//kg
36
+ ACCEPT dim_L
37
+ ACCEPT (dim_L*dim_M)/dim_T^2
38
+ ACCEPT sqrt(dim_M)
39
+ ACCEPT sqrt(m*s)
40
+ ACCEPT sqrt((m))
41
+ ACCEPT (sqrt(m))
42
+ ACCEPT sqrt(m)s
43
+ ACCEPT m^2*s
44
+ ACCEPT m^-1/2
45
+ ACCEPT m^(-1/2)
46
+ ACCEPT m^(1/2)
47
+ ACCEPT (m)(s)(A)
48
+ ACCEPT 1m
49
+ ACCEPT 1*m
50
+ ACCEPT m*1
51
+ ACCEPT ((m))
52
+ ACCEPT dim_L dim_M
53
+ ACCEPT (dim_L)(dim_M)
54
+ ACCEPT (dim_L)*dim_M
55
+ ACCEPT mm*
56
+ ACCEPT k-
57
+ ACCEPT da-
58
+ ACCEPT M-
59
+ ACCEPT s^2/m^2
60
+ ACCEPT m/s^2
61
+ ACCEPT K*kg^0
62
+ ACCEPT Hz^-10
63
+ ACCEPT um^3
64
+ ACCEPT mmol
65
+ ACCEPT nm
66
+ ACCEPT kat
67
+ ACCEPT Bq*Sv^2
68
+ ACCEPT ft*lb/s^2
69
+ ACCEPT mu*s
70
+ ACCEPT m*s^-3*K^4
71
+ ACCEPT sqrt(m*s^-1)
72
+ ACCEPT cm^(3)
73
+ ACCEPT cal_th/cm^2 h
74
+ ACCEPT (a_year*s^-1)
75
+ ACCEPT m*s/
76
+ ACCEPT sqrt(sqrt(m))
77
+ ACCEPT ton-force (2000 lb)
78
+ ACCEPT ton-force (2000 lb)*m
79
+ ACCEPT ton-force (2000 lb)^2
80
+ ACCEPT m//s//kg
81
+ ACCEPT m/s/kg
82
+ REJECT m^2^3
83
+ REJECT m^(2)^3
84
+ REJECT m^(2^3)
85
+ REJECT m^(-2)^2
86
+ ACCEPT m*s^(1)
87
+ ACCEPT m*s^(-1)
88
+ REJECT m*s^(+1)
89
+ REJECT m*1/2
90
+ REJECT m/2
91
+ ACCEPT Mt
92
+ REJECT EiB
93
+ REJECT que?
94
+ REJECT m2
95
+ REJECT m^
96
+ REJECT sqrt
97
+ REJECT dim_Ldim_M
98
+ REJECT mm**
99
+ REJECT *m
100
+ REJECT ()
101
+ REJECT sqrt()
102
+ REJECT m**
103
+ REJECT s-2
104
+ REJECT m^-1/2 (spaced)
105
+ REJECT m ^2
106
+ REJECT s ^ -2
107
+ REJECT m)s
108
+ REJECT m(s
109
+ REJECT (m
110
+ REJECT ((m)
111
+ REJECT (m))
112
+ REJECT ki-
113
+ REJECT degK-
114
+ REJECT m 2
115
+ REJECT m^2 3
116
+ REJECT sqrt(m)^2
117
+ REJECT dim_L*
118
+ REJECT micro*s
119
+ REJECT (cm)^3
120
+ REJECT m1
121
+ REJECT -
122
+ REJECT --
123
+ REJECT ^
124
+ REJECT *
125
+ REJECT ^2m
126
+ REJECT k
127
+ REJECT TON
128
+ REJECT SQRT(m)
129
+ REJECT Sqrt(m)
@@ -0,0 +1,79 @@
1
+ # UnitsML AsciiUnits expression grammar.
2
+ #
3
+ # 1:1 transcription of unitsml-ruby lib/unitsml/parse.rb +
4
+ # lib/unitsml/intermediate_exp_rules.rb (Parslet), rule for rule, in the
5
+ # same alternative order — PEG ordered choice makes order decisive, and the
6
+ # quirks (trailing-extender acceptance, guard fall-through to prefixed
7
+ # units, no power after fenced/sqrt forms) are load-bearing.
8
+ #
9
+ # Terminal tables are generated from UnitsDB via scripts/gen_tables.rb and
10
+ # embedded in the artifact at compile time.
11
+ #
12
+ # Capture names (unit, prefix, dimension, integer, power_numerator, extender,
13
+ # sqrt, int_exp, sequence, first_set, second_set, open_paren, close_paren)
14
+ # mirror the Parslet .as() names so consumers can map them 1:1.
15
+
16
+ grammar UnitsmlAscii version "0.1.0" {
17
+
18
+ ws = %x09 / %x0A / %x0B / %x0C / %x0D / %x20
19
+ spaces = 1*ws
20
+ lparen = "("
21
+ rparen = ")"
22
+ hyphen = "-"
23
+ star = "*"
24
+ digit = %x30-39
25
+ forward_slashes = "//" / "/"
26
+ extender = (forward_slashes / star) as extender
27
+ number = ["-"] 1*digit
28
+ slashed_number = (number [forward_slashes number]) as integer
29
+ end_guard = !ANY / &(extender / lparen / rparen / spaces)
30
+
31
+ unit = alt from_table "units" column "name" as unit
32
+ single_letter_prefixes = alt from_table "prefixes_single" column "name" as prefix
33
+ double_letter_prefixes = alt from_table "prefixes_double" column "name" as prefix
34
+ dimensions = alt from_table "dimensions" column "name" as dimension
35
+
36
+ power = "^" slashed_number_int_exp as power_numerator
37
+ slashed_number_int_exp = slashed_number / (lparen slashed_number_named_int_exp as int_exp rparen)
38
+ slashed_number_named_int_exp = (lparen slashed_number_int_exp rparen) / slashed_number_int_exp
39
+ unit_and_power = unit [power]
40
+ sqrt_sequence = "sqrt" lparen prefixes_units_int_exp as sqrt rparen
41
+ sqrt_dimensions = "sqrt" lparen dimension_rules_int_exp as sqrt rparen
42
+ extended_prefixed_units = extender [spaces] prefixes_units_int_exp as sequence
43
+ powered_dimensions = dimensions [power]
44
+
45
+ prefixes_units = (sqrt_sequence [extended_prefixed_units]) / ("1" as unit [extended_prefixed_units]) / (unit_and_power extended_prefixed_units) / (unit_and_power end_guard) / (double_letter_prefixes unit_and_power extended_prefixed_units) / (double_letter_prefixes unit_and_power) / (single_letter_prefixes unit_and_power extended_prefixed_units) / (single_letter_prefixes unit_and_power)
46
+
47
+ wrapper_prefixes_units_value = int_exp_prefixes_units / prefixes_units_int_exp
48
+ int_exp_prefixes_units = lparen [spaces] named_int_exp_prefixes_units as int_exp [spaces] rparen
49
+ prefixes_units_named_int_exp = (lparen as open_paren [spaces] wrapper_prefixes_units_value as int_exp [spaces] rparen as close_paren)
50
+ named_int_exp_prefixes_units = (prefixes_units_named_int_exp as int_exp [(prefixes_units_int_exp / extended_prefixed_units)]) / prefixes_units_int_exp
51
+
52
+ implicit_extended = (prefixes_units as first_set spaces as extender prefixes_units as second_set) / (int_exp_prefixes_units as first_int_exp_set [spaces] int_exp_prefixes_units as second_int_exp_set) / (prefixes_units as first_set [spaces] int_exp_prefixes_units as second_int_exp_set) / (int_exp_prefixes_units as first_int_exp_set [spaces] prefixes_units as second_set)
53
+
54
+ prefixes_units_int_exp = (implicit_extended as implicit_extended [spaces] [prefixes_units_int_exp as sequence]) / (implicit_extended as implicit_extended [spaces] extender [spaces] [prefixes_units_int_exp as sequence]) / (int_exp_prefixes_units [spaces] extender [spaces] [prefixes_units_int_exp as sequence]) / (prefixes_units [spaces] extender [spaces] [prefixes_units_int_exp as sequence]) / (int_exp_prefixes_units [prefixes_units_int_exp as sequence]) / (prefixes_units [prefixes_units_int_exp as sequence])
55
+
56
+ dimension_rules = (sqrt_dimensions / powered_dimensions) [extended_dimension_rules]
57
+ extended_dimension_rules = [spaces] extender [spaces] dimension_rules_int_exp as sequence
58
+ int_exp_dimension_rules = lparen dimension_rules_named_exp as int_exp rparen [extended_dimension_rules]
59
+ dimension_rules_named_exp = ((lparen as open_paren dimension_rules_int_exp as int_exp rparen as close_paren) as int_exp [spaces] (dimension_rules_int_exp / extended_dimension_rules) as sequence) / dimension_rules_int_exp
60
+
61
+ dimension_rules_int_exp = (dimension_rules as first_set spaces as extender dimension_rules as second_set [dimension_rules_int_exp]) / (dimension_rules as first_set [spaces] int_exp_dimension_rules as second_int_exp_set [dimension_rules_int_exp]) / (int_exp_dimension_rules as first_int_exp_set [spaces] dimension_rules as second_set [dimension_rules_int_exp]) / (int_exp_dimension_rules as first_int_exp_set [spaces] int_exp_dimension_rules as second_int_exp_set [dimension_rules_int_exp]) / int_exp_dimension_rules / dimension_rules
62
+
63
+ expression = prefixes_units_int_exp / dimension_rules_int_exp / (single_letter_prefixes hyphen) / (double_letter_prefixes hyphen)
64
+
65
+ entry expression: expression
66
+
67
+ test expression {
68
+ accept "mm*s^-2"
69
+ accept "sqrt(Hz)"
70
+ accept "K/(kg*m)"
71
+ accept "p-"
72
+ accept "(m)(s)"
73
+ accept "mm*"
74
+ accept "sqrt(sqrt(m))"
75
+ reject "que?"
76
+ reject "m2"
77
+ reject "dim_Ldim_M"
78
+ }
79
+ }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asciiunits
4
+ VERSION = "0.1.0"
5
+ end