v1.0.0-alpha.31 Syntax matching improvements and fixes
This release improves syntax matching by new features and some fixes.
Bracketed range notation
A couple month ago bracketed range notation was added to Values and Units spec. The notation allows restrict numeric values to some range. For example, <integer [0,∞]>
is for positive integers, or <number [0,1]>
that can be used for an alpha value.
Since the notation is new thing in syntax definition, it isn't used in specs yet. However, there is a PR (w3c/csswg-drafts#3894) that will bring it to some specs. And CSSTree is ready for this.
Right now, the notation helped to remove <number-zero-one>
, <number-one-or-greater>
and <positive-integer>
from generic types and define them using a regular grammar (thanks to the notation).
Low priority type matching
There are at least two productions that has a low priority in matching. It means that such productions give a chance for other production to claim a token, and if no one – claim a token. This release introduce a solution for such productions. It's hardcoded at the moment, but can be exposed if needed (i.e. if there are more such productions).
First production is <custom-ident>
. The Values and Units spec states:
When parsing positionally-ambiguous keywords in a property value, a
<custom-ident>
production can only claim the keyword if no other unfulfilled production can claim it.
This rule takes place in properties like <'animation'>
, <'transition'>
and <'list-style'>
. Before solves in different ways:
<'animation'>
– that's not an issue since<'custom-ident'>
goes last, however a terms order can be changed in the future<'transition'>
– there was a patch for<single-transition>
that changes order of terms<'list-style'>
– had no fixes, just didn't work in some cases (see #101)
And now, all those and the rest syntaxes work as expected.
Second production is a bit tricky. It's about "unitless zero" for <length>
production. The spec states:
... if a
0
could be parsed as either a<number>
or a<length>
in a property (such asline-height
), it must parse as a<number>
.
This rule takes place in properties like <'line-height'>
or <'flex'>
. And now it works per spec too (try it here):
Changes
- Bumped
mdn/data
to2.0.4
(#99) - Lexer
- Added bracketed range notation support and related refactoring
- Removed
<number-zero-one>
,<number-one-or-greater>
and<positive-integer>
from generic types. In fact, types moved to patch, because those types can be expressed in a regular grammar due to bracketed range notation implemented - Added support for multiple token string matching
- Improved
<custom-ident>
production matching to claim the keyword only if no other unfulfilled production can claim it (#101) - Improved
<length>
production matching to claim "unitless zero" only if no other unfulfilled production can claim it - Changed lexer's constructor to prevent generic types override when used
- Fixed large
||
- and&&
-group matching, matching continues from the beginning on term match (#85) - Fixed checking that value has
var()
occurrences when value is a string (such values can't be matched on syntax currently and fail with specific error that can be used for ignorance in validation tools) - Fixed
<declaration-value>
and<any-value>
matching when a value contains a function, parentheses or braces