Skip to content

Commit

Permalink
Add support for carriage return
Browse files Browse the repository at this point in the history
  • Loading branch information
VOID404 committed Jul 10, 2024
1 parent f1d6a98 commit d18e52c
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ use crate::ast::{self, Task, Term, Variable};
pub type ParseErr<'a> = VerboseError<&'a str>;
type ParseResult<'a, O> = nom::IResult<&'a str, O, ParseErr<'a>>;

fn enl(input: &str) -> ParseResult<()> {
value((), pair(char('\\'), nl)).parse(input)
}

fn hspace0<'a>(tab: bool) -> impl Parser<&'a str, (), ParseErr<'a>> {
macro_rules! hst {
() => {};
}
let hst = value(
(),
many0_count(alt((value((), tag("\\\n")), value((), one_of(" \t"))))),
many0_count(alt((value((), enl), value((), one_of(" \t"))))),
);

let hsnt = value(
(),
many0_count(alt((value((), tag("\\\n")), value((), one_of(" \t"))))),
many0_count(alt((value((), enl), value((), one_of(" \t"))))),
);
match tab {
true => hst,
Expand All @@ -36,12 +40,12 @@ fn hspace0<'a>(tab: bool) -> impl Parser<&'a str, (), ParseErr<'a>> {
fn hspace1<'a>(tab: bool) -> impl Parser<&'a str, (), ParseErr<'a>> {
let hst = value(
(),
many1_count(alt((value((), tag("\\\n")), value((), one_of(" \t"))))),
many1_count(alt((value((), enl), value((), one_of(" \t"))))),
);

let hsnt = value(
(),
many1_count(alt((value((), tag("\\\n")), value((), one_of(" \t"))))),
many1_count(alt((value((), enl), value((), one_of(" \t"))))),
);
match tab {
true => hst,
Expand Down Expand Up @@ -70,7 +74,7 @@ fn comment<'a>(input: &'a str) -> ParseResult<()> {
(), // Output is thrown away.
pair(
ws0(char('#')),
many0_count(alt((value((), tag("\\\n")), value((), none_of("\n\r"))))),
many0_count(alt((value((), enl), value((), none_of("\n\r"))))),
),
),
)
Expand All @@ -93,7 +97,7 @@ fn rest(input: &str) -> ParseResult<&str> {
context(
"rest of line",
recognize(many0_count(alt((
value((), tag("\\\n")),
value((), enl),
value((), none_of("\n\r#")),
)))),
)
Expand Down Expand Up @@ -184,7 +188,17 @@ fn eol(input: &str) -> ParseResult<()> {
if input.is_empty() {
return Ok((input, ()));
}
value((), char('\n')).parse(input)
value((), nl).parse(input)
}

#[cfg(target_family = "windows")]
fn nl(input: &str) -> ParseResult<()> {
value((), tag("\r\n"))(input)
}

#[cfg(not(target_family = "windows"))]
fn nl(input: &str) -> ParseResult<()> {
value((), tag("\n"))(input)
}

pub struct Makefile;
Expand Down

0 comments on commit d18e52c

Please sign in to comment.