mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Rust 1.85, edition=2024 (#15741)
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
authors = ["The Nushell Project Developers"]
|
||||
description = "Nushell's parser"
|
||||
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-parser"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
name = "nu-parser"
|
||||
version = "0.104.1"
|
||||
@ -31,4 +31,4 @@ serde_json = { workspace = true }
|
||||
rstest = { workspace = true, default-features = false }
|
||||
|
||||
[features]
|
||||
plugin = ["nu-plugin-engine"]
|
||||
plugin = ["nu-plugin-engine"]
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "nu-parser-fuzz"
|
||||
version = "0.0.0"
|
||||
publish = false
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
@ -1,11 +1,11 @@
|
||||
use nu_protocol::{
|
||||
DeclId, Span, SyntaxShape, VarId,
|
||||
ast::{
|
||||
Argument, Block, Expr, Expression, ExternalArgument, ImportPatternMember, ListItem,
|
||||
MatchPattern, PathMember, Pattern, Pipeline, PipelineElement, PipelineRedirection,
|
||||
RecordItem,
|
||||
},
|
||||
engine::StateWorkingSet,
|
||||
DeclId, Span, SyntaxShape, VarId,
|
||||
};
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::{
|
||||
CustomExample,
|
||||
ast::{self, Expr, Expression},
|
||||
engine::{self, CallImpl, CommandType, UNKNOWN_SPAN_ID},
|
||||
ir::{self, DataSlice},
|
||||
CustomExample,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -13,15 +13,15 @@ mod type_check;
|
||||
|
||||
pub use deparse::escape_for_script_arg;
|
||||
pub use flatten::{
|
||||
flatten_block, flatten_expression, flatten_pipeline, flatten_pipeline_element, FlatShape,
|
||||
FlatShape, flatten_block, flatten_expression, flatten_pipeline, flatten_pipeline_element,
|
||||
};
|
||||
pub use known_external::KnownExternal;
|
||||
pub use lex::{lex, lex_n_tokens, lex_signature, LexState, Token, TokenContents};
|
||||
pub use lite_parser::{lite_parse, LiteBlock, LiteCommand};
|
||||
pub use lex::{LexState, Token, TokenContents, lex, lex_n_tokens, lex_signature};
|
||||
pub use lite_parser::{LiteBlock, LiteCommand, lite_parse};
|
||||
pub use nu_protocol::parser_path::*;
|
||||
pub use parse_keywords::*;
|
||||
|
||||
pub use parser::{
|
||||
is_math_expression_like, parse, parse_block, parse_expression, parse_external_call,
|
||||
parse_unit_value, trim_quotes, trim_quotes_str, unescape_unquote_string, DURATION_UNIT_GROUPS,
|
||||
DURATION_UNIT_GROUPS, is_math_expression_like, parse, parse_block, parse_expression,
|
||||
parse_external_call, parse_unit_value, trim_quotes, trim_quotes_str, unescape_unquote_string,
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
use crate::{Token, TokenContents};
|
||||
use itertools::{Either, Itertools};
|
||||
use nu_protocol::{ast::RedirectionSource, engine::StateWorkingSet, ParseError, Span};
|
||||
use nu_protocol::{ParseError, Span, ast::RedirectionSource, engine::StateWorkingSet};
|
||||
use std::mem;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
@ -8,16 +8,16 @@ use itertools::Itertools;
|
||||
use log::trace;
|
||||
use nu_path::canonicalize_with;
|
||||
use nu_protocol::{
|
||||
Alias, BlockId, CustomExample, DeclId, FromValue, Module, ModuleId, ParseError, PositionalArg,
|
||||
ResolvedImportPattern, ShellError, Span, Spanned, SyntaxShape, Type, Value, VarId,
|
||||
ast::{
|
||||
Argument, AttributeBlock, Block, Call, Expr, Expression, ImportPattern, ImportPatternHead,
|
||||
ImportPatternMember, Pipeline, PipelineElement,
|
||||
},
|
||||
category_from_string,
|
||||
engine::{StateWorkingSet, DEFAULT_OVERLAY_NAME},
|
||||
engine::{DEFAULT_OVERLAY_NAME, StateWorkingSet},
|
||||
eval_const::eval_constant,
|
||||
parser_path::ParserPath,
|
||||
Alias, BlockId, CustomExample, DeclId, FromValue, Module, ModuleId, ParseError, PositionalArg,
|
||||
ResolvedImportPattern, ShellError, Span, Spanned, SyntaxShape, Type, Value, VarId,
|
||||
};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
@ -30,16 +30,16 @@ pub const LIB_DIRS_VAR: &str = "NU_LIB_DIRS";
|
||||
pub const PLUGIN_DIRS_VAR: &str = "NU_PLUGIN_DIRS";
|
||||
|
||||
use crate::{
|
||||
is_math_expression_like,
|
||||
Token, TokenContents, is_math_expression_like,
|
||||
known_external::KnownExternal,
|
||||
lex,
|
||||
lite_parser::{lite_parse, LiteCommand},
|
||||
lite_parser::{LiteCommand, lite_parse},
|
||||
parser::{
|
||||
check_call, garbage, garbage_pipeline, parse, parse_call, parse_expression,
|
||||
parse_full_signature, parse_import_pattern, parse_internal_call, parse_string, parse_value,
|
||||
parse_var_with_opt_type, trim_quotes, ParsedInternalCall,
|
||||
ParsedInternalCall, check_call, garbage, garbage_pipeline, parse, parse_call,
|
||||
parse_expression, parse_full_signature, parse_import_pattern, parse_internal_call,
|
||||
parse_string, parse_value, parse_var_with_opt_type, trim_quotes,
|
||||
},
|
||||
unescape_unquote_string, Token, TokenContents,
|
||||
unescape_unquote_string,
|
||||
};
|
||||
|
||||
/// These parser keywords can be aliased
|
||||
@ -4206,12 +4206,14 @@ fn detect_params_in_name(
|
||||
.find_position(|c| **c == delim)
|
||||
.unwrap_or((name.len(), &b' '));
|
||||
let param_span = Span::new(name_span.start + idx - 1, name_span.start + idx - 1);
|
||||
let error = ParseError::LabeledErrorWithHelp{
|
||||
let error = ParseError::LabeledErrorWithHelp {
|
||||
error: "no space between name and parameters".into(),
|
||||
label: "expected space".into(),
|
||||
help: format!("consider adding a space between the `{decl_name}` command's name and its parameters"),
|
||||
help: format!(
|
||||
"consider adding a space between the `{decl_name}` command's name and its parameters"
|
||||
),
|
||||
span: param_span,
|
||||
};
|
||||
};
|
||||
Some(error)
|
||||
};
|
||||
|
||||
|
@ -5,9 +5,9 @@ use crate::{
|
||||
parser::{is_variable, parse_value},
|
||||
};
|
||||
use nu_protocol::{
|
||||
ParseError, Span, SyntaxShape, Type, VarId,
|
||||
ast::{MatchPattern, Pattern},
|
||||
engine::StateWorkingSet,
|
||||
ParseError, Span, SyntaxShape, Type, VarId,
|
||||
};
|
||||
pub fn garbage(span: Span) -> MatchPattern {
|
||||
MatchPattern {
|
||||
|
@ -1,8 +1,8 @@
|
||||
#![allow(clippy::byte_char_slices)]
|
||||
|
||||
use crate::{lex::lex_signature, parser::parse_value, trim_quotes, TokenContents};
|
||||
use crate::{TokenContents, lex::lex_signature, parser::parse_value, trim_quotes};
|
||||
use nu_protocol::{
|
||||
engine::StateWorkingSet, IntoSpanned, ParseError, Span, Spanned, SyntaxShape, Type,
|
||||
IntoSpanned, ParseError, Span, Spanned, SyntaxShape, Type, engine::StateWorkingSet,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
|
@ -1,21 +1,21 @@
|
||||
#![allow(clippy::byte_char_slices)]
|
||||
|
||||
use crate::{
|
||||
lex::{is_assignment_operator, lex, lex_n_tokens, lex_signature, LexState},
|
||||
lite_parser::{lite_parse, LiteCommand, LitePipeline, LiteRedirection, LiteRedirectionTarget},
|
||||
Token, TokenContents,
|
||||
lex::{LexState, is_assignment_operator, lex, lex_n_tokens, lex_signature},
|
||||
lite_parser::{LiteCommand, LitePipeline, LiteRedirection, LiteRedirectionTarget, lite_parse},
|
||||
parse_keywords::*,
|
||||
parse_patterns::parse_pattern,
|
||||
parse_shape_specs::{parse_shape_name, parse_type, ShapeDescriptorUse},
|
||||
parse_shape_specs::{ShapeDescriptorUse, parse_shape_name, parse_type},
|
||||
type_check::{self, check_range_types, math_result_type, type_compatible},
|
||||
Token, TokenContents,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use log::trace;
|
||||
use nu_engine::DIR_VAR_PARSER_INFO;
|
||||
use nu_protocol::{
|
||||
ast::*, engine::StateWorkingSet, eval_const::eval_constant, BlockId, DeclId, DidYouMean,
|
||||
FilesizeUnit, Flag, ParseError, PositionalArg, ShellError, Signature, Span, Spanned,
|
||||
SyntaxShape, Type, Value, VarId, ENV_VARIABLE_ID, IN_VARIABLE_ID,
|
||||
BlockId, DeclId, DidYouMean, ENV_VARIABLE_ID, FilesizeUnit, Flag, IN_VARIABLE_ID, ParseError,
|
||||
PositionalArg, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value, VarId, ast::*,
|
||||
engine::StateWorkingSet, eval_const::eval_constant,
|
||||
};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
@ -2328,12 +2328,8 @@ pub fn parse_cell_path(
|
||||
} else if bytes.len() == 1 && bytes[0] == b'?' {
|
||||
if let Some(last) = tail.last_mut() {
|
||||
match last {
|
||||
PathMember::String {
|
||||
ref mut optional, ..
|
||||
} => *optional = true,
|
||||
PathMember::Int {
|
||||
ref mut optional, ..
|
||||
} => *optional = true,
|
||||
PathMember::String { optional, .. } => *optional = true,
|
||||
PathMember::Int { optional, .. } => *optional = true,
|
||||
}
|
||||
}
|
||||
expected_token = TokenType::Dot;
|
||||
@ -4199,8 +4195,8 @@ pub fn parse_signature_helper(working_set: &mut StateWorkingSet, span: Span) ->
|
||||
"Default value is the wrong type"
|
||||
.into(),
|
||||
format!(
|
||||
"expected default value to be `{t}`"
|
||||
),
|
||||
"expected default value to be `{t}`"
|
||||
),
|
||||
expression_span,
|
||||
),
|
||||
)
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_protocol::{
|
||||
ParseError, Span, Type,
|
||||
ast::{Block, Comparison, Expr, Expression, Math, Operator, Pipeline, Range},
|
||||
engine::StateWorkingSet,
|
||||
ParseError, Span, Type,
|
||||
};
|
||||
|
||||
fn type_error(
|
||||
@ -370,7 +370,9 @@ pub fn math_result_type(
|
||||
let help = if matches!(lhs.ty, Type::List(_) | Type::Table(_))
|
||||
|| matches!(rhs.ty, Type::List(_) | Type::Table(_))
|
||||
{
|
||||
Some("if you meant to append a value to a list or a record to a table, use the `append` command or wrap the value in a list. For example: `$list ++ $value` should be `$list ++ [$value]` or `$list | append $value`.")
|
||||
Some(
|
||||
"if you meant to append a value to a list or a record to a table, use the `append` command or wrap the value in a list. For example: `$list ++ $value` should be `$list ++ [$value]` or `$list | append $value`.",
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![allow(clippy::byte_char_slices)]
|
||||
|
||||
use nu_parser::{lex, lex_n_tokens, lex_signature, LexState, Token, TokenContents};
|
||||
use nu_parser::{LexState, Token, TokenContents, lex, lex_n_tokens, lex_signature};
|
||||
use nu_protocol::{ParseError, Span};
|
||||
|
||||
#[test]
|
||||
|
@ -1,8 +1,8 @@
|
||||
use nu_parser::*;
|
||||
use nu_protocol::{
|
||||
DeclId, ParseError, Signature, Span, SyntaxShape, Type,
|
||||
ast::{Argument, Expr, Expression, ExternalArgument, PathMember, Range},
|
||||
engine::{Command, EngineState, Stack, StateWorkingSet},
|
||||
DeclId, ParseError, Signature, Span, SyntaxShape, Type,
|
||||
};
|
||||
use rstest::rstest;
|
||||
|
||||
@ -1998,7 +1998,7 @@ mod mock {
|
||||
use super::*;
|
||||
use nu_engine::CallExt;
|
||||
use nu_protocol::{
|
||||
engine::Call, Category, IntoPipelineData, PipelineData, ShellError, Type, Value,
|
||||
Category, IntoPipelineData, PipelineData, ShellError, Type, Value, engine::Call,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
Reference in New Issue
Block a user