Compare commits

..

3 commits

Author SHA1 Message Date
Julius 6536c099e1
Remove lwb generated files 2022-07-08 12:23:08 +02:00
Julius bd19c832cf
Operator presedence works 🎉 2022-07-08 12:13:24 +02:00
Julius e03f3088d2
Try to get lwb-parser to work 2022-07-08 12:10:55 +02:00
8 changed files with 705 additions and 16 deletions

2
.gitignore vendored
View file

@ -1 +1,3 @@
/target
src/sunflower/*
!src/sunflower/.gitkeep

504
Cargo.lock generated
View file

@ -2,6 +2,71 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
dependencies = [
"memchr",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]]
name = "block-buffer"
version = "0.7.3"
@ -23,6 +88,12 @@ dependencies = [
"byte-tools",
]
[[package]]
name = "by_address"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e245704f60eb4eb45810d65cf14eb54d2eb50a6f3715fe2d7cd01ee905c2944f"
[[package]]
name = "byte-tools"
version = "0.3.1"
@ -35,6 +106,56 @@ version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"winapi",
]
[[package]]
name = "convert_case"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "convert_case"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb4a24b1aaf0fd0ce8b45161144d6f42cd91677fd5940fd431183eb023b3a2b8"
[[package]]
name = "derive_more"
version = "0.99.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
dependencies = [
"convert_case 0.4.0",
"proc-macro2",
"quote",
"rustc_version",
"syn",
]
[[package]]
name = "digest"
version = "0.8.1"
@ -50,6 +171,32 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "140206b78fb2bc3edbcfc9b5ccbd0b30699cfe8d348b8b31b330e47df5291a5a"
[[package]]
name = "either"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be"
[[package]]
name = "enum-iterator"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eeac5c5edb79e4e39fe8439ef35207780a11f69c52cbe424ce3dfad4cb78de6"
dependencies = [
"enum-iterator-derive",
]
[[package]]
name = "enum-iterator-derive"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c134c37760b27a871ba422106eedbb8247da973a09e82558bf26d619c882b159"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
@ -65,18 +212,168 @@ dependencies = [
"typenum",
]
[[package]]
name = "gimli"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "is_ci"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb"
[[package]]
name = "itertools"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
dependencies = [
"either",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
[[package]]
name = "lwb-parser"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2979cd39b4c303b9943535680650d59a1b940212e69ad26b97e3e675cc6f308d"
dependencies = [
"bincode",
"by_address",
"chrono",
"convert_case 0.5.0",
"derive_more",
"enum-iterator",
"itertools",
"lazy_static",
"miette",
"proc-macro2",
"quote",
"serde",
"thiserror",
"toml",
"typed-arena",
]
[[package]]
name = "maplit"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "miette"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd2adcfcced5d625bf90a958a82ae5b93231f57f3df1383fee28c9b5096d35ed"
dependencies = [
"atty",
"backtrace",
"miette-derive",
"once_cell",
"owo-colors",
"supports-color",
"supports-hyperlinks",
"supports-unicode",
"terminal_size",
"textwrap",
"thiserror",
]
[[package]]
name = "miette-derive"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c01a8b61312d367ce87956bb686731f87e4c6dd5dbc550e8f06e3c24fb1f67f"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "miniz_oxide"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc"
dependencies = [
"adler",
]
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]]
name = "object"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
[[package]]
name = "opaque-debug"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
name = "owo-colors"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b"
[[package]]
name = "pest"
version = "2.1.3"
@ -138,6 +435,64 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc_version"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
]
[[package]]
name = "semver"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1"
[[package]]
name = "serde"
version = "1.0.138"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.138"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "sha-1"
version = "0.8.2"
@ -150,15 +505,50 @@ dependencies = [
"opaque-debug",
]
[[package]]
name = "smawk"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043"
[[package]]
name = "sunflower"
version = "0.1.0"
dependencies = [
"dyn-clone",
"lwb-parser",
"pest",
"pest_derive",
]
[[package]]
name = "supports-color"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4872ced36b91d47bae8a214a683fe54e7078875b399dfa251df346c9b547d1f9"
dependencies = [
"atty",
"is_ci",
]
[[package]]
name = "supports-hyperlinks"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "590b34f7c5f01ecc9d78dba4b3f445f31df750a67621cf31626f3b7441ce6406"
dependencies = [
"atty",
]
[[package]]
name = "supports-unicode"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8b945e45b417b125a8ec51f1b7df2f8df7920367700d1f98aedd21e5735f8b2"
dependencies = [
"atty",
]
[[package]]
name = "syn"
version = "1.0.98"
@ -170,6 +560,73 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "terminal_size"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "textwrap"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
dependencies = [
"smawk",
"unicode-linebreak",
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi",
"winapi",
]
[[package]]
name = "toml"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
dependencies = [
"serde",
]
[[package]]
name = "typed-arena"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae"
[[package]]
name = "typenum"
version = "1.15.0"
@ -178,12 +635,55 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]]
name = "ucd-trie"
version = "0.1.3"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c"
[[package]]
name = "unicode-ident"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
[[package]]
name = "unicode-linebreak"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a52dcaab0c48d931f7cc8ef826fa51690a08e1ea55117ef26f89864f532383f"
dependencies = [
"regex",
]
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View file

@ -2,11 +2,16 @@
name = "sunflower"
version = "0.1.0"
edition = "2021"
build = "src/build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dyn-clone = "1.0.6"
lwb-parser = "0.1.3"
pest = "2.1.3"
pest_derive = "2.1.0"
[build-dependencies]
lwb-parser = "0.1.3"

9
lwb.toml Normal file
View file

@ -0,0 +1,9 @@
[syntax]
definition = "src/sunflower.syntax"
destination = "src/sunflower"
serde = true
[language]
name = "Sunflower"
extensions = ["sunflower", "sfl"]

6
src/build.rs Normal file
View file

@ -0,0 +1,6 @@
use lwb_parser::codegen::manager::Codegen;
fn main() {
let m = Codegen::new();
m.codegen();
}

View file

@ -1,10 +1,9 @@
use std::{
any::Any,
fs::read_to_string,
};
use std::{any::Any, fs::read_to_string};
use env::Env;
use expression::Expression;
use function::FunctionMap;
use lwb_parser::{codegen_prelude::AstInfo, language::Language, sources::source_file::SourceFile};
use statement::Statement;
use value::{custom::CustomValue, Value};
@ -18,6 +17,10 @@ mod value;
// mod parser;
mod pest_parser;
#[rustfmt::skip]
mod sunflower;
lwb_parser::language!(SFL at mod sunflower);
fn run(functions: &FunctionMap, statement: &Statement) {
let env = Env::new();
statement.eval(&env, functions);
@ -69,16 +72,120 @@ impl CustomValue for Foo {
}
fn main() {
let f = read_to_string("./test.foo").unwrap();
let (res, funcs) = pest_parser::parse(&f);
// let f = read_to_string("./test.foo").unwrap();
// let (res, funcs) = pest_parser::parse(&f);
let mut m = FunctionMap::new();
m.insert_holder(funcs);
m.insert_native("print", |a: &Value| {
println!("{}", a);
});
m.insert_native("waluigi", || "Waluigi");
m.insert_native("native_test", || Foo { x: 41 });
m.insert_native("other_foo", || Foo { x: 1 });
// m.insert_holder(funcs);
// m.insert_native("print", |a: &Value| {
// println!("{}", a);
// });
// m.insert_native("waluigi", || "Waluigi");
// m.insert_native("native_test", || Foo { x: 41 });
// m.insert_native("other_foo", || Foo { x: 1 });
run(&m, &res);
// run(&m, &res);
let res = SFL::try_parse(&SourceFile::new(
"
10 / 2 + 3 * 4;
",
"based.sfl",
))
.unwrap();
// println!("{:?}", res);
for r in res.1 {
if let sunflower::Statement::Expression(_, e) = r {
println!("{}", e.eval())
}
}
// for r in res.1 {
// r.eval(&Env::new(), &m)
// }
}
impl<M: AstInfo> sunflower::Expression<M> {
fn eval(&self) -> Value {
self.1.eval()
}
}
impl<M: AstInfo> sunflower::Equality<M> {
fn eval(&self) -> Value {
match self {
sunflower::Equality::Equal(_, lhs, rhs) => (lhs.eval() == rhs.eval()).into(),
sunflower::Equality::NotEqual(_, rhs, lhs) => (lhs.eval() != rhs.eval()).into(),
sunflower::Equality::Inequality(_, all) => all.eval(),
}
}
}
impl<M: AstInfo> sunflower::Inequality<M> {
fn eval(&self) -> Value {
match self {
sunflower::Inequality::LessThan(_, lhs, rhs) => (lhs.eval() < rhs.eval()).into(),
sunflower::Inequality::LessThanOrEqual(_, lhs, rhs) => {
(lhs.eval() <= rhs.eval()).into()
}
sunflower::Inequality::GreaterThan(_, lhs, rhs) => (lhs.eval() > rhs.eval()).into(),
sunflower::Inequality::GreaterThanOrEqual(_, lhs, rhs) => {
(lhs.eval() >= rhs.eval()).into()
}
sunflower::Inequality::Plus(_, all) => all.eval(),
}
}
}
impl<M: AstInfo> sunflower::Plus<M> {
fn eval(&self) -> Value {
match self {
sunflower::Plus::Plus(_, lhs, rhs) => {
println!("doing plus");
(lhs.eval() + rhs.eval()).into()
}
sunflower::Plus::Minus(_, lhs, rhs) => (lhs.eval() - rhs.eval()).into(),
sunflower::Plus::Times(_, all) => all.eval(),
}
}
}
impl<M: AstInfo> sunflower::Times<M> {
fn eval(&self) -> Value {
match self {
sunflower::Times::Times(_, lhs, rhs) => {
println!("doing times");
(lhs.eval() * rhs.eval()).into()
}
sunflower::Times::Divide(_, lhs, rhs) => {
println!("doing divide");
(lhs.eval() / rhs.eval()).into()
}
sunflower::Times::Value(_, all) => all.eval(),
}
}
}
impl<M: AstInfo> sunflower::Value<M> {
fn eval(&self) -> Value {
match self {
sunflower::Value::Const(_, c) => {
println!("doing const");
c.eval()
}
sunflower::Value::Call(_, _) => todo!(),
sunflower::Value::Identifier(_, _) => todo!(),
sunflower::Value::Parens(_, inner) => inner.eval(),
}
}
}
impl<M: AstInfo> sunflower::ConstValue<M> {
fn eval(&self) -> Value {
match self {
sunflower::ConstValue::Int(_, i) => i.1.parse::<i32>().unwrap().into(),
sunflower::ConstValue::Bool(_, b) => match b {
sunflower::Bool::True(_) => true.into(),
sunflower::Bool::False(_) => false.into(),
},
sunflower::ConstValue::String(_, _) => todo!(),
sunflower::ConstValue::Char(_, _) => todo!(),
}
}
}

60
src/sunflower.syntax Normal file
View file

@ -0,0 +1,60 @@
identifier = [A-Za-z_][A-Za-z0-9-_]*; {single-string, no-layout}
string = "\"" [^\"]* "\""; {single-string, no-layout}
char = "'" [^\'] "'"; {single-string, no-layout}
int = [0-9]+; {single-string, no-layout}
bool:
true = "true";
false = "false";
const_value:
int = int;
bool = bool;
string = string;
char = char;
call = identifier "(" delimited(expression, ",", *) ")";
value:
const = const_value;
call = call;
identifier = identifier;
parens = "(" expression ")";
equality:
equal = inequality "==" inequality;
not_equal = inequality "!=" inequality;
inequality = inequality;
inequality:
less_than = plus "<" plus;
less_than_or_equal = plus "<=" plus;
greater_than = plus ">" plus;
greater_than_or_equal = plus ">=" plus;
plus = plus;
expression:
equality = equality;
plus:
plus = times "+" times;
minus = times "-" times;
times = times;
times:
times = value "*" value;
divide = value "/" value;
value = value;
statement:
expression = expression ";";
let = "let" identifier "=" expression ";";
program = statement*;
start at program;
layout = [\r\n\t ];

0
src/sunflower/.gitkeep Normal file
View file