Skip to content

Commit

Permalink
[BugFix]: Addressing issues with parsing newline characters on window…
Browse files Browse the repository at this point in the history
…s for conjunctions (#482)

* removing ConjunctionsWrapper tuple struct because it was unused

* explicitly ignoring failing lints

* [BugFix]: fixing issue with parseing conjunctions for when clauses on windows due to escape characters

* removing test function used for debugging
  • Loading branch information
joshfried-aws committed Mar 25, 2024
1 parent ef40dcc commit b014d90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 2 additions & 0 deletions guard/src/rules/libyaml/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ pub(crate) enum Event<'input> {
StreamEnd,
DocumentStart,
DocumentEnd,
#[allow(dead_code)]
Alias(Anchor),
Scalar(Scalar<'input>),
SequenceStart(SequenceStart),
SequenceEnd,
#[allow(dead_code)]
MappingStart(MappingStart),
MappingEnd,
}
Expand Down
20 changes: 9 additions & 11 deletions guard/src/rules/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use indexmap::map::IndexMap;
use nom::branch::alt;
use nom::bytes::complete::{is_not, take_while, take_while1};
use nom::bytes::complete::{tag, take_till};
use nom::character::complete::{alpha1, newline, space1};
use nom::character::complete::{alpha1, space1};
use nom::character::complete::{anychar, digit1, one_of};
use nom::character::complete::{char, multispace0, multispace1, space0};
use nom::combinator::{all_consuming, cut, peek};
Expand Down Expand Up @@ -1187,6 +1187,13 @@ fn single_clause(input: Span) -> IResult<Span, WhenGuardClause> {
//
// rule_name\s+<<msg>>[ \t\n]+or[ \t\n]+
//
//
//

fn newline(input: Span) -> IResult<Span, Span> {
alt((tag("\n"), tag("\r\n")))(input)
}

fn rule_clause(input: Span) -> IResult<Span, GuardClause> {
let location = FileLocation {
file_name: input.extra,
Expand Down Expand Up @@ -1345,6 +1352,7 @@ fn single_clauses(input: Span) -> IResult<Span, Conjunctions<WhenGuardClause>> {
)
}

#[allow(dead_code)] // TODO: investigate why this is unused
fn clauses(input: Span) -> IResult<Span, Conjunctions<GuardClause>> {
cnf_clauses(
input,
Expand Down Expand Up @@ -1936,16 +1944,6 @@ impl<'a> TryFrom<&'a str> for GuardClause<'a> {
}
}

pub(crate) struct ConjunctionsWrapper<'a>(pub(crate) Conjunctions<GuardClause<'a>>);
impl<'a> TryFrom<&'a str> for ConjunctionsWrapper<'a> {
type Error = Error;

fn try_from(value: &'a str) -> Result<Self, Self::Error> {
let span = from_str2(value);
Ok(ConjunctionsWrapper(clauses(span)?.1))
}
}

impl<'a> TryFrom<&'a str> for TypeBlock<'a> {
type Error = Error;

Expand Down

0 comments on commit b014d90

Please sign in to comment.