mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
Compare commits
3 commits
d9fdaee754
...
4413226aff
Author | SHA1 | Date | |
---|---|---|---|
azur | 4413226aff | ||
azur | 5e09ed53e4 | ||
azur | 1ad99fcfa5 |
2
FUNDING.yml
Normal file
2
FUNDING.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ko_fi: azur1s
|
||||||
|
github: azur1s
|
15
README.md
Normal file
15
README.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<div align="center" style="display:grid;place-items:center;">
|
||||||
|
<h1>Holymer</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Holymer is a programming language
|
||||||
|
|
||||||
|
It's pretty boring right now so come back later :D
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
You need to have [Rust Toolchain](https://github.com/rust-lang/rust) installed on your machine before building it.
|
||||||
|
```shell
|
||||||
|
$ git clone https://github.com/azur1s/holymer.git
|
||||||
|
$ cd holymer
|
||||||
|
# build with `cargo build`
|
||||||
|
```
|
2
b.hlm
2
b.hlm
|
@ -1,5 +1,5 @@
|
||||||
println((\x: num -> x + 35)(34));
|
println((\x: num -> x + 35)(34));
|
||||||
16---1*3/-16+8%-2;
|
println(16---1*3/-16+8%-2);
|
||||||
|
|
||||||
let a: num = 1 in
|
let a: num = 1 in
|
||||||
println(a);
|
println(a);
|
||||||
|
|
39
src/main.rs
39
src/main.rs
|
@ -2,6 +2,8 @@
|
||||||
pub mod read;
|
pub mod read;
|
||||||
pub mod trans;
|
pub mod trans;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use read::parse::{lex, parse};
|
use read::parse::{lex, parse};
|
||||||
use trans::low::{translate_expr, translate_js};
|
use trans::low::{translate_expr, translate_js};
|
||||||
|
|
||||||
|
@ -15,34 +17,23 @@ fn main() {
|
||||||
let (ast, parse_errs) = parse(tokens, src.len());
|
let (ast, parse_errs) = parse(tokens, src.len());
|
||||||
|
|
||||||
if let Some(ast) = ast {
|
if let Some(ast) = ast {
|
||||||
println!();
|
|
||||||
println!("\x1b[90m───SOURCE─────────────────────────────────────────\x1b[0m");
|
|
||||||
println!("{src}");
|
|
||||||
println!("\x1b[90m───PARSE TREE─────────────────────────────────────\x1b[0m");
|
|
||||||
for (e, _) in &ast {
|
|
||||||
println!("{}", {
|
|
||||||
let e = format!("{:?}", e);
|
|
||||||
if e.len() > 50 {
|
|
||||||
format!("{}...", &e[..47])
|
|
||||||
} else {
|
|
||||||
e
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
println!("\x1b[90m───INTERNAL AST───────────────────────────────────\x1b[0m");
|
|
||||||
let nexprs = ast.into_iter().map(|(e, _)| translate_expr(e)).collect::<Vec<_>>();
|
let nexprs = ast.into_iter().map(|(e, _)| translate_expr(e)).collect::<Vec<_>>();
|
||||||
|
|
||||||
for expr in &nexprs {
|
|
||||||
println!("{}", expr);
|
|
||||||
}
|
|
||||||
println!("\x1b[90m───JS OUTPUT──────────────────────────────────────\x1b[0m");
|
|
||||||
let jsexprs = nexprs.into_iter().map(translate_js).collect::<Vec<_>>();
|
let jsexprs = nexprs.into_iter().map(translate_js).collect::<Vec<_>>();
|
||||||
|
|
||||||
for expr in &jsexprs {
|
let mut file = std::fs::File::create("out.js").expect("Failed to create file");
|
||||||
let s = format!("{}", expr);
|
let s = jsexprs
|
||||||
println!("{}{}", s, if s.ends_with(';') { "" } else { ";" });
|
.into_iter()
|
||||||
|
.map(|e| {
|
||||||
|
let s = format!("{}", e);
|
||||||
|
if s.ends_with(';') {
|
||||||
|
s
|
||||||
|
} else {
|
||||||
|
format!("{};", s)
|
||||||
}
|
}
|
||||||
println!();
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("\n");
|
||||||
|
file.write_all(s.as_bytes()).expect("Failed to write to file");
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_errs
|
parse_errs
|
||||||
|
|
Loading…
Reference in a new issue