diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-01 00:09:30 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-01 00:09:30 +0200 |
commit | cc318d3e7ee1006e98994f7d2e382a0a69445893 (patch) | |
tree | f814c73152086730338874716a91808057612a80 /crates/rebel-parse/src/grammar | |
parent | aa74f757abdabc386b76858f8a3c0babdb478a0b (diff) | |
download | rebel-cc318d3e7ee1006e98994f7d2e382a0a69445893.tar rebel-cc318d3e7ee1006e98994f7d2e382a0a69445893.zip |
rebel-parse: add support for different path roots
Distinguish relative (unprefixed), absolute (`::` prefix) and
section-specific (`recipe::`, `task::`) paths.
Diffstat (limited to 'crates/rebel-parse/src/grammar')
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 13 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/tokenize.rs | 1 |
2 files changed, 13 insertions, 1 deletions
diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index b1ac32f..50a0694 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -164,7 +164,18 @@ peg::parser! { } rule path() -> ast::Path<'a> - = components:ident() ++ p2(':', ':') { ast::Path { components } } + = components:(ident() ++ p2(':', ':')) { + ast::Path { root: ast::PathRoot::Relative, components } + } + / components:(p2(':', ':') ident:ident() { ident })+ { + ast::Path { root: ast::PathRoot::Absolute, components } + } + / [Token::Keyword(Keyword::Recipe)] components:(p2(':', ':') ident:ident() { ident })* { + ast::Path { root: ast::PathRoot::Recipe, components } + } + / [Token::Keyword(Keyword::Task)] components:(p2(':', ':') ident:ident() { ident })* { + ast::Path { root: ast::PathRoot::Task, components } + } rule field() -> ast::Ident<'a> = ident() diff --git a/crates/rebel-parse/src/grammar/tokenize.rs b/crates/rebel-parse/src/grammar/tokenize.rs index 8696a89..70df2c3 100644 --- a/crates/rebel-parse/src/grammar/tokenize.rs +++ b/crates/rebel-parse/src/grammar/tokenize.rs @@ -8,6 +8,7 @@ static KEYWORDS: phf::Map<&'static str, Keyword> = phf::phf_map! { "let" => Keyword::Let, "map" => Keyword::Map, "mut" => Keyword::Mut, + "recipe" => Keyword::Recipe, "set" => Keyword::Set, "struct" => Keyword::Struct, "task" => Keyword::Task, |