css-parser-api icon indicating copy to clipboard operation
css-parser-api copied to clipboard

Give parser ability to automatically collapse repeated property names in a block

Open tabatkins opened this issue 9 years ago • 2 comments

When you have multiple declarations with the same property name in a single block, CSS automatically collapses them for you, retaining only the last one. While we shouldn't opt the generic parser into this by default (other languages might have a good reason to allow multiple declarations with the same name), it would be nice to give the parser an option to do this for you automatically.

tabatkins avatar May 31 '16 23:05 tabatkins

Oooh, or better idea: treat declaration values with the same property name as monoids. Default to the List monoid so the multiple values just get collected in an array, allow easily opting into CSS's behavior of using the Last monoid, but also allow just providing a "join" callback to the parser that can implement arbitrary monoidal behavior, like merging properties into a conjoined value. (My InfoTree format I invented for Bikeshed, which is vaguely CSSish, has both of these behaviors, depending on the key - some override with last-wins behavior, others combine in a reasonable way.)

tabatkins avatar May 31 '16 23:05 tabatkins

(Note that this doesn't need to actually mention the word "monoid" anywhere - the options property can just take either an enum or a function.)

tabatkins avatar May 31 '16 23:05 tabatkins