Skip to content

Commit

Permalink
Merge pull request #4 from SARDONYX-sard/feature/support-dar-line-com…
Browse files Browse the repository at this point in the history
…ment

feat!(core): support to parse  dar comment
  • Loading branch information
SARDONYX-sard authored Oct 7, 2023
2 parents 564598c + 4ed7bb1 commit 6bc5c1b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion dar2oar_core/src/dar_syntax/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use nom::{
branch::alt,
bytes::complete::{escaped, tag, take_while1},
bytes::complete::{escaped, tag, take_until, take_while1},
character::complete::{char, digit1, hex_digit1, multispace0, one_of, space0},
combinator::{map, opt},
error::context,
Expand Down Expand Up @@ -285,6 +285,11 @@ fn parse_expression(input: &str) -> IResult<&str, Expression> {
))
}

/// Comments starting with ';'
fn comment(input: &str) -> IResult<&str, &str> {
preceded(char(';'), alt((take_until("\n"), take_until("\r\n"))))(input)
}

pub fn parse_condition<'a>(input: &'a str) -> IResult<&'a str, Condition<'a>> {
let mut top_conditions = Condition::And(Vec::new());
let mut or_vec = Vec::new();
Expand All @@ -293,6 +298,15 @@ pub fn parse_condition<'a>(input: &'a str) -> IResult<&'a str, Condition<'a>> {

loop {
let (input, _) = multispace0(input_tmp)?;
// Skip line comment.
match comment(input) {
Ok((input, _)) => {
input_tmp = input;
continue;
}
Err(_) => (),
};

let (input, expr) = opt(parse_expression)(input)?;

// NOTE:
Expand Down Expand Up @@ -391,7 +405,12 @@ mod tests {
let input = r#"
IsActorBase("Skyrim.esm" | 0x00BCDEF7) OR
IsPlayerTeammate() AND
; This is a line comment.
; This is a line comment.
IsEquippedRightType(3) OR
; This is a line comment.
IsEquippedRightType(4)
"#;

Expand Down

0 comments on commit 6bc5c1b

Please sign in to comment.