refmt
This commit is contained in:
parent
f805290a4b
commit
be73b0b828
17 changed files with 588 additions and 675 deletions
21
src/lex.rs
21
src/lex.rs
|
|
@ -15,7 +15,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use crate::segment::{Ctr, Ast, list_append, new_ast};
|
||||
use crate::segment::{list_append, new_ast, Ast, Ctr};
|
||||
|
||||
const UNMATCHED_STR_DELIM: &str = "Unmatched string delimiter in input";
|
||||
const UNMATCHED_LIST_DELIM: &str = "Unmatched list delimiter in input";
|
||||
|
|
@ -34,8 +34,8 @@ pub fn lex(document: String) -> Result<Ast, String> {
|
|||
// To represent the multiple passable outcomes
|
||||
return match tree {
|
||||
Err(e) => Err(format!("Problem lexing document: {:?}", e)),
|
||||
Ok(t) => Ok(t)
|
||||
}
|
||||
Ok(t) => Ok(t),
|
||||
};
|
||||
}
|
||||
|
||||
/* The logic used in lex
|
||||
|
|
@ -113,27 +113,27 @@ fn process(document: String) -> Result<Ast, String> {
|
|||
'(' => {
|
||||
if is_str {
|
||||
token.push(c);
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
|
||||
if token != "" {
|
||||
if token != "" {
|
||||
return Err("list started in middle of another token".to_string());
|
||||
}
|
||||
|
||||
ref_stack.push(new_ast(Ctr::None, Ctr::None));
|
||||
|
||||
delim_stack.push(')');
|
||||
},
|
||||
}
|
||||
// begin parsing a string
|
||||
'"' | '\'' | '`' => {
|
||||
is_str = true;
|
||||
delim_stack.push(c);
|
||||
},
|
||||
}
|
||||
// eat the whole line
|
||||
'#' => {
|
||||
ign = true;
|
||||
delim_stack.push('\n');
|
||||
},
|
||||
}
|
||||
// escape next char
|
||||
'\\' => {
|
||||
delim_stack.push('*');
|
||||
|
|
@ -200,7 +200,6 @@ fn process(document: String) -> Result<Ast, String> {
|
|||
return Err(UNMATCHED_LIST_DELIM.to_string());
|
||||
}
|
||||
|
||||
|
||||
/* Returns true if token
|
||||
* - is all alphanumeric except dash and underscore
|
||||
*
|
||||
|
|
@ -210,9 +209,9 @@ fn tok_is_symbol(token: &String) -> Option<String> {
|
|||
let tok = token.as_str();
|
||||
for t in tok.chars() {
|
||||
if !t.is_alphabetic() && !t.is_digit(10) && !(t == '-') && !(t == '_') {
|
||||
return None
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
return Some(String::from(tok))
|
||||
return Some(String::from(tok));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue