liveview-native / live_view_native_stylesheet

MIT License
10 stars 4 forks source link

Parsing failure message does not print multi-line modifiers #51

Closed jtormey closed 4 months ago

jtormey commented 7 months ago

Given an invalid multi-line modifier like this:

  "sheet" do
    sheet(
      asdf: "<- invalid",
      isPresented: attr("presented"),
      onDismiss: event("sheet_dismiss"),
      content: :sheet_content
    )
  end

The following message will print in the Xcode console:

Stylesheet parsing failed for modifier `sheet` in class `sheet`:

  |
0 | 
  | ^ No matching clause found for modifier `sheet`. Expected `sheet(isPresented:onDismiss:content:)`

in  (:0)

It would be nice for debugging if the full modifier call were printed.

bcardarella commented 4 months ago

@NduatiK how much of a lift would it be to support multiline rules? I believe we are currently splitting on \n and parsing each individually.

bcardarella commented 4 months ago

I bet I could repurpose the code I'm writing for the interpolation update. It just really requires a byte processor to detect when a rule's ( and ) terminate and using that as the point to split on. I may try to solve this tonight

NduatiK commented 4 months ago

@NduatiK how much of a lift would it be to support multiline rules? I believe we are currently splitting on \n and parsing each individually.

We are not splitting on \n. I believe we use whitespace and ignore_whitespace to be agnostic on the delimiter between things. We know that a rule has ended if it has the expected structure: "..." do ... end.


That said, annotations could do with some work though, the rule in the original issue produces the following AST. The :sheet source should capture everything in the original snippet instead of just capturing the line and source of the closing )

"sheet" => [
    {:sheet, [file: "mock_sheet.ex", line: 10, module: MockSheet, source: ")"],
     [
       [
         asdf: "<- invalid",
         isPresented:
           {:__attr__,
            [
              file: "mock_sheet.ex",
              line: 7,
              module: MockSheet,
              source: "isPresented: attr(\"presented\"),"
            ], "presented"},
         onDismiss:
           {:__event__,
            [
              file: "mock_sheet.ex",
              line: 8,
              module: MockSheet,
              source: "onDismiss: event(\"sheet_dismiss\"),"
            ], ["sheet_dismiss", []]},
         content: :sheet_content
       ]
     ]}
  ]
NduatiK commented 4 months ago

@bcardarella, could you also run this with the latest swiftui to see if the issue is still there?

I suspect that the swiftui side is detecting an invalid key on asdf: "<- invalid" and failing to show the location because kv pairs do not have annotations. In that case, it might also be useful to have the swift ui parser climb up the ast to find annotations higher up the tree, in this case, asdf: "<- invalid" should use sheets annotations

bcardarella commented 4 months ago

@NduatiK you are correct, this works perfect fine. Thanks, closing as a non-issue for main