mirror of
https://github.com/nushell/nushell.git
synced 2025-01-11 00:38:23 +01:00
Start env shorthand
This commit is contained in:
parent
b82a4869d5
commit
cb11f042ab
@ -192,7 +192,7 @@ fn main() -> std::io::Result<()> {
|
||||
);
|
||||
if let Some(err) = err {
|
||||
eprintln!("Parse Error: {:?}", err);
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
(output, working_set.render())
|
||||
};
|
||||
|
@ -783,11 +783,32 @@ impl<'a> ParserWorkingSet<'a> {
|
||||
|
||||
pub fn parse_call(&mut self, spans: &[Span]) -> (Expression, Option<ParseError>) {
|
||||
// assume spans.len() > 0?
|
||||
let name = self.get_span_contents(spans[0]);
|
||||
let mut pos = 0;
|
||||
let mut shorthand = vec![];
|
||||
|
||||
while pos < spans.len() {
|
||||
// First, check if there is any environment shorthand
|
||||
let name = self.get_span_contents(spans[pos]);
|
||||
let split: Vec<_> = name.splitn(2, |x| *x == b'=').collect();
|
||||
if split.len() == 2 {
|
||||
shorthand.push(split);
|
||||
pos += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if pos == spans.len() {
|
||||
return (
|
||||
Expression::garbage(span(spans)),
|
||||
Some(ParseError::UnknownCommand(spans[0])),
|
||||
);
|
||||
}
|
||||
let name = self.get_span_contents(spans[pos]);
|
||||
pos += 1;
|
||||
|
||||
if let Some(mut decl_id) = self.find_decl(name) {
|
||||
let mut name = name.to_vec();
|
||||
let mut pos = 1;
|
||||
while pos < spans.len() {
|
||||
// look to see if it's a subcommand
|
||||
let mut new_name = name.to_vec();
|
||||
|
@ -123,3 +123,8 @@ fn predecl_check() -> TestResult {
|
||||
fn def_with_no_dollar() -> TestResult {
|
||||
run_test("def bob [x] { $x + 3 }; bob 4", "7")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn env_shorthand() -> TestResult {
|
||||
run_test("FOO=BAR if $false { 3 } else { 4 }", "4")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user