Description
There was a discussion over at YaLTeR/niri#1142 (comment) when trying to come up with enhancements to Niri's DSL regarding numerical stuff. The tl;dr is that there's interest in being able to type things like 100px
and 50%
, and not having to quote it.
I thought about this a bit, and I would like to propose the following change to the number grammar to facilitate this. This change would be forward compatible: existing v2 parsers would error (instead of returning incorrect data).
The change is as follows:
- any valid number may be suffixed, with no spaces, by a string (of any kind, but most likely an unquoted string). If this is done, the suffix will be used as the type annotation for that number value. That is,
100px
would be equivalent to(px)100
. - If you have BOTH a parenthetical annotation, AND a suffix, it will be treated as a syntax error. You simply cannot do
(px)100%
One catch: a very narrow range of invalid v2 documents will now become valid (since foo 100px
will no longer be an error)
Thoughts?