Skip to content

Commit

Permalink
Add Source::{VariableValue, Other}
Browse files Browse the repository at this point in the history
  • Loading branch information
magicant committed Jul 15, 2024
1 parent 556845e commit 2eae979
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions yash-syntax/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
struct is renamed to `syntax::BracedParam`.
- The `parser::SyntaxError::InvalidParam` variant is added, which is returned
when a parameter expansion has an invalid name.
- The `source::Source` enum is extended with new variants `VariableValue` and
`Other`.

### Changed

Expand Down
14 changes: 14 additions & 0 deletions yash-syntax/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ pub enum Source {
/// Location of the simple command that has set this trap command
origin: Location,
},

/// Value of a variable
VariableValue {
/// Variable name
name: String,
},

/// Other source
Other {
/// Label that describes the source
label: String,
},
// TODO More Source types
}

Expand Down Expand Up @@ -159,6 +171,8 @@ impl Source {
Eval { .. } => "<eval>",
DotScript { name, .. } => name,
Trap { condition, .. } => condition,
VariableValue { name } => name,
Other { label } => label,
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion yash-syntax/src/source/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ impl super::Source {
pub fn complement_annotations<'a, 's: 'a, T: Extend<Annotation<'a>>>(&'s self, result: &mut T) {
use super::Source::*;
match self {
Unknown | Stdin | CommandString | CommandFile { .. } => (),
Unknown
| Stdin
| CommandString
| CommandFile { .. }
| VariableValue { .. }
| Other { .. } => (),

CommandSubst { original } => {
// TODO Use Extend::extend_one
result.extend(std::iter::once(Annotation::new(
Expand Down

0 comments on commit 2eae979

Please sign in to comment.