Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query selector parsing with parents wrong (precedence not handled) #54

Open
tslnc04 opened this issue Nov 7, 2022 · 0 comments · May be fixed by #66
Open

Query selector parsing with parents wrong (precedence not handled) #54

tslnc04 opened this issue Nov 7, 2022 · 0 comments · May be fixed by #66

Comments

@tslnc04
Copy link

tslnc04 commented Nov 7, 2022

If we have the query selector div > .hello.world > span, the current query selector parser produces the following result:

Parent(
    Tag([div]),
    And(
        Class([hello]),
        Parent(
            Class([world]),
            Tag([span])
        )
    )
)

This is equivalent to div > (.hello AND .world > span), which would be written as div.world > span.hello. This is a bit unexpected, as the spec would suggest the following as the result:

Parent (
    Tag([div]),
    Parent(
        And(
            Class([hello]),
            Class([world])
        ),
        Tag([span])
    )
)

I ran into this issue while making an attempt at fixing #22 but this seems to be a prerequisite to implementing child selectors. Since the parent combinator is associative, it's also possible to parse the query as left associative instead of right associative:

Parent (
    Parent (
        Tag([div]),
        And(
            Class([hello]),
            Class([world])
        ),
    ),
    Tag([span])
)

which seems to be easier for eventually implementing child selectors, since you can match a node to the right and its parent to the left. That assumes you have access to the parent though, which is part of how I had been planning on implementing the parent selector. Otherwise, you'd likely have to approach it top-down.

To fix this issue though, it seems like one would need to add a bit more complexity to the query selector parser to handle precedence. I believe this is what @kelko was running into with and and or operations in #22.

tslnc04 added a commit to tslnc04/tl that referenced this issue Apr 27, 2024
Fixes y21#54 by aligning the parsing of query selectors to the Selectors
Level 3 Reccomendations.
tslnc04 added a commit to tslnc04/tl that referenced this issue Apr 27, 2024
Fixes y21#54 by aligning the parsing of query selectors to the Selectors
Level 3 Recommendations.
@tslnc04 tslnc04 linked a pull request Apr 27, 2024 that will close this issue
tslnc04 added a commit to tslnc04/tl that referenced this issue Apr 28, 2024
Fixes y21#54 by aligning the parsing of query selectors to the Selectors
Level 3 Recommendations.
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 a pull request may close this issue.

1 participant