correctly parse grammars that don't have a final newline
This commit is contained in:
parent
f99f22f477
commit
dab6774a47
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "purrchance"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
authors = ["xenofem <xenofem@xeno.science>"]
|
||||
description = "An unofficial Rust implementation of the Perchance grammar engine"
|
||||
repository = "https://git.xeno.science/xenofem/purrchance"
|
||||
|
|
|
@ -172,6 +172,7 @@ test
|
|||
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("
|
||||
|
@ -184,4 +185,12 @@ test1
|
|||
let nt = Symbol::NonTerminal(String::from("test"));
|
||||
assert_eq!(nt.eval(&g), Some(String::from("foo")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_loaded_grammar_no_trailing_newline() {
|
||||
let g = load_grammar("test
|
||||
foo").unwrap();
|
||||
let nt = Symbol::NonTerminal(String::from("test"));
|
||||
assert_eq!(nt.eval(&g), Some(String::from("foo")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,12 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn take_all(input: &str) -> IResult<&str, &str> {
|
||||
take_while(|_| true)(input)
|
||||
}
|
||||
|
||||
fn terminal(input: &str) -> IResult<&str, Symbol> {
|
||||
let (input, mut terminal_val) = verify(take_until_any(vec!["[", "//", "^", "\n"]), |s: &str| s.len() > 0)(input)?;
|
||||
let (input, mut terminal_val) = verify(alt((take_until_any(vec!["[", "//", "^", "\n"]), take_all)), |s: &str| s.len() > 0)(input)?;
|
||||
if !input.starts_with("[") {
|
||||
terminal_val = terminal_val.trim_end();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue