Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/formatting/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ impl<'i> Formatter<'i> {
self.append_char('\n');
}

if let Some(template) = metadata.template {
if let Some(domain) = metadata.domain {
self.append_str("& ");
self.append_str(template);
self.append_str(domain);
self.append_char('\n');
}
self.reset_syntax();
Expand Down Expand Up @@ -536,11 +536,11 @@ impl<'i> Formatter<'i> {
}

pub fn append_signature(&mut self, signature: &'i Signature) {
self.append_genus(&signature.domain);
self.append_genus(&signature.requires);
self.add_fragment_reference(Syntax::Neutral, " ");
self.add_fragment_reference(Syntax::Structure, "->");
self.add_fragment_reference(Syntax::Neutral, " ");
self.append_genus(&signature.range);
self.append_genus(&signature.provides);
}

pub fn append_genus(&mut self, genus: &'i Genus) {
Expand Down Expand Up @@ -1376,22 +1376,22 @@ mod check {
let mut output = Formatter::new(78);

output.append_signature(&Signature {
domain: Genus::Single(Forma("Alderaan")),
range: Genus::Single(Forma("AsteroidField")),
requires: Genus::Single(Forma("Alderaan")),
provides: Genus::Single(Forma("AsteroidField")),
});
assert_eq!(output.to_string(), "Alderaan -> AsteroidField");

output.reset();
output.append_signature(&Signature {
domain: Genus::List(Forma("Clone")),
range: Genus::Single(Forma("Army")),
requires: Genus::List(Forma("Clone")),
provides: Genus::Single(Forma("Army")),
});
assert_eq!(output.to_string(), "[Clone] -> Army");

output.reset();
let signature = Signature {
domain: Genus::Single(Forma("TaxationOfTradeRoutes")),
range: Genus::Tuple(vec![Forma("Rebels"), Forma("Empire")]),
requires: Genus::Single(Forma("TaxationOfTradeRoutes")),
provides: Genus::Tuple(vec![Forma("Rebels"), Forma("Empire")]),
};
output.append_signature(&signature);
assert_eq!(
Expand Down
26 changes: 13 additions & 13 deletions src/language/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Metadata<'i> {
pub version: u8,
pub license: Option<&'i str>,
pub copyright: Option<&'i str>,
pub template: Option<&'i str>,
pub domain: Option<&'i str>,
}

impl Default for Metadata<'_> {
Expand All @@ -22,7 +22,7 @@ impl Default for Metadata<'_> {
version: 1,
license: None,
copyright: None,
template: None,
domain: None,
}
}
}
Expand Down Expand Up @@ -87,8 +87,8 @@ pub enum Genus<'i> {

#[derive(Eq, Debug, PartialEq)]
pub struct Signature<'i> {
pub domain: Genus<'i>,
pub range: Genus<'i>,
pub requires: Genus<'i>,
pub provides: Genus<'i>,
}

// now types for procedure bodies
Expand Down Expand Up @@ -234,7 +234,7 @@ pub(crate) fn validate_copyright(input: &str) -> Option<&str> {
}
}

pub(crate) fn validate_template(input: &str) -> Option<&str> {
pub(crate) fn validate_domain(input: &str) -> Option<&str> {
let re = regex!(r"^[A-Za-z0-9.,\-]+$");

if re.is_match(input) {
Expand Down Expand Up @@ -538,18 +538,18 @@ mod check {
}

#[test]
fn template_rules() {
assert_eq!(validate_template("checklist"), Some("checklist"));
assert_eq!(validate_template("checklist,v1"), Some("checklist,v1"));
assert_eq!(validate_template("checklist-v1.0"), Some("checklist-v1.0"));
fn domain_rules() {
assert_eq!(validate_domain("checklist"), Some("checklist"));
assert_eq!(validate_domain("checklist,v1"), Some("checklist,v1"));
assert_eq!(validate_domain("checklist-v1.0"), Some("checklist-v1.0"));
}

fn maker<'i>() -> Metadata<'i> {
let t1 = Metadata {
version: 1,
license: None,
copyright: None,
template: None,
domain: None,
};

t1
Expand All @@ -561,7 +561,7 @@ mod check {
version: 1,
license: None,
copyright: None,
template: None,
domain: None,
};

assert_eq!(Metadata::default(), t1);
Expand All @@ -570,7 +570,7 @@ mod check {
version: 1,
license: Some("MIT"),
copyright: Some("ACME, Inc"),
template: Some("checklist"),
domain: Some("checklist"),
};

let t3 = maker();
Expand All @@ -580,7 +580,7 @@ mod check {
let t4 = Metadata {
license: Some("MIT"),
copyright: Some("ACME, Inc"),
template: Some("checklist"),
domain: Some("checklist"),
..t3
};

Expand Down
42 changes: 21 additions & 21 deletions src/parsing/checks/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ fn header_spdx() {
}

#[test]
fn header_template() {
fn header_domain() {
let mut input = Parser::new();
input.initialize("& checklist");
assert!(is_template_line(input.source));
assert!(is_domain_line(input.source));

let result = input.read_template_line();
let result = input.read_domain_line();
assert_eq!(result, Ok(Some("checklist")));

input.initialize("& nasa-flight-plan,v4.0");
assert!(is_template_line(input.source));
assert!(is_domain_line(input.source));

let result = input.read_template_line();
let result = input.read_domain_line();
assert_eq!(result, Ok(Some("nasa-flight-plan,v4.0")));
}

Expand Down Expand Up @@ -159,8 +159,8 @@ fn signatures() {
assert_eq!(
result,
Ok(Signature {
domain: Genus::Single(Forma("A")),
range: Genus::Single(Forma("B"))
requires: Genus::Single(Forma("A")),
provides: Genus::Single(Forma("B"))
})
);

Expand All @@ -169,8 +169,8 @@ fn signatures() {
assert_eq!(
result,
Ok(Signature {
domain: Genus::Single(Forma("Beans")),
range: Genus::Single(Forma("Coffee"))
requires: Genus::Single(Forma("Beans")),
provides: Genus::Single(Forma("Coffee"))
})
);

Expand All @@ -179,8 +179,8 @@ fn signatures() {
assert_eq!(
result,
Ok(Signature {
domain: Genus::List(Forma("Bits")),
range: Genus::Single(Forma("Bob"))
requires: Genus::List(Forma("Bits")),
provides: Genus::Single(Forma("Bob"))
})
);

Expand All @@ -189,8 +189,8 @@ fn signatures() {
assert_eq!(
result,
Ok(Signature {
domain: Genus::Single(Forma("Complex")),
range: Genus::Tuple(vec![Forma("Real"), Forma("Imaginary")])
requires: Genus::Single(Forma("Complex")),
provides: Genus::Tuple(vec![Forma("Real"), Forma("Imaginary")])
})
);
}
Expand Down Expand Up @@ -219,8 +219,8 @@ fn declaration_full() {
Identifier("f"),
None,
Some(Signature {
domain: Genus::Single(Forma("A")),
range: Genus::Single(Forma("B"))
requires: Genus::Single(Forma("A")),
provides: Genus::Single(Forma("B"))
})
))
);
Expand All @@ -235,8 +235,8 @@ fn declaration_full() {
Identifier("making_coffee"),
None,
Some(Signature {
domain: Genus::Tuple(vec![Forma("Beans"), Forma("Milk")]),
range: Genus::List(Forma("Coffee"))
requires: Genus::Tuple(vec![Forma("Beans"), Forma("Milk")]),
provides: Genus::List(Forma("Coffee"))
})
))
);
Expand Down Expand Up @@ -292,8 +292,8 @@ making_coffee :
Identifier("making_coffee"),
None,
Some(Signature {
domain: Genus::Single(Forma("Ingredients")),
range: Genus::Single(Forma("Coffee"))
requires: Genus::Single(Forma("Ingredients")),
provides: Genus::Single(Forma("Coffee"))
})
))
);
Expand All @@ -315,8 +315,8 @@ making_coffee(b, m) :
Identifier("making_coffee"),
Some(vec![Identifier("b"), Identifier("m")]),
Some(Signature {
domain: Genus::Tuple(vec![Forma("Beans"), Forma("Milk")]),
range: Genus::Single(Forma("Coffee"))
requires: Genus::Tuple(vec![Forma("Beans"), Forma("Milk")]),
provides: Genus::Single(Forma("Coffee"))
})
))
);
Expand Down
44 changes: 22 additions & 22 deletions src/parsing/checks/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn technique_header() {
version: 1,
license: None,
copyright: None,
template: None
domain: None
})
);

