Skip to content

Commit

Permalink
Define SimpleCommandWord
Browse files Browse the repository at this point in the history
  • Loading branch information
magicant committed Dec 14, 2024
1 parent c49511f commit e80a357
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions yash-syntax/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,41 @@ impl Redir {
}
}

/// Word of a simple command
///
/// This enum represents a word that appears in a [`SimpleCommand`]. Most words
/// are regular words, but some words are expanded as if they were assignments.
/// For example, in the command `export PATH FOO=bar`, `PATH` is a regular word
/// and `FOO=bar` is an assignment word.
///
/// Note that any assignments preceding the command words are represented as
/// [`Assign`]s in the [`SimpleCommand`] struct, not as [`SimpleCommandWord`]s.
/// For example, in the command `FOO=bar printenv FOO`, `FOO=bar` is an
/// assignment and `printenv` and `FOO` are command words.
///
/// A word is considered an assignment word if it can be converted to an
/// [`Assign`] and if it follows another word that names a declaration utility.
/// (TODO: What commands are declaration utilities?)
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum SimpleCommandWord {
/// Normal word
Regular(Word),
/// Word to be expanded in assignment context
Assign(Assign),
}

/// Command that involves assignments, redirections, and word expansions
///
/// In the shell language syntax, a valid simple command must contain at least one of assignments,
/// redirections, and words. The parser must not produce a completely empty simple command.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SimpleCommand {
/// Assignments
pub assigns: Vec<Assign>,
// TODO Use SimpleCommandWord instead of Word
/// Main command words
pub words: Vec<Word>,
/// Redirections
pub redirs: Rc<Vec<Redir>>,
}

Expand Down

0 comments on commit e80a357

Please sign in to comment.