From fe4ce14fe64ab05318c0c66317a6d4f5578127fc Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 24 Apr 2024 23:23:45 +0200 Subject: rebel-parse: token: remove Ident struct --- crates/rebel-parse/src/grammar/recipe.rs | 4 ++-- crates/rebel-parse/src/grammar/tokenize.rs | 6 +++--- crates/rebel-parse/src/token.rs | 5 +---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index 92ab7f8..d5400af 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -141,7 +141,7 @@ peg::parser! { = p_(ch1) p(ch2) rule ident() -> ast::Ident<'a> - = !keyword() [Token::Ident(Ident(name))] { ast::Ident { name } } + = !keyword() [Token::Ident(name)] { ast::Ident { name } } rule keyword() = keyword_true() @@ -159,7 +159,7 @@ peg::parser! { = const_ident("task") rule const_ident(keyword: &str) - = [Token::Ident(Ident(name)) if keyword == name] + = [Token::Ident(name) if keyword == name] rule delimited(expr: rule, delim: rule<()>) -> Vec = values:(expr() ++ delim()) delim()? { values } diff --git a/crates/rebel-parse/src/grammar/tokenize.rs b/crates/rebel-parse/src/grammar/tokenize.rs index a30e299..b497e23 100644 --- a/crates/rebel-parse/src/grammar/tokenize.rs +++ b/crates/rebel-parse/src/grammar/tokenize.rs @@ -12,11 +12,11 @@ peg::parser! { / ident:ident() { Token::Ident(ident) } / punct:punct() { Token::Punct(punct) } - rule ident() -> Ident<'input> - = name:$( + rule ident() -> &'input str + = $( ['a'..='z' | 'A' ..='Z' | '_' ] ['a'..='z' | 'A' ..='Z' | '_' | '0'..='9']* - ) { Ident(name) } + ) rule punct() -> Punct = ch:punct_char() spacing:spacing() { Punct(ch, spacing) } diff --git a/crates/rebel-parse/src/token.rs b/crates/rebel-parse/src/token.rs index 3147899..b985f74 100644 --- a/crates/rebel-parse/src/token.rs +++ b/crates/rebel-parse/src/token.rs @@ -1,13 +1,10 @@ #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Token<'a> { - Ident(Ident<'a>), + Ident(&'a str), Punct(Punct), Literal(Literal<'a>), } -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub struct Ident<'a>(pub &'a str); - #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Punct(pub char, pub Spacing); -- cgit v1.2.3