mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:55:42 +02:00
Parser refactoring for improving pipelines (#7162)
* Remove lite_parse file * Add LiteElement to represent different pipeline elem types * Add PipelineElement to Pipelines * Remove lite_parse specific tests
This commit is contained in:
@ -310,10 +310,10 @@ mod test_examples {
|
||||
let (mut block, delta) = parse(src, engine_state);
|
||||
match block.pipelines.len() {
|
||||
1 => {
|
||||
let n_expressions = block.pipelines[0].expressions.len();
|
||||
block.pipelines[0].expressions.truncate(&n_expressions - 1);
|
||||
let n_expressions = block.pipelines[0].elements.len();
|
||||
block.pipelines[0].elements.truncate(&n_expressions - 1);
|
||||
|
||||
if !block.pipelines[0].expressions.is_empty() {
|
||||
if !block.pipelines[0].elements.is_empty() {
|
||||
let empty_input = PipelineData::new(Span::test_data());
|
||||
Some(eval_block(block, empty_input, cwd, engine_state, delta))
|
||||
} else {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_protocol::ast::{Call, Expr, Expression};
|
||||
use nu_protocol::ast::{Call, Expr, Expression, PipelineElement};
|
||||
use nu_protocol::engine::{Command, EngineState, Stack, StateWorkingSet};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoPipelineData, PipelineData, Range, ShellError, Signature, Span, Type,
|
||||
@ -88,15 +88,11 @@ impl Command for FromNuon {
|
||||
let (lexed, err) = nu_parser::lex(string_input.as_bytes(), 0, &[b'\n', b'\r'], &[], true);
|
||||
error = error.or(err);
|
||||
|
||||
let (lite_block, err) = nu_parser::lite_parse(&lexed);
|
||||
error = error.or(err);
|
||||
|
||||
let (mut block, err) =
|
||||
nu_parser::parse_block(&mut working_set, &lite_block, true, &[], false);
|
||||
let (mut block, err) = nu_parser::parse_block(&mut working_set, &lexed, true, &[], false);
|
||||
error = error.or(err);
|
||||
|
||||
if let Some(pipeline) = block.pipelines.get(1) {
|
||||
if let Some(expr) = pipeline.expressions.get(0) {
|
||||
if let Some(element) = pipeline.elements.get(0) {
|
||||
return Err(ShellError::GenericError(
|
||||
"error when loading nuon text".into(),
|
||||
"could not load nuon text".into(),
|
||||
@ -106,7 +102,7 @@ impl Command for FromNuon {
|
||||
string_input,
|
||||
"error when loading".into(),
|
||||
"excess values when loading".into(),
|
||||
expr.span,
|
||||
element.span(),
|
||||
)],
|
||||
));
|
||||
} else {
|
||||
@ -136,7 +132,7 @@ impl Command for FromNuon {
|
||||
} else {
|
||||
let mut pipeline = block.pipelines.remove(0);
|
||||
|
||||
if let Some(expr) = pipeline.expressions.get(1) {
|
||||
if let Some(expr) = pipeline.elements.get(1) {
|
||||
return Err(ShellError::GenericError(
|
||||
"error when loading nuon text".into(),
|
||||
"could not load nuon text".into(),
|
||||
@ -146,12 +142,12 @@ impl Command for FromNuon {
|
||||
string_input,
|
||||
"error when loading".into(),
|
||||
"detected a pipeline in nuon file".into(),
|
||||
expr.span,
|
||||
expr.span(),
|
||||
)],
|
||||
));
|
||||
}
|
||||
|
||||
if pipeline.expressions.is_empty() {
|
||||
if pipeline.elements.is_empty() {
|
||||
Expression {
|
||||
expr: Expr::Nothing,
|
||||
span: head,
|
||||
@ -159,7 +155,12 @@ impl Command for FromNuon {
|
||||
ty: Type::Nothing,
|
||||
}
|
||||
} else {
|
||||
pipeline.expressions.remove(0)
|
||||
match pipeline.elements.remove(0) {
|
||||
PipelineElement::Expression(expression)
|
||||
| PipelineElement::Redirect(expression)
|
||||
| PipelineElement::And(expression)
|
||||
| PipelineElement::Or(expression) => expression,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -10,15 +10,14 @@ mod format_conversions;
|
||||
#[quickcheck]
|
||||
fn quickcheck_parse(data: String) -> bool {
|
||||
let (tokens, err) = nu_parser::lex(data.as_bytes(), 0, b"", b"", true);
|
||||
let (lite_block, err2) = nu_parser::lite_parse(&tokens);
|
||||
|
||||
if err.is_none() && err2.is_none() {
|
||||
if err.is_none() {
|
||||
let context = create_default_context();
|
||||
{
|
||||
let mut working_set = StateWorkingSet::new(&context);
|
||||
working_set.add_file("quickcheck".into(), data.as_bytes());
|
||||
|
||||
let _ = nu_parser::parse_block(&mut working_set, &lite_block, false, &[], false);
|
||||
let _ = nu_parser::parse_block(&mut working_set, &tokens, false, &[], false);
|
||||
}
|
||||
}
|
||||
true
|
||||
|
Reference in New Issue
Block a user