Skip to content

Commit

Permalink
close #122
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Pennebaker committed Apr 14, 2023
1 parent 1157622 commit d0014a0
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,44 @@ pub trait Traceable {
pub trait Node: Traceable + Debug + PartialEq {}

/// Ore provides raw token information.
///
/// Ores produces by [parse_posix] may receive values as string literals,
/// as originally supplied in the AST. Minimal or no evaluation is performed;
/// The actual value may vary during makefile processing with a live make implementation.
#[derive(Debug, PartialEq)]
pub enum Ore {
/// Ru models a makefile rule.
Ru {
/// ts denotes the target(s) produced by this rule.
ts: Vec<String>,

/// ps denotes any prerequisite(s) depended on by this rule.
ps: Vec<String>,

/// cs denotes any shell command(s) executed by this rule.
cs: Vec<String>,
},

/// Mc models a makefile macro definition.
///
/// Values
Mc {
/// n denotes a name for this macro.
n: String,

/// v denotes an unexpanded value for this macro.
v: String,
},

/// In models an include line.
In {
/// p denotes the file path of a makefile to include.
p: String,
},

/// Ex models a general macro expression.
Ex {
/// e denotes an unexpanded macro expression.
e: String,
},
}
Expand Down Expand Up @@ -294,7 +317,7 @@ parser! {
}

rule macro_definition() -> Gem =
(comment() / line_ending())* p:position!() n:macro_name() _ "=" _ v:macro_value() {
(comment() / line_ending())* p:position!() n:macro_name() _ ("+=" / ":=" / "?=" / "=") _ v:macro_value() {
Gem {
o: p,
l: 0,
Expand Down Expand Up @@ -338,7 +361,7 @@ parser! {
}

rule node() -> Gem =
n:(make_rule() / include() / macro_definition() / general_expression()) {
n:(macro_definition() / make_rule() / include() / general_expression()) {
n
}

Expand Down Expand Up @@ -1059,6 +1082,45 @@ fn test_parse_macros() {

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

assert_eq!(
parse_posix("A:=apple\n")
.unwrap()
.ns
.into_iter()
.map(|e| e.n)
.collect::<Vec<Ore>>(),
vec![Ore::Mc {
n: "A".to_string(),
v: "apple".to_string(),
}]
);

assert_eq!(
parse_posix("A?=apple\n")
.unwrap()
.ns
.into_iter()
.map(|e| e.n)
.collect::<Vec<Ore>>(),
vec![Ore::Mc {
n: "A".to_string(),
v: "apple".to_string(),
}]
);

assert_eq!(
parse_posix("A+=apple\n")
.unwrap()
.ns
.into_iter()
.map(|e| e.n)
.collect::<Vec<Ore>>(),
vec![Ore::Mc {
n: "A".to_string(),
v: "apple".to_string(),
}]
);
}

#[test]
Expand Down

0 comments on commit d0014a0

Please sign in to comment.