35: More specific error for leading pipes r=matklad a=ammkrn

Re: rust-analyzer/ungrammar#34; return a more detailed error message when counting an improperly placed leading pipe.

Co-authored-by: ammkrn <ammkrn@tuta.io>
This commit is contained in:
bors[bot] 2021-06-19 18:11:59 +00:00 committed by GitHub
commit 4457576f49
2 changed files with 9 additions and 1 deletions

View File

@ -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 <aleksey.kladov@gmail.com>"]

View File

@ -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() {