Skip to content

Feature/add property rule support#122

Open
shagkur wants to merge 15 commits intophax:masterfrom
unblu:feature/add-property-rule-support
Open

Feature/add property rule support#122
shagkur wants to merge 15 commits intophax:masterfrom
unblu:feature/add-property-rule-support

Conversation

@shagkur
Copy link
Copy Markdown
Contributor

@shagkur shagkur commented Apr 2, 2026

No description provided.

@blutorange
Copy link
Copy Markdown

I opened #124 before I saw that this exists. I think you're implementation is better 👍 , so #124 should be closed in favor of this.

Small note:

@blutorange
Copy link
Copy Markdown

blutorange commented Apr 4, 2026

There's one issue that relates to #69, which isn't special to this PR, but gets worse as more keywords are added.

Previously, CSS such as

syntax.foo { color: red; }

gets correctly parsed as an element+class selector with a declaration list. Now that syntax is a keyword, parsing fails with

Failed to parse CSS: [1:1] Encountered text 'syntax' corresponding to token "syntax". Was expecting one of: <EOF>, <S>, ...

(same for e.g. .inherits { color: red; })

Again, this issue already exists with other keywords, but I wanted to bring attention to this.

This could be an argument for not adding additional keywords; and parsing the contents of the rule as a general declaration list (like #124). And handling everything else when converting to the parsed AST to the domain model (CSSNodeToDomainObject). Though the "real" solution should be (in my opinion) to get the parser to tokenize differently depending on the context.

image

@shagkur
Copy link
Copy Markdown
Contributor Author

shagkur commented Apr 4, 2026

I opened #124 before I saw that this exists. I think you're implementation is better 👍 , so #124 should be closed in favor of this.

Small note:

The @property rule must not be nested. It must appear at the top level of a stylesheet.

@shagkur
Copy link
Copy Markdown
Contributor Author

shagkur commented Apr 4, 2026

There's one issue that relates to #69, which isn't special to this PR, but gets worse as more keywords are added.

Previously, CSS such as

syntax.foo { color: red; }

gets correctly parsed as an element+class selector with a declaration list. Now that syntax is a keyword, parsing fails with

Failed to parse CSS: [1:1] Encountered text 'syntax' corresponding to token "syntax". Was expecting one of: <EOF>, <S>, ...

(same for e.g. .inherits { color: red; })

Again, this issue already exists with other keywords, but I wanted to bring attention to this.

This could be an argument for not adding additional keywords; and parsing the contents of the rule as a general declaration list (like #124). And handling everything else when converting to the parsed AST to the domain model (CSSNodeToDomainObject). Though the "real" solution should be (in my opinion) to get the parser to tokenize differently depending on the context.

image

Yes this can be solved by introducing a dedicated lexer state for the property rule

@shagkur shagkur force-pushed the feature/add-property-rule-support branch from bf0f52a to 37f1315 Compare April 4, 2026 18:01
@blutorange
Copy link
Copy Markdown

The @Property rule must not be nested. It must appear at the top level of a stylesheet

I know, I only meant it should be added to produce a parser error, like it's already in various places in the jjt grammar.

@shagkur
Copy link
Copy Markdown
Contributor Author

shagkur commented Apr 5, 2026

The @Property rule must not be nested. It must appear at the top level of a stylesheet

I know, I only meant it should be added to produce a parser error, like it's already in various places in the jjt grammar.

Hmm.... i thought i already did that. See mediaRuleList() for instance

@blutorange
Copy link
Copy Markdown

Hmm.... i thought i already did that. See mediaRuleList() for instance

Yes you did. Sorry for the confusion: I added a new production that does not contain propertyRule -- so it needs to be added to either your or my PR, depending on which gets merged first ;)

@phax
Copy link
Copy Markdown
Owner

phax commented Apr 7, 2026

Thanks for taking this on!!! Still recovering from sickness and trying to catch up. Please note that I want to wait for !123 to be sorted out before doing this one - I hope you understand.

@shagkur
Copy link
Copy Markdown
Contributor Author

shagkur commented Apr 7, 2026

@blutorange Do you have an idea why couple of the new unit tests now fail? I already use the build of this branch in a project and there i don't get any errors. Do you have, by any chance, a way to debug?

@shagkur
Copy link
Copy Markdown
Contributor Author

shagkur commented Apr 7, 2026

Thanks for taking this on!!! Still recovering from sickness and trying to catch up. Please note that I want to wait for !123 to be sorted out before doing this one - I hope you understand.

Sure no worries. Meanwhile we use it as a local build for our project. With my PRs i just want to make sure to feed back changes/additions/improvements, i have to make to the parser, to make sure it finds its way back into the main stream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants