From 67df3a69238ef159df63340a40dc3d0cd88c6992 Mon Sep 17 00:00:00 2001 From: ammkrn Date: Sat, 19 Jun 2021 11:29:31 -0500 Subject: [PATCH] More specific error for leading pipes --- lib/ungrammar/Cargo.toml | 2 +- lib/ungrammar/src/parser.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 "] 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 { + 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() {