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

Nesting selectors in a selector list causes a stylesheet error #3969

Closed
davep opened this issue Jan 6, 2024 · 5 comments · Fixed by #4040
Closed

Nesting selectors in a selector list causes a stylesheet error #3969

davep opened this issue Jan 6, 2024 · 5 comments · Fixed by #4040
Assignees
Labels
bug Something isn't working question Further information is requested Task

Comments

@davep
Copy link
Contributor

davep commented Jan 6, 2024

If you have a stylesheet like this:

from textual.app import App, ComposeResult
from textual.widgets import Label

class NestedCSSTokenErrorApp(App[None]):

    CSS = """
    Label {
        &.foo, &.bar {
            border: solid red;
        }
    }
    """

    def compose(self) -> ComposeResult:
        yield Label("This is class foo", classes="foo")
        yield Label("This is class bar", classes="bar")

if __name__ == "__main__":
    NestedCSSTokenErrorApp().run()

the result is:

Error in stylesheet:
 /Users/davep/develop/python/textual-sandbox/nested_css_token_error.py, NestedCSSTokenErrorApp.CSS:3:16
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│   1 │                                                                                                                                               │
│   2 │   Label {                                                                                                                                     │
│ ❱ 3 │   │   &.foo, &.bar {                                                                                                                          │
│   4 │   │   │   border: solid red;                                                                                                                  │
│   5 │   │   }                                                                                                                                       │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
 • Expected selector or { (found '&.bar {').                                                                                                           
 • Did you forget a semicolon at the end of a line? 

This feels like a bug given that it's a slightly different way of writing this:

from textual.app import App, ComposeResult
from textual.widgets import Label

class NestedCSSTokenErrorApp(App[None]):

    CSS = """
    Label {
        &.foo {
            border: solid red;
        }
        &.bar {
            border: solid red;
        }
    }
    """

    def compose(self) -> ComposeResult:
        yield Label("This is class foo", classes="foo")
        yield Label("This is class bar", classes="bar")

if __name__ == "__main__":
    NestedCSSTokenErrorApp().run()

Tagging @willmcgugan for triage.

@davep davep added bug Something isn't working question Further information is requested Task labels Jan 6, 2024
davep added a commit to davep/textual-sandbox that referenced this issue Jan 6, 2024
@willmcgugan
Copy link
Collaborator

To whomever picks this up, talk to @willmcgugan if you need pointers on this.

@rodrigogiraoserrao
Copy link
Contributor

rodrigogiraoserrao commented Jan 16, 2024

@willmcgugan if you had to guess would you say this will involve modifying the tokenizer state machine?

@willmcgugan
Copy link
Collaborator

Yes, I think so. If I were to guess, the comma token causes the tokenizer to switch to an Expect that doesn't include the nesting operator.

@rodrigogiraoserrao rodrigogiraoserrao self-assigned this Jan 17, 2024
@rodrigogiraoserrao
Copy link
Contributor

I'll take a stab at this. I wouldn't put it past me to take more than today to fix this if I happen to struggle with understanding how the tokenizer state machine works.

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants