Skip to content

Commit

Permalink
small code change
Browse files Browse the repository at this point in the history
  • Loading branch information
Aloso committed Mar 21, 2023
1 parent 776d327 commit 4c2f155
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pomsky-lib/src/exprs/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ enum ReferenceDirection {
Forwards,
}

impl From<ReferenceDirection> for Feature {
fn from(direction: ReferenceDirection) -> Self {
match direction {
ReferenceDirection::Backwards => Feature::Backreference,
ReferenceDirection::Forwards => Feature::ForwardReference,
}
}
}

impl<'i> RuleExt<'i> for Reference<'i> {
fn compile(&self, options: CompileOptions, state: &mut CompileState) -> CompileResult<'i> {
let (direction, number) = match self.target {
Expand Down Expand Up @@ -77,15 +86,9 @@ impl<'i> RuleExt<'i> for Reference<'i> {
};

match options.flavor {
RegexFlavor::Rust => Err(CompileErrorKind::Unsupported(
if direction == ReferenceDirection::Backwards {
Feature::Backreference
} else {
Feature::ForwardReference
},
options.flavor,
)
.at(self.span)),
RegexFlavor::Rust => {
Err(CompileErrorKind::Unsupported(direction.into(), options.flavor).at(self.span))
}

RegexFlavor::JavaScript | RegexFlavor::Python
if direction == ReferenceDirection::Forwards =>
Expand Down

0 comments on commit 4c2f155

Please sign in to comment.