Expand All @@ -39,7 +39,7 @@ fn technique_header() {
version: 1,
license: Some("MIT"),
copyright: Some("ACME, Inc"),
template: Some("checklist")
domain: Some("checklist")
})
);
}
Expand All @@ -61,8 +61,8 @@ making_coffee : (Beans, Milk) -> Coffee
name: Identifier("making_coffee"),
parameters: None,
signature: Some(Signature {
domain: Genus::Tuple(vec![Forma("Beans"), Forma("Milk")]),
range: Genus::Single(Forma("Coffee"))
requires: Genus::Tuple(vec![Forma("Beans"), Forma("Milk")]),
provides: Genus::Single(Forma("Coffee"))
}),
elements: vec![],
})
Expand All @@ -88,8 +88,8 @@ second : C -> D
name: Identifier("first"),
parameters: None,
signature: Some(Signature {
domain: Genus::Single(Forma("A")),
range: Genus::Single(Forma("B"))
requires: Genus::Single(Forma("A")),
provides: Genus::Single(Forma("B"))
}),
elements: vec![],
})
Expand All @@ -102,8 +102,8 @@ second : C -> D
name: Identifier("second"),
parameters: None,
signature: Some(Signature {
domain: Genus::Single(Forma("C")),
range: Genus::Single(Forma("D"))
requires: Genus::Single(Forma("C")),
provides: Genus::Single(Forma("D"))
}),
elements: vec![],
})
Expand All @@ -127,8 +127,8 @@ making_coffee(e) : Ingredients -> Coffee
name: Identifier("making_coffee"),
parameters: Some(vec![Identifier("e")]),
signature: Some(Signature {
domain: Genus::Single(Forma("Ingredients")),
range: Genus::Single(Forma("Coffee"))
requires: Genus::Single(Forma("Ingredients")),
provides: Genus::Single(Forma("Coffee"))
}),
elements: vec![],
})
Expand Down Expand Up @@ -159,8 +159,8 @@ This is the first one.
name: Identifier("first"),
parameters: None,
signature: Some(Signature {
domain: Genus::Single(Forma("A")),
range: Genus::Single(Forma("B"))
requires: Genus::Single(Forma("A")),
provides: Genus::Single(Forma("B"))
}),
elements: vec![
Element::Title("The First"),
Expand Down Expand Up @@ -214,8 +214,8 @@ This is the first one.
name: Identifier("first"),
parameters: None,
signature: Some(Signature {
domain: Genus::Single(Forma("A")),
range: Genus::Single(Forma("B"))
requires: Genus::Single(Forma("A")),
provides: Genus::Single(Forma("B"))
}),
elements: vec![
Element::Title("The First"),
Expand Down Expand Up @@ -280,8 +280,8 @@ This is the first one.
name: Identifier("first"),
parameters: None,
signature: Some(Signature {
domain: Genus::Single(Forma("A")),
range: Genus::Single(Forma("B"))
requires: Genus::Single(Forma("A")),
provides: Genus::Single(Forma("B"))
}),
elements: vec![
Element::Title("The First"),
Expand Down Expand Up @@ -1287,8 +1287,8 @@ III. Implementation
name: Identifier("requirements_and_architecture"),
parameters: None,
signature: Some(Signature {
domain: Genus::Single(Forma("Concept")),
range: Genus::Naked(vec![
requires: Genus::Single(Forma("Concept")),
provides: Genus::Naked(vec![
Forma("Requirements"),
Forma("Architecture")
]),
Expand Down Expand Up @@ -1332,17 +1332,17 @@ III. Implementation
name: Identifier("define_requirements"),
parameters: None,
signature: Some(Signature {
domain: Genus::Single(Forma("Concept")),
range: Genus::Single(Forma("Requirements")),
requires: Genus::Single(Forma("Concept")),
provides: Genus::Single(Forma("Requirements")),
}),
elements: vec![],
},
Procedure {
name: Identifier("determine_architecture"),
parameters: None,
signature: Some(Signature {
domain: Genus::Single(Forma("Concept")),
range: Genus::Single(Forma("Architecture")),
requires: Genus::Single(Forma("Concept")),
provides: Genus::Single(Forma("Architecture")),
}),
elements: vec![],
},
Expand Down
Loading
Loading