From 012d1e356b81a0702fda42c9bc44f6cbf55d19c9 Mon Sep 17 00:00:00 2001 From: Aron Zwaan Date: Fri, 24 Nov 2023 10:51:23 +0100 Subject: [PATCH] Fix doctest + better lex error message --- scopegraphs-regular-expressions/src/parse.rs | 9 +++++---- scopegraphs-regular-expressions/src/regex.rs | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scopegraphs-regular-expressions/src/parse.rs b/scopegraphs-regular-expressions/src/parse.rs index 40a2389..33a9690 100644 --- a/scopegraphs-regular-expressions/src/parse.rs +++ b/scopegraphs-regular-expressions/src/parse.rs @@ -185,10 +185,8 @@ impl<'a> Lexer<'a> { return Ok(Token::End); } - let lookahead = input.lookahead1(); - // Rust performs parenthesis matching: leverage that here. - if lookahead.peek(syn::token::Paren) { + if input.peek(syn::token::Paren) { let inner; parenthesized!(inner in input); return Regex::parse(&inner).map(|re| Token::Regex(Rc::new(re))); @@ -241,7 +239,10 @@ impl<'a> Lexer<'a> { return Ok(Token::And); } - Err(lookahead.error()) + Err(syn::Error::new( + input.span(), + "expected '0', 'e', '~', '*', '+', '?', '|', '&', '(' or label here.", + )) } /// Peeks the first token in the stream. diff --git a/scopegraphs-regular-expressions/src/regex.rs b/scopegraphs-regular-expressions/src/regex.rs index f4b5699..cff0ea1 100644 --- a/scopegraphs-regular-expressions/src/regex.rs +++ b/scopegraphs-regular-expressions/src/regex.rs @@ -173,6 +173,7 @@ impl Regex { /// Examples of this include the `e` itself, any 0-ary repeat `A*`, `e | A`, etc. /// /// ``` + /// # use scopegraphs_regular_expressions::Regex; /// assert!(Regex::EmptyString.is_nullable()) /// ``` pub fn is_nullable(&self) -> bool {