diff --git a/brush-builtins/src/declare.rs b/brush-builtins/src/declare.rs index 3874f0032..da0943df8 100644 --- a/brush-builtins/src/declare.rs +++ b/brush-builtins/src/declare.rs @@ -6,6 +6,7 @@ use brush_core::{ ErrorKind, ExecutionResult, builtins, env::{self, EnvironmentLookup, EnvironmentScope}, error, + parser::ast, variables::{ self, ArrayLiteral, ShellValue, ShellValueLiteral, ShellValueUnsetType, ShellVariable, ShellVariableUpdateTransform, @@ -365,15 +366,12 @@ impl DeclareCommand { } brush_core::CommandArg::Assignment(assignment) => { match &assignment.name { - brush_parser::ast::AssignmentName::VariableName(var_name) => { + ast::AssignmentName::VariableName(var_name) => { name = var_name.to_owned(); assigned_index = None; } - brush_parser::ast::AssignmentName::ArrayElementName(var_name, index) => { - if matches!( - assignment.value, - brush_parser::ast::AssignmentValue::Array(_) - ) { + ast::AssignmentName::ArrayElementName(var_name, index) => { + if matches!(assignment.value, ast::AssignmentValue::Array(_)) { return Err(ErrorKind::AssigningListToArrayMember.into()); } @@ -383,7 +381,7 @@ impl DeclareCommand { } match &assignment.value { - brush_parser::ast::AssignmentValue::Scalar(s) => { + ast::AssignmentValue::Scalar(s) => { if let Some(index) = &assigned_index { initial_value = Some(ShellValueLiteral::Array(ArrayLiteral(vec![( Some(index.to_owned()), @@ -395,7 +393,7 @@ impl DeclareCommand { name_is_array = false; } } - brush_parser::ast::AssignmentValue::Array(a) => { + ast::AssignmentValue::Array(a) => { initial_value = Some(ShellValueLiteral::Array(ArrayLiteral( a.iter() .map(|(i, v)| { diff --git a/brush-builtins/src/export.rs b/brush-builtins/src/export.rs index dc9385592..748d91475 100644 --- a/brush-builtins/src/export.rs +++ b/brush-builtins/src/export.rs @@ -5,6 +5,7 @@ use std::io::Write; use brush_core::{ ExecutionExitCode, ExecutionResult, builtins, env::{EnvironmentLookup, EnvironmentScope}, + parser::ast, variables, }; @@ -96,18 +97,18 @@ impl ExportCommand { } brush_core::CommandArg::Assignment(assignment) => { let name = match &assignment.name { - brush_parser::ast::AssignmentName::VariableName(name) => name, - brush_parser::ast::AssignmentName::ArrayElementName(_, _) => { + ast::AssignmentName::VariableName(name) => name, + ast::AssignmentName::ArrayElementName(_, _) => { writeln!(context.stderr(), "not a valid variable name")?; return Ok(ExecutionExitCode::InvalidUsage.into()); } }; let value = match &assignment.value { - brush_parser::ast::AssignmentValue::Scalar(s) => { + ast::AssignmentValue::Scalar(s) => { variables::ShellValueLiteral::Scalar(s.flatten()) } - brush_parser::ast::AssignmentValue::Array(a) => { + ast::AssignmentValue::Array(a) => { variables::ShellValueLiteral::Array(variables::ArrayLiteral( a.iter() .map(|(k, v)| (k.as_ref().map(|k| k.flatten()), v.flatten())) diff --git a/brush-builtins/src/type_.rs b/brush-builtins/src/type_.rs index dbfba2006..04a8baf9d 100644 --- a/brush-builtins/src/type_.rs +++ b/brush-builtins/src/type_.rs @@ -1,11 +1,10 @@ use std::io::Write; use std::path::{Path, PathBuf}; -use brush_parser::ast; use clap::Parser; use brush_core::sys::fs::PathExt; -use brush_core::{ExecutionResult, Shell, builtins}; +use brush_core::{ExecutionResult, Shell, builtins, parser::ast}; /// Inspect the type of a named shell item. #[derive(Parser)] diff --git a/brush-core/src/error.rs b/brush-core/src/error.rs index 9c995657f..0f52da515 100644 --- a/brush-core/src/error.rs +++ b/brush-core/src/error.rs @@ -168,23 +168,23 @@ pub enum ErrorKind { /// An error occurred while parsing. #[error("{1}: {0}")] - ParseError(brush_parser::ParseError, brush_parser::SourceInfo), + ParseError(crate::parser::ParseError, crate::SourceInfo), /// An error occurred while parsing a function body. #[error("{0}: {1}")] - FunctionParseError(String, brush_parser::ParseError), + FunctionParseError(String, crate::parser::ParseError), /// An error occurred while parsing a word. #[error(transparent)] - WordParseError(#[from] brush_parser::WordParseError), + WordParseError(#[from] crate::parser::WordParseError), /// Unable to parse a test command. #[error(transparent)] - TestCommandParseError(#[from] brush_parser::TestCommandParseError), + TestCommandParseError(#[from] crate::parser::TestCommandParseError), /// Unable to parse a key binding specification. #[error(transparent)] - BindingParseError(#[from] brush_parser::BindingParseError), + BindingParseError(#[from] crate::parser::BindingParseError), /// A threading error occurred. #[error("threading error")] diff --git a/brush-core/src/expansion.rs b/brush-core/src/expansion.rs index 40dfc2df0..e219d4556 100644 --- a/brush-core/src/expansion.rs +++ b/brush-core/src/expansion.rs @@ -4,8 +4,7 @@ use std::borrow::Cow; use std::cmp::min; use brush_parser::ast; -use brush_parser::word::ParameterTransformOp; -use brush_parser::word::SubstringMatchKind; +use brush_parser::word::{ParameterTransformOp, SubstringMatchKind}; use itertools::Itertools; use crate::ExecutionParameters; diff --git a/brush-core/src/lib.rs b/brush-core/src/lib.rs index 3f28ea3ec..4406aa31c 100644 --- a/brush-core/src/lib.rs +++ b/brush-core/src/lib.rs @@ -38,11 +38,22 @@ pub mod traps; pub mod variables; mod wellknownvars; +/// Re-export parser types used in core definitions. +pub mod parser { + pub use brush_parser::{ + BindingParseError, ParseError, SourcePosition, SourceSpan, TestCommandParseError, + WordParseError, ast, + }; +} + +// For now we re-export SourceInfo from brush-parser at the top level of brush-core; +// we plan to move its definition to this crate entirely in the future. +pub use brush_parser::SourceInfo; + pub use commands::{CommandArg, ExecutionContext}; pub use error::{BuiltinError, Error, ErrorKind}; pub use interp::{ExecutionParameters, ProcessGroupPolicy}; +pub use parser::{SourcePosition, SourceSpan}; pub use results::{ExecutionControlFlow, ExecutionExitCode, ExecutionResult, ExecutionSpawnResult}; pub use shell::{CreateOptions, Shell, ShellBuilder, ShellBuilderState, ShellFd}; pub use variables::{ShellValue, ShellVariable}; - -pub use brush_parser::{SourceInfo, SourceSpan};