parser: reject closing delims that look like an op

This commit is contained in:
René Kijewski 2024-08-13 10:27:28 +02:00
parent d5710c9d4b
commit e4c5ca3f6b
5 changed files with 58 additions and 0 deletions

View File

@ -360,6 +360,26 @@ impl<'a> RawSyntax<'a> {
}
}
for end in [syntax.block_end, syntax.expr_end, syntax.comment_end] {
for prefix in ["<<", ">>", "&&", "..", "||"] {
if end.starts_with(prefix) {
let msg = if end == prefix {
format!("a closing delimiter must not start with an operator: {end:?}")
} else {
format!(
"a closing delimiter must not start an with operator: \
{end:?} starts with {prefix:?}",
)
};
return Err(CompileError::new_with_span(
msg,
file_info.copied(),
config_span,
));
}
}
}
Ok(syntax)
}
}

4
testing/issue-128-2.toml Normal file
View File

@ -0,0 +1,4 @@
[[syntax]]
name = "mwe"
expr_start = "<<<"
expr_end = ">>>"

4
testing/issue-128.toml Normal file
View File

@ -0,0 +1,4 @@
[[syntax]]
name = "mwe"
expr_start = "<<"
expr_end = ">>"

View File

@ -0,0 +1,17 @@
use rinja::Template;
#[derive(Template)]
#[template(source = "<<a>> and <<b>>", config = "issue-128.toml", syntax = "mwe", ext="")]
struct HelloTemplate {
a: u32,
b: u32,
}
#[derive(Template)]
#[template(source = "<<a>> and <<b>>", config = "issue-128-2.toml", syntax = "mwe", ext="")]
struct HelloTemplate2 {
a: u32,
b: u32,
}
fn main() {}

View File

@ -0,0 +1,13 @@
error: a closing delimiter must not start with an operator: ">>"
--> testing/issue-128.toml
--> tests/ui/terminator-operator.rs:4:49
|
4 | #[template(source = "<<a>> and <<b>>", config = "issue-128.toml", syntax = "mwe", ext="")]
| ^^^^^^^^^^^^^^^^
error: a closing delimiter must not start an with operator: ">>>" starts with ">>"
--> testing/issue-128-2.toml
--> tests/ui/terminator-operator.rs:11:49
|
11 | #[template(source = "<<a>> and <<b>>", config = "issue-128-2.toml", syntax = "mwe", ext="")]
| ^^^^^^^^^^^^^^^^^^