Add uncommitted files
This commit is contained in:
parent
6ff38d3972
commit
070e936c4a
4 changed files with 49 additions and 0 deletions
|
|
@ -1 +1,3 @@
|
|||
mod boolean;
|
||||
mod integer;
|
||||
mod table;
|
||||
|
|
|
|||
8
src/parse/boolean.rs
Normal file
8
src/parse/boolean.rs
Normal 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
37
src/parse/table.rs
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue