fix compile errors

This commit is contained in:
Tanishq Kancharla 2021-09-30 23:04:56 -04:00
parent 2b5ef1b2d7
commit e00755a2e9
2 changed files with 63 additions and 89 deletions

24
Cargo.lock generated
View File

@ -39,9 +39,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bstr"
version = "0.2.16"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90682c8d613ad3373e66de8c6411e0ae2ab2571e879d2efbf73558cc66f21279"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [
"lazy_static",
"memchr",
@ -166,9 +166,9 @@ dependencies = [
[[package]]
name = "instant"
version = "0.1.10"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d"
checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd"
dependencies = [
"cfg-if",
]
@ -190,9 +190,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.101"
version = "0.2.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21"
checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103"
[[package]]
name = "lock_api"
@ -477,8 +477,8 @@ dependencies = [
[[package]]
name = "reedline"
version = "0.1.0"
source = "git+https://github.com/jntrnr/reedline?branch=main#cd87851ad9f238b491062bb854d65489ca2c4c1c"
version = "0.2.0"
source = "git+https://github.com/jntrnr/reedline?branch=main#93c2146fcf4257c40426bc2f0c6903d4115caaf1"
dependencies = [
"chrono",
"crossterm",
@ -567,9 +567,9 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
[[package]]
name = "syn"
version = "1.0.76"
version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84"
checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0"
dependencies = [
"proc-macro2",
"quote",
@ -624,9 +624,9 @@ checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
[[package]]
name = "unicode-width"
version = "0.1.8"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"

View File

@ -2490,97 +2490,71 @@ pub fn parse_source(
working_set: &mut StateWorkingSet,
spans: &[Span],
) -> (Statement, Option<ParseError>) {
let mut error = None;
let name = working_set.get_span_contents(spans[0]);
if name == b"source" {
let (name_expr, err) = parse_string(working_set, spans[1]);
error = error.or(err);
if let Some(decl_id) = working_set.find_decl(b"source") {
let (call, call_span, _) =
parse_internal_call(working_set, spans[0], &spans[1..], decl_id);
if let Some(filename) = name_expr.as_string() {
let source_file = Path::new(&filename);
// This is to stay consistent w/ the code taken from nushell
let path = source_file;
// Command and one file name
if spans.len() >= 2 {
let name_expr = working_set.get_span_contents(spans[1]);
if let Ok(filename) = String::from_utf8(name_expr.to_vec()) {
let source_file = Path::new(&filename);
let contents = std::fs::read(path);
let path = source_file;
let contents = std::fs::read(path);
match contents {
Ok(contents) => {
let (block, err) = parse(
&mut working_set,
path.file_name().and_then(|x| x.to_str()),
&contents,
true,
);
if let Some(e) = err {
(
Statement::Pipeline(Pipeline::from_vec(vec![Expression {
expr: Expr::Garbage,
span: span(spans),
ty: Type::Unknown,
}])),
err,
)
} else {
let block_id = working_set.add_block(block);
(
// Why creating a pipeline here for only one expression?
// Is there a way to only make this a declaration?
Statement::Pipeline(Pipeline::from_vec(vec![Expression {
expr: Expr::Subexpression(block_id),
span: span(spans),
ty: Type::Unknown, // FIXME
}])),
None,
)
if let Ok(contents) = contents {
let (block, err) = parse(
working_set,
path.file_name().and_then(|x| x.to_str()),
&contents,
true,
);
if let None = err {
// Successful parse
// What should I be doing here?
let block_id = working_set.add_block(block);
// return (
// // Successful parse
// // Why creating a pipeline here for only one expression?
// // Is there a way to only make this a declaration?
// Statement::Pipeline(Pipeline::from_vec(vec![Expression {
// expr: Expr::Subexpression(block_id),
// span: span(spans),
// ty: Type::Unknown, // FIXME
// }])),
// None,
// );
}
}
}
Err(e) => (
Statement::Pipeline(Pipeline::from_vec(vec![Expression {
expr: Expr::Garbage,
span: span(spans),
ty: Type::Unknown,
}])),
Some(ParseError::UnknownState(e.into(), span(spans))),
), //(ShellError::InternalError("Can't load file to source".to_string())),
}
} else {
(
return (
Statement::Pipeline(Pipeline::from_vec(vec![Expression {
expr: Expr::Garbage,
span: span(spans),
expr: Expr::Call(call),
span: call_span,
ty: Type::Unknown,
}])),
Some(ParseError::Mismatch(
"string".into(),
// Can this be better?
"incompatible string".into(),
spans[1],
)),
)
None,
);
}
} else {
// Not source command?
(
Statement::Pipeline(Pipeline::from_vec(vec![Expression {
expr: Expr::Garbage,
span: span(spans),
ty: Type::Unknown,
}])),
error,
)
}
// (
// Statement::Pipeline(Pipeline::from_vec(vec![Expression {
// expr: Expr::Garbage,
// span: span(spans),
// ty: Type::Unknown,
// }])),
// Some(ParseError::UnknownState(
// "internal error: let statement unparseable".into(),
// span(spans),
// )),
// )
(
Statement::Pipeline(Pipeline::from_vec(vec![Expression {
expr: Expr::Garbage,
span: span(spans),
ty: Type::Unknown,
}])),
Some(ParseError::UnknownState(
"internal error: source statement unparseable".into(),
span(spans),
)),
)
}
/// Parse a statement. Check if def, let, alias, or source command can process it properly