Open savetheclocktower opened 5 months ago
So I think I understand the problem:
(
, it sees li.foo
ahead of itplain_value
plain_value
because that gives it the longest possible matchplain_values
…li#foo
and li.foo
both are, because a plain value can be a URL, and both .
and #
are characters that occur in URLsSo this is a lexical precedence issue. I can think of a few solutions:
plain_value
that excludes URLs (something like plain_value_without_url
, but aliased to plain_value
), then a different version of _value
that lists plain_value_without_url
instead of plain_value
among its options, and then change pseudo_class_arguments
to choose between _selector
and my _value_without_url
url
functions (which is how I fixed a similar problem in my tree-sitter-css
fork). Hence plain_value
excludes URLs by default, and only in one specific usage do you need plain_value_with_url
insteadli#foo
might actually be a valid URL in some strange context; not sure)But the simplest thing I can think of — use prec
to encourage the parser to favor _selector
over plain_value
— is the one I just can't get working.
I could demote plain_value
to a lower precedence, and this solves my problem…
plain_value: _ => token(prec(-1, seq(
repeat(choice(
/[-_]/,
/\/[^\*\s,;!{}()\[\]]/, // Slash not followed by a '*' (which would be a comment)
)),
/[a-zA-Z]/,
repeat(choice(
/[^/\s,;!{}()\[\]]/, // Not a slash, not a delimiter character
/\/[^\*\s,;!{}()\[\]]/, // Slash not followed by a '*' (which would be a comment)
)),
))),
…but breaks three other tests. I'd much rather boost the precedence of _selectors
, but I can't seem to get that to have any effect.
I think I'm pretty close on this one and just need a nudge to find the right answer.
Did you check existing issues?
Tree-Sitter CLI Version, if relevant (output of
tree-sitter --version
)No response
Describe the bug
Only certain kinds of selectors fail to be parsed within a
:has
—class_selector
andid_selector
when they have tag names.Steps To Reproduce/Bad Parse Tree
This parses correctly:
This does not:
Here are some other examples that parse exactly as expected:
And here are some which are interpreted as
plain_value
:Expected Behavior/Parse Tree
In each of these cases, the
plain_value
should instead be aselectors
node.:has
can accept selectors of arbitrary complexity, much like:not
.Repro
No response