new fixes for lexing process, tests to go with them
This commit is contained in:
parent
5ed8a054d3
commit
72598c2168
3 changed files with 43 additions and 9 deletions
13
src/lex.rs
13
src/lex.rs
|
|
@ -111,6 +111,11 @@ fn process(document: String) -> Result<Ast, String> {
|
|||
match c {
|
||||
// add a new Seg reference to the stack
|
||||
'(' => {
|
||||
if is_str {
|
||||
token.push(c);
|
||||
continue
|
||||
}
|
||||
|
||||
if token != "" {
|
||||
return Err("list started in middle of another token".to_string());
|
||||
}
|
||||
|
|
@ -135,7 +140,7 @@ fn process(document: String) -> Result<Ast, String> {
|
|||
}
|
||||
// add to token
|
||||
_ => {
|
||||
token.push(c)
|
||||
token.push(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -149,11 +154,13 @@ fn process(document: String) -> Result<Ast, String> {
|
|||
|
||||
let mut current_seg_ref = ref_stack.pop().unwrap();
|
||||
let mut obj;
|
||||
if token.len() > 0 {
|
||||
if is_str {
|
||||
obj = Ctr::String(token);
|
||||
is_str = false;
|
||||
} else if token == "true" {
|
||||
token = String::new();
|
||||
list_append(current_seg_ref.clone(), obj);
|
||||
} else if token.len() > 0 {
|
||||
if token == "true" {
|
||||
obj = Ctr::Bool(true);
|
||||
} else if token == "false" {
|
||||
obj = Ctr::Bool(false);
|
||||
|
|
|
|||
|
|
@ -41,13 +41,12 @@ pub fn get_echo() -> Function {
|
|||
Ctr::Seg(c) => string.push_str(ast_as_string(c.clone(), true).as_str()),
|
||||
Ctr::None => ()
|
||||
}
|
||||
|
||||
string.push_str(" ");
|
||||
return true;
|
||||
}) {
|
||||
// TODO: use custom logger
|
||||
println!("Echo failure!")
|
||||
}
|
||||
|
||||
return Ctr::String(string);
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -58,6 +58,34 @@ mod lex_tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_delim_in_str() {
|
||||
let document: &str = "('(')";
|
||||
match lex(document.to_string()) {
|
||||
Ok(tree) => {
|
||||
assert_eq!(ast_to_string(tree), document);
|
||||
},
|
||||
Err(s) => {
|
||||
print!("{}\n", s);
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_string() {
|
||||
let document: &str = "('')";
|
||||
match lex(document.to_string()) {
|
||||
Ok(tree) => {
|
||||
assert_eq!(ast_to_string(tree), document);
|
||||
},
|
||||
Err(s) => {
|
||||
print!("{}\n", s);
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unmatched_list_delim_flat() {
|
||||
let document: &str = "(one two";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue