From 09867c48cafab00c2a93cd7aaf5f93594c361883 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 1 Jul 2024 11:24:18 -0700 Subject: [PATCH] Pest parser WIP --- Cargo.lock | 53 +++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/justfile.pest | 9 ++++++++ src/parser.rs | 11 ++++++++++ 4 files changed, 75 insertions(+) create mode 100644 src/justfile.pest diff --git a/Cargo.lock b/Cargo.lock index 5ceb6c1..3d8e10c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -613,6 +613,8 @@ dependencies = [ "log", "num_cpus", "percent-encoding", + "pest", + "pest_derive", "pretty_assertions", "rand", "regex", @@ -737,6 +739,51 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pest" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26293c9193fbca7b1a3bf9b79dc1e388e927e6cacaa78b4a3ab705a1d3d41459" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ec22af7d3fb470a85dd2ca96b7c577a1eb4ef6f1683a9fe9a8c16e136c04687" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "pest_meta" +version = "2.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a240022f37c361ec1878d646fc5b7d7c4d28d5946e1a80ad5a7a4f4ca0bdcd" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1198,6 +1245,12 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + [[package]] name = "unicase" version = "2.7.0" diff --git a/Cargo.toml b/Cargo.toml index 9e9f0e3..c4c8e9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,8 @@ libc = "0.2.0" log = "0.4.4" num_cpus = "1.15.0" percent-encoding = "2.3.1" +pest = "2.7.10" +pest_derive = "2.7.10" rand = "0.8.5" regex = "1.10.4" semver = "1.0.20" diff --git a/src/justfile.pest b/src/justfile.pest new file mode 100644 index 0000000..23cfec6 --- /dev/null +++ b/src/justfile.pest @@ -0,0 +1,9 @@ + +identifier = { (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")+ } + +recipe = { identifier ~ ":" ~ NEWLINE ~ recipe_body } + +recipe_body = { recipe_line* } + +recipe_line = { + diff --git a/src/parser.rs b/src/parser.rs index b1d088e..70b43aa 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -36,7 +36,18 @@ pub(crate) struct Parser<'run, 'src> { working_directory: &'run Path, } +#[derive(pest_derive::Parser)] +#[grammar = "justfile.pest"] +struct JustfileParser; + impl<'run, 'src> Parser<'run, 'src> { + + pub(crate) fn parse_new(path: &'src Path, src: &'src str) -> CompileResult<'src, Ast<'src>> { + + todo!() + } + + /// Parse `tokens` into an `Ast` pub(crate) fn parse( file_depth: u32,