diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-24 23:23:45 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-24 23:38:34 +0200 |
commit | fe4ce14fe64ab05318c0c66317a6d4f5578127fc (patch) | |
tree | ca5b81f3ab176abbb93673bbd8e2a4bb8e417fd9 | |
parent | 481e423ab99bdece32dba6f526d902799702e9d7 (diff) | |
download | rebel-fe4ce14fe64ab05318c0c66317a6d4f5578127fc.tar rebel-fe4ce14fe64ab05318c0c66317a6d4f5578127fc.zip |
rebel-parse: token: remove Ident struct
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 4 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/tokenize.rs | 6 | ||||
-rw-r--r-- | 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<T>(expr: rule<T>, delim: rule<()>) -> Vec<T> = 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,14 +1,11 @@ #[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); #[derive(Clone, Copy, Debug, PartialEq, Eq)] |