Skip to content

Parse pseudo-class function arguments #62

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

Merged

Conversation

flavorjones
Copy link
Collaborator

Previously, PseudoClassFunction arguments were simply a copy of the Function token arguments. So from a selector of ".flex:not(div, span.wide, .hidden)", the not function would have these arguments in the AST:

[(ident-token "div"),
 (comma-token),
 (whitespace-token " "),
 (ident-token "span"),
 (delim-token "."),
 (ident-token "wide"),
 (comma-token),
 (whitespace-token " "),
 (delim-token "."),
 (ident-token "hidden")]

Now the arguments are parsed, so that a PseudoClassFunction is represented fully in the AST as something like:

(pseudo-class-selector
  (pseudo-class-function
    "not"
    (arguments
      (type-selector (wqname (ident-token "div"))),
      (compound-selector
        (type (type-selector (wqname (ident-token "span"))))
        (subclasses
          (class-selector (ident-token "wide"))
        )
        (pseudo-elements)
      ),
      (class-selector (ident-token "hidden"))
    )
  )
)

so that the AST doesn't just contain tokens. Previously the arguments
were something like

```
[(ident-token "div"),
 (comma-token),
 (whitespace-token " "),
 (ident-token "span"),
 (delim-token "."),
 (ident-token "wide"),
 (comma-token),
 (whitespace-token " "),
 (delim-token "."),
 (ident-token "hidden")]
```

Now those tokens will be represented in the AST as

```
[(type-selector (wqname (ident-token "div"))),
 (compound-selector
   (type (type-selector (wqname (ident-token "span"))))
   (subclasses
     (class-selector (ident-token "wide"))
   )
   (pseudo-elements)
 ),
 (class-selector (ident-token "hidden"))]
```
@kddnewton kddnewton merged commit 5b84ed8 into ruby-syntax-tree:main Jun 28, 2024
2 checks passed
@kddnewton
Copy link
Member

This is a clever way to do it!

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.

2 participants