Skip to content

Commit

Permalink
feat: modernize parser (#412)
Browse files Browse the repository at this point in the history
* feat: modernize parser

* feat: recoverable parsing!

* chore: fix lints

* chore: update docs Cargo.lock

* fix: make kw error recoverable

* fix: consolidate error handling

* fix: trybuild $DIR placeholder

* chore: make some parsing more robust

* chore: refactor some stuff

* fix: add test for `@let` without block, fix spans for error

* Allow ints as literals in test

---------

Co-authored-by: Chris Wong <[email protected]>
  • Loading branch information
vidhanio and lambda-fairy authored Jan 6, 2025
1 parent 1d22a47 commit 31d3792
Show file tree
Hide file tree
Showing 11 changed files with 1,292 additions and 390 deletions.
29 changes: 9 additions & 20 deletions docs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion maud/tests/warnings/attribute-missing-value.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unexpected end of input
error: unexpected end of input, expected one of: curly braces, literal, parentheses, identifier, `.`, `#`, `@`, `;`
--> $DIR/attribute-missing-value.rs:4:5
|
4 | / html! {
Expand Down
2 changes: 1 addition & 1 deletion maud/tests/warnings/class-shorthand-missing-value.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unexpected end of input
error: unexpected end of input, expected one of: curly braces, literal, parentheses, identifier, `.`, `#`, `@`, `;`
--> $DIR/class-shorthand-missing-value.rs:4:5
|
4 | / html! {
Expand Down
9 changes: 9 additions & 0 deletions maud/tests/warnings/let-without-block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use maud::html;

fn main() {
html! {
p.@let x = 1; {
(x)
}
};
}
5 changes: 5 additions & 0 deletions maud/tests/warnings/let-without-block.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: `@let` bindings are only allowed inside blocks
--> tests/warnings/let-without-block.rs:5:11
|
5 | p.@let x = 1; {
| ^^^^^^^^^^^
2 changes: 1 addition & 1 deletion maud/tests/warnings/non-closed-element.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: expected `;`, found end of macro
error: unexpected end of input, expected one of: identifier, literal, `.`, `#`, curly braces, `;`
--> $DIR/non-closed-element.rs:4:5
|
4 | / html! {
Expand Down
20 changes: 4 additions & 16 deletions maud/tests/warnings/non-string-literal.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
error: literal must be double-quoted: `"42"`
--> tests/warnings/non-string-literal.rs:5:9
|
5 | 42
| ^^

error: literal must be double-quoted: `"42usize"`
--> tests/warnings/non-string-literal.rs:6:9
|
6 | 42usize
| ^^^^^^^

error: literal must be double-quoted: `"42.0"`
--> tests/warnings/non-string-literal.rs:7:9
|
Expand All @@ -35,19 +23,19 @@ error: expected string
| ^^^^

error: attribute value must be a string
--> tests/warnings/non-string-literal.rs:13:24
--> tests/warnings/non-string-literal.rs:13:15
|
13 | input disabled=true;
| ^^^^
| ^^^^^^^^^^^^^
|
= help: to declare an empty attribute, omit the equals sign: `disabled`
= help: to toggle the attribute, use square brackets: `disabled[some_boolean_flag]`

error: attribute value must be a string
--> tests/warnings/non-string-literal.rs:14:24
--> tests/warnings/non-string-literal.rs:14:15
|
14 | input disabled=false;
| ^^^^^
| ^^^^^^^^^^^^^^
|
= help: to declare an empty attribute, omit the equals sign: `disabled`
= help: to toggle the attribute, use square brackets: `disabled[some_boolean_flag]`
4 changes: 2 additions & 2 deletions maud_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ repository.workspace = true
edition.workspace = true

[dependencies]
syn = "2"
syn = { version = "2", features = ["extra-traits", "full"] }
quote = "1.0.7"
proc-macro2 = "1.0.23"
proc-macro-error = { version = "1.0.0", default-features = false }
proc-macro2-diagnostics = { version = "0.10", default-features = false }

[lib]
name = "maud_macros"
Expand Down
Loading

0 comments on commit 31d3792

Please sign in to comment.