Skip to content

Commit 254a32b

Browse files
committed
Explain grammar details; add another edge case to tests.
1 parent 3985e1c commit 254a32b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/ucumvert/parser.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@
7373
# and fixes some more edge cases not present in the official examples.
7474
#
7575
# Changes made:
76-
# - to fix "100/{cells}" issue, we moved FACTOR from component to the simple_unit rule
77-
# - to fix "(8.h){shift}" issue, we moved "(" term ")" from component to the annotatable rule
76+
# - To fix "100/{cells}" issue, we moved FACTOR from component to the simple_unit rule
77+
# - To fix "(8.h){shift}" issue, we moved "(" term ")" from component to the annotatable rule
7878
# - Don't allow "0" as EXPONENT or FACTOR, see https://github.com/ucum-org/ucum/issues/121
79-
79+
# - Don't allow curly braces {} inside of annotation STRING (ascii 123 and 125). Without this
80+
# or escaping rules the end of annotation STRING is ambiguous.
81+
# - Move term from component rule to annotatable rule. Add maint_term and component to
82+
# annotatable rule. These changes solve various annotation issues with the original
83+
# grammar (e.g. "100{pc}", "(/m){ann}", "{ann1}{ann2}").
8084
# - Distinguish short prefixes (1 char) form long ones to handle parsing of "dar" as deci-are
8185
# instead of deca-r which does not exist.
8286

tests/test_parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
"x3": "(/s)", # bracketed unary divide
2323
"x4": "(/s2{sunit_s2}.(10{factor}.m{sunit_m}){term}){mterm}", # annotations everywhere
2424
"x5": "dar", # ambiguous prefix-unit combo: deci-are vs. deka-r (unit "r" does not exist)
25-
"x6": "{}/m",
26-
"x7": "{}",
25+
"x6": "{}/m", # operator between annotation and unit
26+
"x7": "{}", # annotation only
2727
"x8": "{/ann1/2.g}/m", # operators in annotation
28+
"x9": "{ann1}/{ann2}", # annotations only with operator
2829
}
2930
)
3031

0 commit comments

Comments
 (0)