Unnamed repository; edit this file 'description' to name the repository.
More specific error for leading pipes
ammkrn 2021-06-20
parent 4b2938c · commit 67df3a6
-rw-r--r--lib/ungrammar/Cargo.toml2
-rw-r--r--lib/ungrammar/src/parser.rs8
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/ungrammar/Cargo.toml b/lib/ungrammar/Cargo.toml
index 56dbc825fa..18c9dffecf 100644
--- a/lib/ungrammar/Cargo.toml
+++ b/lib/ungrammar/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "ungrammar"
description = "A DSL for describing concrete syntax trees"
-version = "1.14.0"
+version = "1.14.1"
license = "MIT OR Apache-2.0"
repository = "https://github.com/matklad/ungrammar"
authors = ["Aleksey Kladov <[email protected]>"]
diff --git a/lib/ungrammar/src/parser.rs b/lib/ungrammar/src/parser.rs
index bd067f22a5..a4ce9c1202 100644
--- a/lib/ungrammar/src/parser.rs
+++ b/lib/ungrammar/src/parser.rs
@@ -109,6 +109,14 @@ fn node(p: &mut Parser) -> Result<()> {
}
fn rule(p: &mut Parser) -> Result<Rule> {
+ if let Some(lexer::Token { kind: TokenKind::Pipe, loc }) = p.peek() {
+ bail!(
+ *loc,
+ "The first element in a sequence of productions or alternatives \
+ must not have a leading pipe (`|`)"
+ );
+ }
+
let lhs = seq_rule(p)?;
let mut alt = vec![lhs];
while let Some(token) = p.peek() {