Some HIR
```python
x = """Lambda,
If,
Set,
Define,
Cond,
Case,
And,
Or,
When,
Unless,
Begin,"""
x = x.replace(" ", "").replace(",", "").replace("\r", "")
x = x.splitlines()
print("// ===== Begin Special Forms =====")
for i in x:
i = i.lower()
print(f"fn sf_{i}<'a>(&mut self, tree: &[Ast<'a>]) -> Option<Hir<'a>> {{")
print("todo!()")
print("}")
print("// ===== End Special Forms =====")
```
2022-01-01 18:38:43 +00:00
|
|
|
mod hir;
|
2021-12-29 16:49:49 +00:00
|
|
|
mod parser;
|
|
|
|
|
Some HIR
```python
x = """Lambda,
If,
Set,
Define,
Cond,
Case,
And,
Or,
When,
Unless,
Begin,"""
x = x.replace(" ", "").replace(",", "").replace("\r", "")
x = x.splitlines()
print("// ===== Begin Special Forms =====")
for i in x:
i = i.lower()
print(f"fn sf_{i}<'a>(&mut self, tree: &[Ast<'a>]) -> Option<Hir<'a>> {{")
print("todo!()")
print("}")
print("// ===== End Special Forms =====")
```
2022-01-01 18:38:43 +00:00
|
|
|
use anyhow::bail;
|
2021-12-29 16:49:49 +00:00
|
|
|
use fs_err as fs;
|
|
|
|
|
Some HIR
```python
x = """Lambda,
If,
Set,
Define,
Cond,
Case,
And,
Or,
When,
Unless,
Begin,"""
x = x.replace(" ", "").replace(",", "").replace("\r", "")
x = x.splitlines()
print("// ===== Begin Special Forms =====")
for i in x:
i = i.lower()
print(f"fn sf_{i}<'a>(&mut self, tree: &[Ast<'a>]) -> Option<Hir<'a>> {{")
print("todo!()")
print("}")
print("// ===== End Special Forms =====")
```
2022-01-01 18:38:43 +00:00
|
|
|
type Error = String;
|
|
|
|
|
2021-12-29 16:49:49 +00:00
|
|
|
#[derive(Debug, PartialEq, logos::Logos)]
|
|
|
|
enum Kind {
|
|
|
|
#[token("(")]
|
|
|
|
Lparen,
|
|
|
|
|
|
|
|
#[token(")")]
|
|
|
|
Rparen,
|
|
|
|
|
|
|
|
#[regex(r"[A-Za-z0-9!$%&*+-./:<=>?@^_~]+")]
|
|
|
|
// Most literals are floats, and can be seperated later
|
|
|
|
Symbol,
|
|
|
|
|
|
|
|
#[regex(r"#(f|t)")]
|
|
|
|
Boolean,
|
|
|
|
|
|
|
|
#[regex(r#""(\\.|[^"\\])*""#)]
|
|
|
|
String,
|
|
|
|
|
|
|
|
#[error]
|
|
|
|
#[regex(r"[ \t\n\f\r]+", logos::skip)]
|
|
|
|
#[regex(r";.*", logos::skip)]
|
|
|
|
Error,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
|
|
let arg = std::env::args()
|
|
|
|
.nth(1)
|
|
|
|
.ok_or_else(|| anyhow::anyhow!("Useage: handball sources.scm"))?;
|
|
|
|
|
|
|
|
let src = fs::read_to_string(&arg)?;
|
|
|
|
|
Some HIR
```python
x = """Lambda,
If,
Set,
Define,
Cond,
Case,
And,
Or,
When,
Unless,
Begin,"""
x = x.replace(" ", "").replace(",", "").replace("\r", "")
x = x.splitlines()
print("// ===== Begin Special Forms =====")
for i in x:
i = i.lower()
print(f"fn sf_{i}<'a>(&mut self, tree: &[Ast<'a>]) -> Option<Hir<'a>> {{")
print("todo!()")
print("}")
print("// ===== End Special Forms =====")
```
2022-01-01 18:38:43 +00:00
|
|
|
let (trees, errs) = dbg!(parser::parse(&src));
|
|
|
|
|
|
|
|
if !errs.is_empty() {
|
|
|
|
bail!("Got some parse errors");
|
|
|
|
}
|
|
|
|
|
|
|
|
for tree in trees {
|
|
|
|
dbg!(hir::Lowerer::default().ast(&tree));
|
|
|
|
}
|
2021-12-29 16:49:49 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum Ast<'s> {
|
|
|
|
Tree(Vec<Ast<'s>>),
|
|
|
|
Leaf(&'s str),
|
|
|
|
}
|