mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
Some cleanup, better subexpressions
This commit is contained in:
parent
82cf6caba4
commit
b20c4047d4
4 changed files with 13 additions and 27 deletions
|
@ -1,7 +1,7 @@
|
||||||
use nu_engine::{eval_block, eval_expression};
|
use nu_engine::eval_block;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EvaluationContext};
|
use nu_protocol::engine::{Command, EvaluationContext};
|
||||||
use nu_protocol::{IntoValueStream, Signature, Span, SyntaxShape, Value};
|
use nu_protocol::{IntoValueStream, Signature, SyntaxShape, Value};
|
||||||
|
|
||||||
pub struct Each;
|
pub struct Each;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use nu_engine::{eval_block, eval_expression};
|
use nu_engine::{eval_block, eval_expression};
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EvaluationContext};
|
use nu_protocol::engine::{Command, EvaluationContext};
|
||||||
use nu_protocol::{IntoValueStream, Signature, Span, SyntaxShape, Value};
|
use nu_protocol::{IntoValueStream, Signature, SyntaxShape, Value};
|
||||||
|
|
||||||
pub struct For;
|
pub struct For;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ impl Command for For {
|
||||||
&self,
|
&self,
|
||||||
context: &EvaluationContext,
|
context: &EvaluationContext,
|
||||||
call: &Call,
|
call: &Call,
|
||||||
input: Value,
|
_input: Value,
|
||||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||||
let var_id = call.positional[0]
|
let var_id = call.positional[0]
|
||||||
.as_var()
|
.as_var()
|
||||||
|
|
|
@ -595,11 +595,7 @@ pub fn parse_call(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_int(
|
pub fn parse_int(token: &str, span: Span) -> (Expression, Option<ParseError>) {
|
||||||
working_set: &mut StateWorkingSet,
|
|
||||||
token: &str,
|
|
||||||
span: Span,
|
|
||||||
) -> (Expression, Option<ParseError>) {
|
|
||||||
if let Some(token) = token.strip_prefix("0x") {
|
if let Some(token) = token.strip_prefix("0x") {
|
||||||
if let Ok(v) = i64::from_str_radix(token, 16) {
|
if let Ok(v) = i64::from_str_radix(token, 16) {
|
||||||
(
|
(
|
||||||
|
@ -677,11 +673,7 @@ pub fn parse_int(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_float(
|
pub fn parse_float(token: &str, span: Span) -> (Expression, Option<ParseError>) {
|
||||||
working_set: &mut StateWorkingSet,
|
|
||||||
token: &str,
|
|
||||||
span: Span,
|
|
||||||
) -> (Expression, Option<ParseError>) {
|
|
||||||
if let Ok(x) = token.parse::<f64>() {
|
if let Ok(x) = token.parse::<f64>() {
|
||||||
(
|
(
|
||||||
Expression {
|
Expression {
|
||||||
|
@ -699,14 +691,10 @@ pub fn parse_float(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_number(
|
pub fn parse_number(token: &str, span: Span) -> (Expression, Option<ParseError>) {
|
||||||
working_set: &mut StateWorkingSet,
|
if let (x, None) = parse_int(token, span) {
|
||||||
token: &str,
|
|
||||||
span: Span,
|
|
||||||
) -> (Expression, Option<ParseError>) {
|
|
||||||
if let (x, None) = parse_int(working_set, token, span) {
|
|
||||||
(x, None)
|
(x, None)
|
||||||
} else if let (x, None) = parse_float(working_set, token, span) {
|
} else if let (x, None) = parse_float(token, span) {
|
||||||
(x, None)
|
(x, None)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
|
@ -951,7 +939,7 @@ pub fn parse_full_column_path(
|
||||||
|
|
||||||
let source = working_set.get_span_contents(span);
|
let source = working_set.get_span_contents(span);
|
||||||
|
|
||||||
let (output, err) = lex(source, start, &[], &[]);
|
let (output, err) = lex(source, start, &[b'\n'], &[]);
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
|
|
||||||
let (output, err) = lite_parse(&output);
|
let (output, err) = lite_parse(&output);
|
||||||
|
@ -1717,7 +1705,7 @@ pub fn parse_value(
|
||||||
match shape {
|
match shape {
|
||||||
SyntaxShape::Number => {
|
SyntaxShape::Number => {
|
||||||
if let Ok(token) = String::from_utf8(bytes.into()) {
|
if let Ok(token) = String::from_utf8(bytes.into()) {
|
||||||
parse_number(working_set, &token, span)
|
parse_number(&token, span)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
garbage(span),
|
garbage(span),
|
||||||
|
@ -1727,7 +1715,7 @@ pub fn parse_value(
|
||||||
}
|
}
|
||||||
SyntaxShape::Int => {
|
SyntaxShape::Int => {
|
||||||
if let Ok(token) = String::from_utf8(bytes.into()) {
|
if let Ok(token) = String::from_utf8(bytes.into()) {
|
||||||
parse_int(working_set, &token, span)
|
parse_int(&token, span)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
garbage(span),
|
garbage(span),
|
||||||
|
|
|
@ -16,9 +16,7 @@ pub fn parse_int() {
|
||||||
assert!(err.is_none());
|
assert!(err.is_none());
|
||||||
assert!(block.len() == 1);
|
assert!(block.len() == 1);
|
||||||
match &block[0] {
|
match &block[0] {
|
||||||
Statement::Pipeline(Pipeline {
|
Statement::Pipeline(Pipeline { expressions }) => {
|
||||||
expressions: expressions,
|
|
||||||
}) => {
|
|
||||||
assert!(expressions.len() == 1);
|
assert!(expressions.len() == 1);
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
expressions[0],
|
expressions[0],
|
||||||
|
|
Loading…
Reference in a new issue