Skip to content

Commit

Permalink
Start of an implementation of an elm parser in rust
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianReeves committed May 31, 2024
1 parent f3978d0 commit 5d6388a
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[workspace]
resolver = "2"
members = ["apps/cli", "crates/morphir-runtime", "crates/morphir-runtime-wasm"]
members = [
"apps/cli",
"crates/morphir-elm-compiler-rs",
"crates/morphir-runtime",
"crates/morphir-runtime-wasm",
]
default-members = ["crates/morphir-runtime"]

[workspace.package]
Expand Down Expand Up @@ -36,6 +41,8 @@ linked-data = "0.1.2"
miette = "7.2.0"
once_cell = "1.19.0"
proptest = "1.4.0"
pest = "2.6"
pest_derive = "2.6"
quickjs-wasm-rs = "3.0.0"
ractor = "0.10.3"
rdf-types = "0.22.4"
Expand Down
30 changes: 30 additions & 0 deletions crates/morphir-elm-compiler-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "morphir-elm-compiler-rs"
version.workspace = true
description = "Morphir runtime"
homepage.workspace = true
keywords = ["morphir", "finos"]
authors.workspace = true
license.workspace = true
edition.workspace = true

[badges]
maintnance = { status = "actively-developer" }

[[bin]]
name = "morphir-elmc"
path = "src/main.rs"

[lib]
name = "morphir_elm_compiler_rs"
path = "src/lib.rs"

[features]

[dependencies]
tokio.workspace = true
pest.workspace = true
pest_derive.workspace = true

[build-dependencies]
deno_core.workspace = true
1 change: 1 addition & 0 deletions crates/morphir-elm-compiler-rs/moon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: rust
5 changes: 5 additions & 0 deletions crates/morphir-elm-compiler-rs/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use pest_derive::Parser;

#[derive(Parser)]
#[grammar = "elm.pest"]
pub struct ElmParser;
12 changes: 12 additions & 0 deletions crates/morphir-elm-compiler-rs/src/elm.pest
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Parsing rules for the Elm programming language.

exposing_clause = { "exposing" ~ WHITE_SPACE ~ "(..)" }
// TODO: Relax the casing in parsing and produce an error about improper casing in a later stage
module_path_part = { (ASCII_ALPHA_UPPER ~ (ASCII_ALPHA | ASCII_DIGIT)*) }
module_statement = { "module" ~ WHITE_SPACE ~ module_path ~ WHITE_SPACE ~ (exposing_clause) }
module_path = { module_path_part ~ ("." ~ module_path)* }
statement = { module_statement ~ trivia* }
file = { SOI ~ statement ~ EOI }
INLINE_COMMENT = { "--" ~ (!NEWLINE ~ ANY)* ~ NEWLINE }
COMMENT = { INLINE_COMMENT }
trivia = { WHITE_SPACE | COMMENT }
1 change: 1 addition & 0 deletions crates/morphir-elm-compiler-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod compiler;
13 changes: 13 additions & 0 deletions crates/morphir-elm-compiler-rs/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub(crate) mod compiler;

use crate::compiler::{ElmParser, Rule};
use pest::Parser;

fn main() {
let file_contents: &'static str = r#"module Com.Example.Main exposing (..)
-- This is a comment
-- This is also a comment
"#;
let successful_parse = ElmParser::parse(Rule::file, &file_contents);
println!("{:?}", successful_parse);
}

0 comments on commit 5d6388a

Please sign in to comment.