Add uncommitted files

This commit is contained in:
Joscha 2022-01-15 17:47:53 +01:00
parent 6ff38d3972
commit 070e936c4a
4 changed files with 49 additions and 0 deletions

View file

@ -7,3 +7,5 @@ I've wanted to learn a lisp for a while now, but have never come further than
the absolute basics. Also, I've never created a proper programming language
before. So I decided to make one - inspired by my rudimentary understanding of
lisp, combined with a bit of lua tables.
https://github.com/quchen/stgi

View file

@ -1 +1,3 @@
mod boolean;
mod integer;
mod table;

8
src/parse/boolean.rs Normal file
View file

@ -0,0 +1,8 @@
use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::combinator::map;
use nom::IResult;
pub fn bool(input: &str) -> IResult<&str, bool> {
alt((map(tag("true"), |_| true), map(tag("false"), |_| false)))(input)
}

37
src/parse/table.rs Normal file
View file

@ -0,0 +1,37 @@
use std::collections::HashMap;
use nom::branch::alt;
use nom::character::complete::{char, multispace0};
use nom::combinator::map;
use nom::sequence::{delimited, pair, tuple};
use nom::IResult;
use super::boolean::bool;
use super::integer::integer;
enum Value {
Bool(bool),
Int(i64),
Table(Table),
}
type Table = HashMap<Value, Value>;
fn value(input: &str) -> IResult<&str, Value> {
alt((
map(bool, Value::Bool),
map(integer, Value::Int),
map(table, Value::Table),
))(input)
}
fn table(input: &str) -> IResult<&str, Table> {
map(
delimited(
pair(multispace0, char('(')),
char('*'),
pair(multispace0, char(')')),
),
|_| HashMap::new(),
)(input)
}