Revert "Make $ on variable names optional (#6434)" (#6446)

This reverts commit 3cb9147f22.
This commit is contained in:
JT 2022-09-06 05:42:47 +12:00 committed by GitHub
parent 14512988ba
commit d86350af80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 43 deletions

View file

@ -32,7 +32,7 @@ impl Command for AppendDF {
vec![
Example {
description: "Appends a dataframe as new columns",
example: r#"let a = ([['a' 'b']; [1 2] [3 4]] | into df);
example: r#"let a = ([[a b]; [1 2] [3 4]] | into df);
$a | append $a"#,
result: Some(
NuDataFrame::try_from_columns(vec![
@ -59,7 +59,7 @@ impl Command for AppendDF {
},
Example {
description: "Appends a dataframe merging at the end of columns",
example: r#"let a = ([['a' 'b']; [1 2] [3 4]] | into df);
example: r#"let a = ([[a b]; [1 2] [3 4]] | into df);
$a | append $a --col"#,
result: Some(
NuDataFrame::try_from_columns(vec![

View file

@ -36,9 +36,9 @@ impl Command for DropNulls {
vec![
Example {
description: "drop null values in dataframe",
example: r#"let my_df = ([[a b]; [1 2] [3 0] [1 2]] | into df);
let res = ($my_df.b / $my_df.b);
let a = ($my_df | with-column $res --name 'res');
example: r#"let df = ([[a b]; [1 2] [3 0] [1 2]] | into df);
let res = ($df.b / $df.b);
let a = ($df | with-column $res --name res);
$a | drop-nulls"#,
result: Some(
NuDataFrame::try_from_columns(vec![

View file

@ -38,9 +38,9 @@ impl Command for TakeDF {
vec![
Example {
description: "Takes selected rows from dataframe",
example: r#"let my_df = ([[a b]; [4 1] [5 2] [4 3]] | into df);
example: r#"let df = ([[a b]; [4 1] [5 2] [4 3]] | into df);
let indices = ([0 2] | into df);
$my_df | take $indices"#,
$df | take $indices"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(

View file

@ -74,10 +74,6 @@ pub fn is_math_expression_like(
return true;
}
if bytes == b"nu" {
return false;
}
let b = bytes[0];
if b == b'('
@ -119,11 +115,6 @@ pub fn is_math_expression_like(
return true;
}
let parsed_variable = parse_variable(working_set, span);
if parsed_variable.0.is_some() && parsed_variable.1.is_none() {
return true;
}
false
}
@ -4027,23 +4018,6 @@ pub fn parse_value(
return parse_variable_expr(working_set, span);
}
let parsed_variable = parse_variable(working_set, span);
if parsed_variable.0.is_some() && parsed_variable.1.is_none() {
let var_id = parsed_variable
.0
.expect("internal error: already checked var id exists");
return (
Expression {
expr: Expr::Var(var_id),
span,
custom_completion: None,
ty: working_set.get_variable(var_id).ty.clone(),
},
None,
);
}
let bytes = working_set.get_span_contents(span);
// Check for reserved keyword values
match bytes {
b"true" => {

View file

@ -1511,21 +1511,13 @@ impl<'a> StateWorkingSet<'a> {
pub fn find_variable(&self, name: &[u8]) -> Option<VarId> {
let mut removed_overlays = vec![];
let name = if name.starts_with(&[b'$']) {
name.to_vec()
} else {
let mut new_name = name.to_vec();
new_name.insert(0, b'$');
new_name
};
for scope_frame in self.delta.scope.iter().rev() {
for overlay_frame in scope_frame
.active_overlays(&mut removed_overlays)
.iter()
.rev()
{
if let Some(var_id) = overlay_frame.vars.get(&name) {
if let Some(var_id) = overlay_frame.vars.get(name) {
return Some(*var_id);
}
}
@ -1537,7 +1529,7 @@ impl<'a> StateWorkingSet<'a> {
.iter()
.rev()
{
if let Some(var_id) = overlay_frame.vars.get(&name) {
if let Some(var_id) = overlay_frame.vars.get(name) {
return Some(*var_id);
}
}