mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
Compare commits
No commits in common. "4413226affbb91a64730afd9bb4589428097ba81" and "d9fdaee75412e31ae1313a0f1fab79d9cc395d0e" have entirely different histories.
4413226aff
...
d9fdaee754
|
@ -1,2 +0,0 @@
|
||||||
ko_fi: azur1s
|
|
||||||
github: azur1s
|
|
15
README.md
15
README.md
|
@ -1,15 +0,0 @@
|
||||||
<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));
|
||||||
println(16---1*3/-16+8%-2);
|
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,8 +2,6 @@
|
||||||
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};
|
||||||
|
|
||||||
|
@ -17,23 +15,34 @@ 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<_>>();
|
||||||
|
|
||||||
let mut file = std::fs::File::create("out.js").expect("Failed to create file");
|
for expr in &jsexprs {
|
||||||
let s = jsexprs
|
let s = format!("{}", expr);
|
||||||
.into_iter()
|
println!("{}{}", s, if s.ends_with(';') { "" } else { ";" });
|
||||||
.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