Skip to content

Commit

Permalink
close #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Pennebaker committed Apr 9, 2023
1 parent a98ca04 commit 72a5a79
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ parser! {
}

rule simple_prerequisite() -> String =
s:$([^ (' ' | '\t' | ':' | ';' | '#' | '\r' | '\n')]+) {
s:$([^ (' ' | '\t' | ':' | ';' | '#' | '\r' | '\n' | '\\')]+) {
s.to_string()
}

Expand All @@ -85,8 +85,18 @@ parser! {
s.to_string()
}

rule multiline_command() -> String =
a:command_escaped_newline() b:compound_make_command() {
format!("{}{}", a, b)
}

rule compound_make_command() -> String =
s:(simple_command_value() / multiline_command() / escaped_non_line_ending()) {
s.to_string()
}

rule make_command() -> String =
strings:((simple_command_value() / command_escaped_newline() / escaped_non_line_ending())+) {
strings:(compound_make_command()+) {
strings.join("")
}

Expand Down Expand Up @@ -130,8 +140,18 @@ parser! {
s.to_string()
}

rule multiline_macro_value() -> String =
a:macro_escaped_newline() b:compound_macro_value() {
format!("{}{}", a, b)
}

rule compound_macro_value() -> String =
s:(simple_macro_value() / multiline_macro_value() / escaped_non_line_ending()) {
s.to_string()
}

rule macro_value() -> String =
strings:((simple_macro_value() / macro_escaped_newline() / escaped_non_line_ending())*) ((comment() / line_ending())+ / eof()) {
strings:(compound_macro_value()*) ((comment() / line_ending())+ / eof()) {
strings.join("")
}

Expand Down Expand Up @@ -443,14 +463,6 @@ fn test_parse_macros() {
]))
);

assert_eq!(
parse_posix("A=x\\\n"),
Ok(Makefile::new(vec![Directive::Macro(
"A".to_string(),
"x ".to_string()
)]))
);

assert_eq!(
parse_posix("A=x\\\ny"),
Ok(Makefile::new(vec![Directive::Macro(
Expand Down Expand Up @@ -567,6 +579,9 @@ fn test_parse_macros() {
"\"\\n\"".to_string()
)]))
);

assert!(parse_posix("A=\\\n").is_err());
assert!(parse_posix("A=\\").is_err());
}

#[test]
Expand Down Expand Up @@ -1121,6 +1136,9 @@ fn test_rules() {
)]))
);

assert!(parse_posix("all:\\\n").is_err());
assert!(parse_posix("all:\\").is_err());

assert_eq!(
parse_posix("BIN=hello\n$(BIN): hello.c\n\tcc -o $(BIN) hello.c\n"),
Ok(Makefile::new(vec![
Expand Down

0 comments on commit 72a5a79

Please sign in to comment.