From 907fe17b437be0c2d9d1262f94de9af629ab7832 Mon Sep 17 00:00:00 2001 From: able Date: Wed, 30 Aug 2023 20:15:24 -0500 Subject: [PATCH] Rhea ground work --- .gitignore | 1 + Cargo.lock | 95 ++++++++++++++++++++++++++++ Cargo.toml | 9 +++ assets/examples/func.rhea | 1 + assets/examples/library.rhea | 3 + assets/libraries/math/constants.rhea | 6 ++ assets/libraries/math/math.rhea | 1 + assets/libraries/std/io.rhea | 1 + assets/libraries/std/log.rhea | 5 ++ assets/libraries/std/std.rhea | 2 + rust-toolchain.toml | 3 + shell.nix | 36 +++++++++++ src/main.rs | 45 +++++++++++++ 13 files changed, 208 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 assets/examples/func.rhea create mode 100644 assets/examples/library.rhea create mode 100644 assets/libraries/math/constants.rhea create mode 100644 assets/libraries/math/math.rhea create mode 100644 assets/libraries/std/io.rhea create mode 100644 assets/libraries/std/log.rhea create mode 100644 assets/libraries/std/std.rhea create mode 100644 rust-toolchain.toml create mode 100644 shell.nix create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..5e1083d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,95 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "logos" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1" +dependencies = [ + "logos-derive", +] + +[[package]] +name = "logos-codegen" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68" +dependencies = [ + "beef", + "fnv", + "proc-macro2", + "quote", + "regex-syntax", + "syn", +] + +[[package]] +name = "logos-derive" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbfc0d229f1f42d790440136d941afd806bc9e949e2bcb8faa813b0f00d1267e" +dependencies = [ + "logos-codegen", +] + +[[package]] +name = "proc-macro2" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "rhea" +version = "0.1.0" +dependencies = [ + "logos", +] + +[[package]] +name = "syn" +version = "2.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..fa71c5f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rhea" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +logos = "*" diff --git a/assets/examples/func.rhea b/assets/examples/func.rhea new file mode 100644 index 0000000..f183b86 --- /dev/null +++ b/assets/examples/func.rhea @@ -0,0 +1 @@ +func main(){} \ No newline at end of file diff --git a/assets/examples/library.rhea b/assets/examples/library.rhea new file mode 100644 index 0000000..7786e46 --- /dev/null +++ b/assets/examples/library.rhea @@ -0,0 +1,3 @@ +var std = include "std"; + +func main(){} \ No newline at end of file diff --git a/assets/libraries/math/constants.rhea b/assets/libraries/math/constants.rhea new file mode 100644 index 0000000..50db5b9 --- /dev/null +++ b/assets/libraries/math/constants.rhea @@ -0,0 +1,6 @@ + +// measured in M/S +const C = 299_792_458; + +const pi = 3.141592653589793; +const tau = 6.283185307179586; \ No newline at end of file diff --git a/assets/libraries/math/math.rhea b/assets/libraries/math/math.rhea new file mode 100644 index 0000000..8e22b41 --- /dev/null +++ b/assets/libraries/math/math.rhea @@ -0,0 +1 @@ +var constants = include "constants"; \ No newline at end of file diff --git a/assets/libraries/std/io.rhea b/assets/libraries/std/io.rhea new file mode 100644 index 0000000..90f0d10 --- /dev/null +++ b/assets/libraries/std/io.rhea @@ -0,0 +1 @@ +var log = include "log"; \ No newline at end of file diff --git a/assets/libraries/std/log.rhea b/assets/libraries/std/log.rhea new file mode 100644 index 0000000..3237ccb --- /dev/null +++ b/assets/libraries/std/log.rhea @@ -0,0 +1,5 @@ +func error(){} +func warn(){} +func info(){} +func debug(){} +func trace(){} \ No newline at end of file diff --git a/assets/libraries/std/std.rhea b/assets/libraries/std/std.rhea new file mode 100644 index 0000000..4b29b34 --- /dev/null +++ b/assets/libraries/std/std.rhea @@ -0,0 +1,2 @@ +var io = include "std.io"; +var math = include "math" \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..ecc21cc --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" +components = ["rust-src", "llvm-tools"] diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..91430a3 --- /dev/null +++ b/shell.nix @@ -0,0 +1,36 @@ +{ pkgs ? import { } }: +pkgs.mkShell rec { + buildInputs = with pkgs; [ + clang + llvmPackages.bintools + rustup + ]; + extraCmds = ''''; + RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain.toml; + # https://github.com/rust-lang/rust-bindgen#environment-variables + LIBCLANG_PATH = + pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ]; + shellHook = '' + export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin + export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/ + ''; + # Add precompiled library to rustc search path + RUSTFLAGS = (builtins.map (a: "-L ${a}/lib") [ + # add libraries here (e.g. pkgs.libvmi) + ]); + # Add glibc, clang, glib and other headers to bindgen search path + BINDGEN_EXTRA_CLANG_ARGS = + # Includes with normal include path + (builtins.map (a: ''-I"${a}/include"'') [ + # add dev libraries here (e.g. pkgs.libvmi.dev) + pkgs.glibc.dev + ]) + # Includes with special directory paths + ++ [ + '' + -I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"'' + ''-I"${pkgs.glib.dev}/include/glib-2.0"'' + "-I${pkgs.glib.out}/lib/glib-2.0/include/" + ]; + +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..7e5a8e1 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,45 @@ +// Rhea + +use logos::Logos; + +#[derive(Logos, Debug, PartialEq)] +#[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens +enum Token { + #[token(".")] + Period, + + #[token("(")] + LeftParen, + + #[token("{")] + LeftBrace, + + #[token(")")] + RightParen, + + #[token("}")] + RightBrace, + + #[token("include")] + Include, + + #[token("=")] + Equals, + + #[token(";")] + Semicolon, + + #[token("\"")] + Quote, + + // Or regular expressions. + #[regex("[a-zA-Z]+")] + Text, +} + +fn main() { + let mut lex = Token::lexer(include_str!("../assets/examples/library.rhea")); + for x in lex { + println!("{:?}", x); + } +}