|
|
@ -1,7 +1,7 @@
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
|
error::{ExecError, ParseError},
|
|
|
|
error::{ExecError, ParseError},
|
|
|
|
lex::{Lexer, Token},
|
|
|
|
lex::{Lexer, Token},
|
|
|
|
parse2,
|
|
|
|
parse,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use std::{collections::HashSet, process};
|
|
|
|
use std::{collections::HashSet, process};
|
|
|
|
|
|
|
|
|
|
|
@ -120,9 +120,9 @@ impl TreeBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn descend(&mut self, source: &mut parse2::Cursor) -> Result<Element, ParseError> {
|
|
|
|
fn descend(&mut self, source: &mut parse::Cursor) -> Result<Element, ParseError> {
|
|
|
|
let e = match source.value() {
|
|
|
|
let e = match source.value() {
|
|
|
|
parse2::Value::Start => {
|
|
|
|
parse::Value::Start => {
|
|
|
|
let mut root = Block::new();
|
|
|
|
let mut root = Block::new();
|
|
|
|
let children = source.iter_children();
|
|
|
|
let children = source.iter_children();
|
|
|
|
for mut child in children {
|
|
|
|
for mut child in children {
|
|
|
@ -134,7 +134,7 @@ impl TreeBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Element::Block(root)
|
|
|
|
Element::Block(root)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parse2::Value::Statement => {
|
|
|
|
parse::Value::Statement => {
|
|
|
|
let mut children = source.iter_children();
|
|
|
|
let mut children = source.iter_children();
|
|
|
|
let mut first = children.next().unwrap();
|
|
|
|
let mut first = children.next().unwrap();
|
|
|
|
let name = self.descend(&mut first)?;
|
|
|
|
let name = self.descend(&mut first)?;
|
|
|
@ -148,10 +148,10 @@ impl TreeBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Element::Command(cmd)
|
|
|
|
Element::Command(cmd)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parse2::Value::Terminal(Token::Word(word)) => {
|
|
|
|
parse::Value::Terminal(Token::Word(word)) => {
|
|
|
|
Element::Literal(Value::Text(word.to_string()))
|
|
|
|
Element::Literal(Value::Text(word.to_string()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parse2::Value::Terminal(Token::Glob(_)) => {
|
|
|
|
parse::Value::Terminal(Token::Glob(_)) => {
|
|
|
|
todo!()
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -160,7 +160,7 @@ impl TreeBuilder {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn build(mut source: parse2::Cursor) -> Result<Element, ParseError> {
|
|
|
|
fn build(mut source: parse::Cursor) -> Result<Element, ParseError> {
|
|
|
|
source.up_to_root();
|
|
|
|
source.up_to_root();
|
|
|
|
let mut builder = TreeBuilder::new();
|
|
|
|
let mut builder = TreeBuilder::new();
|
|
|
|
builder.descend(&mut source)
|
|
|
|
builder.descend(&mut source)
|
|
|
@ -168,7 +168,7 @@ fn build(mut source: parse2::Cursor) -> Result<Element, ParseError> {
|
|
|
|
|
|
|
|
|
|
|
|
pub fn x(source: &str) -> Result<Element, ParseError> {
|
|
|
|
pub fn x(source: &str) -> Result<Element, ParseError> {
|
|
|
|
let tokens = Lexer::new(source);
|
|
|
|
let tokens = Lexer::new(source);
|
|
|
|
let parser = parse2::Parser::new(tokens);
|
|
|
|
let parser = parse::Parser::new(tokens);
|
|
|
|
let mut parse_tree = parser.parse()?;
|
|
|
|
let mut parse_tree = parser.parse()?;
|
|
|
|
let mut builder = TreeBuilder::new();
|
|
|
|
let mut builder = TreeBuilder::new();
|
|
|
|
builder.descend(&mut parse_tree)
|
|
|
|
builder.descend(&mut parse_tree)
|
|
|
|