This commit is contained in:
Tanishq Kancharla 2021-10-05 21:59:16 -04:00
parent 909b7d2160
commit d6d0bad7aa
4 changed files with 48 additions and 17 deletions

View file

@ -34,7 +34,9 @@ impl Highlighter for NuHighlighter {
.to_string();
output.push((Style::new(), gap));
}
// println!("line: \n{}", line);
// println!("shape: \n{:#?}\n", shape);
// println!("global_span_offset: \n{:#?}\n", global_span_offset);
let next_token = line
[(shape.0.start - global_span_offset)..(shape.0.end - global_span_offset)]
.to_string();

View file

@ -1,5 +1,7 @@
use std::borrow::Borrow;
use std::path::Path;
use nu_engine::{eval_block, eval_expression};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::{ShellError, Signature, SyntaxShape, Value};
@ -30,8 +32,9 @@ impl Command for Source {
call: &Call,
input: Value,
) -> Result<Value, ShellError> {
Ok(Value::Nothing { span: call.head })
// source(_context, call, input)
let block = &call.positional[0];
Ok(eval_expression(_context, block)?)
}
}

View file

@ -549,8 +549,9 @@ pub fn parse_source(
if name == b"source" {
if let Some(decl_id) = working_set.find_decl(b"source") {
let (call, call_span, _) =
let (call, call_span, err) =
parse_internal_call(working_set, spans[0], &spans[1..], decl_id);
// println!("\nSpans: {:#?}", spans);
// Command and one file name
if spans.len() >= 2 {
@ -570,19 +571,44 @@ pub fn parse_source(
&contents,
false,
);
if let Some(_) = err {
// Unsuccessful parse of file
// return (
// Statement::Pipeline(Pipeline::from_vec(vec![Expression {
// expr: Expr::Call(call),
// span: call_span,
// ty: Type::Unknown,
// }])),
// None,
// );
return (
Statement::Pipeline(Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call),
span: span(&spans[1..]),
ty: Type::Unknown,
custom_completion: None,
}])),
// Return the file parse error
err,
);
} else {
// Save the block into the working set
let block_id = working_set.add_block(block);
// println!("CALL:{:?}", call);
let mut call_with_block = call.clone();
// println!("CALL_WITH_BLOCK: {:?}", call_with_block);
call_with_block.positional.push(Expression {
expr: Expr::Block(block_id),
span: span(&spans[1..]),
ty: Type::Unknown,
custom_completion: None,
});
return (
Statement::Pipeline(Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call_with_block),
span: call_span,
ty: Type::Unknown,
custom_completion: None,
}])),
None,
);
}
} else {
// Source file couldn't be parsed correctly
}
}
}

View file

@ -1,5 +1,5 @@
def greet [name] {
echo "hello" $name
def inc [x] {
$x + 1
}
greet "world"
inc 5