forked from extern/nushell
Fix multiword imports/exports (#336)
This commit is contained in:
parent
f1b2ab0b27
commit
be827e5628
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1328,9 +1328,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.69"
|
version = "1.0.70"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e466864e431129c7e0d3476b92f20458e5879919a0596c6472738d9fa2d342f8"
|
checksum = "e277c495ac6cd1a01a58d0a0c574568b4d1ddf14f59965c6a58b8d96400b54f3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
@ -12,7 +12,7 @@ use crate::{
|
|||||||
lex, lite_parse,
|
lex, lite_parse,
|
||||||
parser::{
|
parser::{
|
||||||
check_name, garbage, garbage_statement, parse, parse_block_expression,
|
check_name, garbage, garbage_statement, parse, parse_block_expression,
|
||||||
parse_import_pattern, parse_internal_call, parse_signature, parse_string,
|
parse_import_pattern, parse_internal_call, parse_signature, parse_string, trim_quotes,
|
||||||
},
|
},
|
||||||
ParseError,
|
ParseError,
|
||||||
};
|
};
|
||||||
@ -357,6 +357,8 @@ pub fn parse_module_block(
|
|||||||
// parts[2] is safe since it's checked in parse_export already
|
// parts[2] is safe since it's checked in parse_export already
|
||||||
working_set.get_span_contents(pipeline.commands[0].parts[2]);
|
working_set.get_span_contents(pipeline.commands[0].parts[2]);
|
||||||
|
|
||||||
|
let decl_name = trim_quotes(decl_name);
|
||||||
|
|
||||||
let decl_id = working_set
|
let decl_id = working_set
|
||||||
.find_decl(decl_name)
|
.find_decl(decl_name)
|
||||||
.expect("internal error: failed to find added declaration");
|
.expect("internal error: failed to find added declaration");
|
||||||
|
@ -69,6 +69,16 @@ fn is_variable(bytes: &[u8]) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn trim_quotes(bytes: &[u8]) -> &[u8] {
|
||||||
|
if (bytes.starts_with(b"\"") && bytes.ends_with(b"\"") && bytes.len() > 1)
|
||||||
|
|| (bytes.starts_with(b"\'") && bytes.ends_with(b"\'") && bytes.len() > 1)
|
||||||
|
{
|
||||||
|
&bytes[1..(bytes.len() - 1)]
|
||||||
|
} else {
|
||||||
|
bytes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn check_call(command: Span, sig: &Signature, call: &Call) -> Option<ParseError> {
|
fn check_call(command: Span, sig: &Signature, call: &Call) -> Option<ParseError> {
|
||||||
// Allow the call to pass if they pass in the help flag
|
// Allow the call to pass if they pass in the help flag
|
||||||
if call.named.iter().any(|(n, _)| n.item == "help") {
|
if call.named.iter().any(|(n, _)| n.item == "help") {
|
||||||
@ -1423,13 +1433,7 @@ pub fn parse_filepath(
|
|||||||
span: Span,
|
span: Span,
|
||||||
) -> (Expression, Option<ParseError>) {
|
) -> (Expression, Option<ParseError>) {
|
||||||
let bytes = working_set.get_span_contents(span);
|
let bytes = working_set.get_span_contents(span);
|
||||||
let bytes = if (bytes.starts_with(b"\"") && bytes.ends_with(b"\"") && bytes.len() > 1)
|
let bytes = trim_quotes(bytes);
|
||||||
|| (bytes.starts_with(b"\'") && bytes.ends_with(b"\'") && bytes.len() > 1)
|
|
||||||
{
|
|
||||||
&bytes[1..(bytes.len() - 1)]
|
|
||||||
} else {
|
|
||||||
bytes
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(token) = String::from_utf8(bytes.into()) {
|
if let Ok(token) = String::from_utf8(bytes.into()) {
|
||||||
(
|
(
|
||||||
@ -1641,13 +1645,7 @@ pub fn parse_glob_pattern(
|
|||||||
span: Span,
|
span: Span,
|
||||||
) -> (Expression, Option<ParseError>) {
|
) -> (Expression, Option<ParseError>) {
|
||||||
let bytes = working_set.get_span_contents(span);
|
let bytes = working_set.get_span_contents(span);
|
||||||
let bytes = if (bytes.starts_with(b"\"") && bytes.ends_with(b"\"") && bytes.len() > 1)
|
let bytes = trim_quotes(bytes);
|
||||||
|| (bytes.starts_with(b"\'") && bytes.ends_with(b"\'") && bytes.len() > 1)
|
|
||||||
{
|
|
||||||
&bytes[1..(bytes.len() - 1)]
|
|
||||||
} else {
|
|
||||||
bytes
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(token) = String::from_utf8(bytes.into()) {
|
if let Ok(token) = String::from_utf8(bytes.into()) {
|
||||||
(
|
(
|
||||||
@ -1672,13 +1670,7 @@ pub fn parse_string(
|
|||||||
span: Span,
|
span: Span,
|
||||||
) -> (Expression, Option<ParseError>) {
|
) -> (Expression, Option<ParseError>) {
|
||||||
let bytes = working_set.get_span_contents(span);
|
let bytes = working_set.get_span_contents(span);
|
||||||
let bytes = if (bytes.starts_with(b"\"") && bytes.ends_with(b"\"") && bytes.len() > 1)
|
let bytes = trim_quotes(bytes);
|
||||||
|| (bytes.starts_with(b"\'") && bytes.ends_with(b"\'") && bytes.len() > 1)
|
|
||||||
{
|
|
||||||
&bytes[1..(bytes.len() - 1)]
|
|
||||||
} else {
|
|
||||||
bytes
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(token) = String::from_utf8(bytes.into()) {
|
if let Ok(token) = String::from_utf8(bytes.into()) {
|
||||||
(
|
(
|
||||||
@ -1853,6 +1845,7 @@ pub fn parse_import_pattern(
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
let tail = trim_quotes(tail);
|
||||||
(
|
(
|
||||||
ImportPattern {
|
ImportPattern {
|
||||||
head,
|
head,
|
||||||
|
@ -900,6 +900,14 @@ fn record_2() -> TestResult {
|
|||||||
run_test(r#"{'b': 'c'}.b"#, "c")
|
run_test(r#"{'b': 'c'}.b"#, "c")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn multi_word_imports() -> TestResult {
|
||||||
|
run_test(
|
||||||
|
r#"module spam { export def "foo bar" [] { 10 } }; use spam "foo bar"; foo bar"#,
|
||||||
|
"10",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn config_var_1() -> TestResult {
|
fn config_var_1() -> TestResult {
|
||||||
// Note: this tests both the config variable and that it is properly captured into a block
|
// Note: this tests both the config variable and that it is properly captured into a block
|
||||||
|
Loading…
Reference in New Issue
Block a user