Implemented an abstraction for extracting flags from builtins
This commit is contained in:
@@ -1,5 +1,32 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::parse::{lex::{LexFlags, LexStream}, node_operation, Node, ParseStream};
|
||||
|
||||
pub mod lexer;
|
||||
pub mod parser;
|
||||
pub mod expand;
|
||||
pub mod term;
|
||||
pub mod error;
|
||||
pub mod getopt;
|
||||
|
||||
/// Unsafe to use outside of tests
|
||||
pub fn get_nodes<F1>(input: &str, filter: F1) -> Vec<Node>
|
||||
where
|
||||
F1: Fn(&Node) -> bool
|
||||
{
|
||||
let mut nodes = vec![];
|
||||
let tokens = LexStream::new(Rc::new(input.into()), LexFlags::empty())
|
||||
.map(|tk| tk.unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
let mut parsed_nodes = ParseStream::new(tokens)
|
||||
.map(|nd| nd.unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for node in parsed_nodes.iter_mut() {
|
||||
node_operation(node,
|
||||
&filter,
|
||||
&mut |node: &mut Node| nodes.push(node.clone())
|
||||
);
|
||||
}
|
||||
nodes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user