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

Track the source span for all nodes #42

Merged
merged 1 commit into from
Nov 12, 2022

Conversation

danheuck
Copy link
Contributor

@danheuck danheuck commented Nov 10, 2022

This updates the parser to keep track of the source span for each node as it is parsed, as suggested in #14. In nightly, this uses Span::join in nightly, while trying to provide a sensible "close enough" span in stable.

Example errors generated from these spans in nightly:

error: Invalid element
  --> test-app\src\main.rs:11:13
   |
11 |             <div/>
   |             ^^^^^^

error: Invalid element
  --> test-app\src\main.rs:14:13
   |
14 | /             <div>
15 | |                 "child"
16 | |             </div>
   | |__________________^

error: Invalid comment
  --> test-app\src\main.rs:19:13
   |
19 |             <!--"comment"-->
   |             ^^^^^^^^^^^^^^^^

error: Invalid doctype
  --> test-app\src\main.rs:22:13
   |
22 |             <!DOCTYPE rsx>
   |             ^^^^^^^^^^^^^^

error: Invalid fragment
  --> test-app\src\main.rs:25:13
   |
25 | /             <>
26 | |                 {stuff}
27 | |             </>
   | |_______________^

error: Invalid block
  --> test-app\src\main.rs:30:13
   |
30 | /             {
31 | |                 code
32 | |             }
   | |_____________^

error: Invalid block
  --> test-app\src\main.rs:35:13
   |
35 |             {inline}
   |             ^^^^^^^^

error: Invalid text
  --> test-app\src\main.rs:38:13
   |
38 |             "text"
   |             ^^^^^^

error: Invalid attribute
  --> test-app\src\main.rs:42:18
   |
42 |             <div key="value"/>
   |                  ^^^^^^^^^^^

and in stable:

error: Invalid element
  --> test-app\src\main.rs:11:14
   |
11 |             <div/>
   |              ^^^

error: Invalid element
  --> test-app\src\main.rs:14:14
   |
14 |             <div>
   |              ^^^

error: Invalid comment
  --> test-app\src\main.rs:19:17
   |
19 |             <!--"comment"-->
   |                 ^^^^^^^^^

error: Invalid doctype
  --> test-app\src\main.rs:22:23
   |
22 |             <!DOCTYPE rsx>
   |                       ^^^

error: Invalid fragment
  --> test-app\src\main.rs:25:13
   |
25 |             <>
   |             ^

error: Invalid block
  --> test-app\src\main.rs:30:13
   |
30 | /             {
31 | |                 code
32 | |             }
   | |_____________^

error: Invalid block
  --> test-app\src\main.rs:35:13
   |
35 |             {inline}
   |             ^^^^^^^^

error: Invalid text
  --> test-app\src\main.rs:38:13
   |
38 |             "text"
   |             ^^^^^^

error: Invalid attribute
  --> test-app\src\main.rs:42:18
   |
42 |             <div key="value"/>
   |                  ^^^

Resolves #14

stoically
stoically approved these changes Nov 12, 2022
Copy link
Owner

@stoically stoically left a comment

Choose a reason for hiding this comment

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

Great addition, thanks for working on it!

@stoically stoically merged commit 0013b1a into stoically:main Nov 12, 2022
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.

Node method to get span for the whole node
2 participants