Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions brush-builtins/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
}

Expand All @@ -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()),
Expand All @@ -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)| {
Expand Down
9 changes: 5 additions & 4 deletions brush-builtins/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::io::Write;
use brush_core::{
ExecutionExitCode, ExecutionResult, builtins,
env::{EnvironmentLookup, EnvironmentScope},
parser::ast,
variables,
};

Expand Down Expand Up @@ -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()))
Expand Down
3 changes: 1 addition & 2 deletions brush-builtins/src/type_.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
10 changes: 5 additions & 5 deletions brush-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
3 changes: 1 addition & 2 deletions brush-core/src/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions brush-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Loading