Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse workspace hints sections such that expressions are not supported. #176

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions wdl-analysis/src/scope/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use wdl_ast::v1::CommandSection;
use wdl_ast::v1::Decl;
use wdl_ast::v1::DocumentItem;
use wdl_ast::v1::Expr;
use wdl_ast::v1::HintsSection;
use wdl_ast::v1::ImportStatement;
use wdl_ast::v1::NameRef;
use wdl_ast::v1::RequirementsSection;
use wdl_ast::v1::RuntimeSection;
use wdl_ast::v1::StructDefinition;
use wdl_ast::v1::TaskDefinition;
use wdl_ast::v1::TaskHintsSection;
use wdl_ast::v1::TaskItem;
use wdl_ast::v1::WorkflowDefinition;
use wdl_ast::v1::WorkflowItem;
Expand Down Expand Up @@ -1039,7 +1039,7 @@ fn type_check_task(
/// The scope to use for evaluating the hints section.
scope: ScopeIndex,
/// The hints section.
section: HintsSection,
section: TaskHintsSection,
},
}

Expand Down
6 changes: 6 additions & 0 deletions wdl-ast/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed

* Split hint section representation into `TaskHintsSection` and
`WorkflowHintsSection` as the latter no longer supports expressions ([#176](https://github.com/stjude-rust-labs/wdl/pull/176))
peterhuene marked this conversation as resolved.
Show resolved Hide resolved


## 0.7.1 - 09-16-2024

### Fixed
Expand Down
42 changes: 21 additions & 21 deletions wdl-ast/src/v1/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl TaskDefinition {
}

/// Gets the hints section of the task.
pub fn hints(&self) -> Option<HintsSection> {
pub fn hints(&self) -> Option<TaskHintsSection> {
child(&self.0)
}

Expand Down Expand Up @@ -126,7 +126,7 @@ pub enum TaskItem {
/// The item is a requirements section.
Requirements(RequirementsSection),
/// The item is a hints section.
Hints(HintsSection),
Hints(TaskHintsSection),
/// The item is a runtime section.
Runtime(RuntimeSection),
/// The item is a metadata section.
Expand All @@ -150,7 +150,7 @@ impl AstNode for TaskItem {
| SyntaxKind::OutputSectionNode
| SyntaxKind::CommandSectionNode
| SyntaxKind::RequirementsSectionNode
| SyntaxKind::HintsSectionNode
| SyntaxKind::TaskHintsSectionNode
| SyntaxKind::RuntimeSectionNode
| SyntaxKind::MetadataSectionNode
| SyntaxKind::ParameterMetadataSectionNode
Expand All @@ -169,7 +169,7 @@ impl AstNode for TaskItem {
SyntaxKind::RequirementsSectionNode => {
Some(Self::Requirements(RequirementsSection(syntax)))
}
SyntaxKind::HintsSectionNode => Some(Self::Hints(HintsSection(syntax))),
SyntaxKind::TaskHintsSectionNode => Some(Self::Hints(TaskHintsSection(syntax))),
SyntaxKind::RuntimeSectionNode => Some(Self::Runtime(RuntimeSection(syntax))),
SyntaxKind::MetadataSectionNode => Some(Self::Metadata(MetadataSection(syntax))),
SyntaxKind::ParameterMetadataSectionNode => {
Expand Down Expand Up @@ -606,37 +606,37 @@ impl AstNode for RequirementsItem {

/// Represents a hints section in a task definition.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct HintsSection(pub(crate) SyntaxNode);
pub struct TaskHintsSection(pub(crate) SyntaxNode);

impl HintsSection {
impl TaskHintsSection {
/// Gets the items in the hints section.
pub fn items(&self) -> AstChildren<HintsItem> {
pub fn items(&self) -> AstChildren<TaskHintsItem> {
children(&self.0)
}

/// Gets the parent of the hints section.
pub fn parent(&self) -> SectionParent {
SectionParent::cast(self.0.parent().expect("should have a parent"))
pub fn parent(&self) -> TaskDefinition {
TaskDefinition::cast(self.0.parent().expect("should have a parent"))
.expect("parent should cast")
}
}

impl AstNode for HintsSection {
impl AstNode for TaskHintsSection {
type Language = WorkflowDescriptionLanguage;

fn can_cast(kind: SyntaxKind) -> bool
where
Self: Sized,
{
kind == SyntaxKind::HintsSectionNode
kind == SyntaxKind::TaskHintsSectionNode
}

fn cast(syntax: SyntaxNode) -> Option<Self>
where
Self: Sized,
{
match syntax.kind() {
SyntaxKind::HintsSectionNode => Some(Self(syntax)),
SyntaxKind::TaskHintsSectionNode => Some(Self(syntax)),
_ => None,
}
}
Expand All @@ -646,11 +646,11 @@ impl AstNode for HintsSection {
}
}

/// Represents an item in a hints section.
/// Represents an item in a task hints section.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct HintsItem(SyntaxNode);
pub struct TaskHintsItem(SyntaxNode);

impl HintsItem {
impl TaskHintsItem {
/// Gets the name of the hints item.
pub fn name(&self) -> Ident {
token(&self.0).expect("expected an item name")
Expand All @@ -662,22 +662,22 @@ impl HintsItem {
}
}

impl AstNode for HintsItem {
impl AstNode for TaskHintsItem {
type Language = WorkflowDescriptionLanguage;

fn can_cast(kind: SyntaxKind) -> bool
where
Self: Sized,
{
kind == SyntaxKind::HintsItemNode
kind == SyntaxKind::TaskHintsItemNode
}

fn cast(syntax: SyntaxNode) -> Option<Self>
where
Self: Sized,
{
match syntax.kind() {
SyntaxKind::HintsItemNode => Some(Self(syntax)),
SyntaxKind::TaskHintsItemNode => Some(Self(syntax)),
_ => None,
}
}
Expand Down Expand Up @@ -1292,7 +1292,7 @@ task test {

// Task hints
let hints = tasks[0].hints().expect("should have a hints section");
assert_eq!(hints.parent().unwrap_task().name().as_str(), "test");
assert_eq!(hints.parent().name().as_str(), "test");
let items: Vec<_> = hints.items().collect();
assert_eq!(items.len(), 1);
assert_eq!(items[0].name().as_str(), "foo");
Expand Down Expand Up @@ -1456,11 +1456,11 @@ task test {
}
}

fn hints_section(
fn task_hints_section(
&mut self,
_: &mut Self::State,
reason: VisitReason,
_: &HintsSection,
_: &TaskHintsSection,
) {
if reason == VisitReason::Enter {
self.hints += 1;
Expand Down
Loading
Loading