parse2 is now parse

main
Jordan Orelli 11 months ago
parent f0dc5f2e64
commit 97602bf42e

@ -6,7 +6,7 @@ mod lex;
mod line;
mod log;
mod output;
mod parse2;
mod parse;
mod prompt;
mod shell;
mod syntax;
@ -55,7 +55,6 @@ fn main() -> Result<()> {
shell.output.newline()?;
let s = shell.line.pop();
info!("◇ {}", s);
// let tree = parse::parse(&s)?;
match syntax::x(&s) {
Ok(tree) => {
debug!(" {:?}", tree);

@ -1,7 +1,7 @@
use crate::{
error::{ExecError, ParseError},
lex::{Lexer, Token},
parse2,
parse,
};
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() {
parse2::Value::Start => {
parse::Value::Start => {
let mut root = Block::new();
let children = source.iter_children();
for mut child in children {
@ -134,7 +134,7 @@ impl TreeBuilder {
}
Element::Block(root)
}
parse2::Value::Statement => {
parse::Value::Statement => {
let mut children = source.iter_children();
let mut first = children.next().unwrap();
let name = self.descend(&mut first)?;
@ -148,10 +148,10 @@ impl TreeBuilder {
}
Element::Command(cmd)
}
parse2::Value::Terminal(Token::Word(word)) => {
parse::Value::Terminal(Token::Word(word)) => {
Element::Literal(Value::Text(word.to_string()))
}
parse2::Value::Terminal(Token::Glob(_)) => {
parse::Value::Terminal(Token::Glob(_)) => {
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();
let mut builder = TreeBuilder::new();
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> {
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 builder = TreeBuilder::new();
builder.descend(&mut parse_tree)

Loading…
Cancel
Save