1
1
Fork 0
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.

4 changed files with 26 additions and 34 deletions

View file

@ -1,2 +0,0 @@
ko_fi: azur1s
github: azur1s

View file

@ -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
View file

@ -1,5 +1,5 @@
println((\x: num -> x + 35)(34));
println(16---1*3/-16+8%-2);
16---1*3/-16+8%-2;
let a: num = 1 in
println(a);

View file

@ -2,8 +2,6 @@
pub mod read;
pub mod trans;
use std::io::Write;
use read::parse::{lex, parse};
use trans::low::{translate_expr, translate_js};
@ -17,23 +15,34 @@ fn main() {
let (ast, parse_errs) = parse(tokens, src.len());
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<_>>();
for expr in &nexprs {
println!("{}", expr);
}
println!("\x1b[90m───JS OUTPUT──────────────────────────────────────\x1b[0m");
let jsexprs = nexprs.into_iter().map(translate_js).collect::<Vec<_>>();
let mut file = std::fs::File::create("out.js").expect("Failed to create file");
let s = jsexprs
.into_iter()
.map(|e| {
let s = format!("{}", e);
if s.ends_with(';') {
s
} else {
format!("{};", s)
for expr in &jsexprs {
let s = format!("{}", expr);
println!("{}{}", s, if s.ends_with(';') { "" } else { ";" });
}
})
.collect::<Vec<_>>()
.join("\n");
file.write_all(s.as_bytes()).expect("Failed to write to file");
println!();
}
parse_errs