Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve selectors, fix complex selector parsing issues#58

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

flavorjones
Copy link
Collaborator

@flavorjonesflavorjones commentedMay 25, 2024
edited
Loading

Dipping my toes into contributing with this first PR, focused on improving selectors for potential use in Nokogiri.

  • create Node classes forCombinator,CompoundSelector, andComplexSelector
  • add some ad-hoc test coverage for selectors
  • fix.a + .b {} and.a > .b don't work #25 describing selector parsing issues
  • flatten the Complex Selector AST
  • introduce some basic selector formatting (incomplete, can finish in a future PR)

I'd love feedback on whether I'm properly following any conventions you want followed.

Comment on lines 131 to 143
assert_pattern do
actual => [
Selectors::ComplexSelector[
left: Selectors::TypeSelector[value: { name: { value: "section" } }],
combinator: { value: { value: ">" } },
right: Selectors::ComplexSelector[
left: Selectors::TypeSelector[value: { name: { value: "table" } }],
combinator: nil,
right: Selectors::TypeSelector[value: { name: { value: "tr" } }]
]
]
]
end
Copy link
CollaboratorAuthor

@flavorjonesflavorjonesMay 26, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

After sleeping on it, I don't like this recursive structure. Thespec defines acomplex-selector as:

<complex-selector> = <compound-selector> [ <combinator>? <compound-selector> ]*

which would imply a preferred AST like:

assert_patterndoactual=>[Selectors::ComplexSelector[child_nodes:[Selectors::TypeSelector[value:{name:{value:"section"}}],Selectors::Combinator[value:{value:">"}],Selectors::TypeSelector[value:{name:{value:"table"}}],Selectors::TypeSelector[value:{name:{value:"tr"}}]]]]end

I'd like to change this, either in this PR or in the next one.@kddnewton thoughts?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I've got a commit the converts to this flattened AST ... let me know what you want to do!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Flatter is better for sure

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

OK, pushed a commit that flattens this AST, LMK what you think.

@flavorjones
Copy link
CollaboratorAuthor

@kddnewton I know there's a lot of code here -- let me know if it needs explanation. The tests drove out all the changes I made, if that's helpful information.

end

# <relative-selector> = <combinator>? <complex-selector>
def relative_selector
combinator = maybe { combinator }
c = maybe { combinator }

if combinator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think I'm not understanding this line.combinator here is changing from a local variable read to a method call. Is that intentional?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As originally written, the outer variablecombinator clobbers the methodcombinator and so the variable is alwaysnil.

For example:

#! /usr/bin/env rubydeffoo42enddefbar(&block)yieldendfoo=bar{foo}foo# => nil

I'm happy to fix it some other way, this was just the simplest I came up with at the time.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry - I missed a replacement ofcombinator withc on the next line, will fix it.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pushed a complete changeset, let me know if it needs explanation.

Comment on lines 131 to 143
assert_pattern do
actual => [
Selectors::ComplexSelector[
left: Selectors::TypeSelector[value: { name: { value: "section" } }],
combinator: { value: { value: ">" } },
right: Selectors::ComplexSelector[
left: Selectors::TypeSelector[value: { name: { value: "table" } }],
combinator: nil,
right: Selectors::TypeSelector[value: { name: { value: "tr" } }]
]
]
]
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Flatter is better for sure

@kddnewton
Copy link
Member

Sorry it took so long to review!

flavorjones reacted with heart emoji

- avoid clobbering the combinator method with a local variable- return a recursive tree of complex selectorsPartial fix forruby-syntax-tree#25
@flavorjonesflavorjonesforce-pushed theflavorjones-work-on-selectors branch fromc78ef8c tobb5fcc0CompareJune 2, 2024 02:14
@flavorjones
Copy link
CollaboratorAuthor

flavorjones commentedJun 2, 2024
edited
Loading

@kddnewton I've added two commits to:

  • introduce some basic selector formatting (incomplete, can finish in a future PR)
  • flatten the Complex Selector AST

Sorry, I know this is a lot of code but I wrote the flatten-ast commit on top of the formatting commit and rebasing to isolate the flatten-ast commit was going to be time consuming.

@kddnewtonkddnewton merged commiteb3e2a7 intoruby-syntax-tree:mainJun 3, 2024
2 checks passed
@flavorjonesflavorjones deleted the flavorjones-work-on-selectors branchJune 3, 2024 21:26
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@kddnewtonkddnewtonkddnewton approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

.a + .b {} and.a > .b don't work
2 participants
@flavorjones@kddnewton

[8]ページ先頭

©2009-2025 Movatter.jp