Compare commits
No commits in common. "c990de795e7113ac30a9f6283f5b7e207ae1517e" and "35d0704740eb4f8d54810508ff9826e4c2b217aa" have entirely different histories.
c990de795e
...
35d0704740
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "purrchance"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
authors = ["xenofem <xenofem@xeno.science>"]
|
||||
description = "An unofficial Rust implementation of the Perchance grammar engine"
|
||||
repository = "https://git.xeno.science/xenofem/purrchance"
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
use purrchance::*;
|
||||
use purrchance::parser::*;
|
||||
|
||||
use std::env;
|
||||
use std::fs::read_to_string;
|
||||
use std::process::exit;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() < 2 {
|
||||
eprintln!("too few arguments!");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
let raw_grammar = read_to_string(&args[1]).unwrap();
|
||||
let grammar = load_grammar(&raw_grammar);
|
||||
if args.len() < 3 {
|
||||
eprintln!("{:?}", grammar);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
let sym = Symbol::NonTerminal(args[2].clone());
|
||||
println!("{}", sym.eval(&grammar).unwrap());
|
||||
}
|
17
src/lib.rs
17
src/lib.rs
|
@ -10,7 +10,6 @@ pub trait Purrchance {
|
|||
fn eval(&self, g: &Grammar) -> Option<String>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Symbol {
|
||||
Terminal(String),
|
||||
NonTerminal(String),
|
||||
|
@ -25,7 +24,6 @@ impl Purrchance for Symbol {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Expr(Vec<Symbol>);
|
||||
|
||||
impl Purrchance for Expr {
|
||||
|
@ -34,7 +32,6 @@ impl Purrchance for Expr {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct List(Vec<(Expr, f64)>);
|
||||
|
||||
impl Purrchance for List {
|
||||
|
@ -43,7 +40,6 @@ impl Purrchance for List {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Grammar(HashMap<String,List>);
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -146,19 +142,6 @@ test
|
|||
test
|
||||
foo ^1000000
|
||||
bar ^1/1000000
|
||||
");
|
||||
let nt = Symbol::NonTerminal(String::from("test"));
|
||||
assert_eq!(nt.eval(&g), Some(String::from("foo")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_loaded_grammar_multiple_lists() {
|
||||
let g = load_grammar("
|
||||
test
|
||||
[test1]
|
||||
|
||||
test1
|
||||
foo
|
||||
");
|
||||
let nt = Symbol::NonTerminal(String::from("test"));
|
||||
assert_eq!(nt.eval(&g), Some(String::from("foo")));
|
||||
|
|
|
@ -25,7 +25,7 @@ fn whitespace(input: &str) -> IResult<&str, ()> {
|
|||
}
|
||||
|
||||
fn empty_line(input: &str) -> IResult<&str, ()> {
|
||||
map(tuple((whitespace, opt(comment), tag("\n"))), |_| ())(input)
|
||||
map(tuple((opt(comment), tag("\n"))), |_| ())(input)
|
||||
}
|
||||
|
||||
pub fn take_until_any<T, Input, Error: ParseError<Input>>(tags: Vec<T>) -> impl Fn(Input) -> IResult<Input, Input, Error>
|
||||
|
|
Loading…
Reference in a new issue