Skip to content

Commit

Permalink
fix: formatting in view generator
Browse files Browse the repository at this point in the history
  • Loading branch information
johnstonskj committed Feb 17, 2024
1 parent 54997f7 commit 42cb4ba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sdml-generate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sdml-generate"
description = "Simple Domain Modeling Language (SDML) generated Artifacts"
version = "0.2.8"
version = "0.2.9"
authors = ["Simon Johnston <johnstonskj@gmail.com>"]
repository = "https://github.com/johnstonskj/rust-sdml.git"
license-file = "../LICENSE"
Expand Down
5 changes: 5 additions & 0 deletions sdml-generate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ The following figure demonstrates this package in the broader project context.

## Changes

**Version 0.2.9**

* Fix: formatting of annotations was broken for the view command.

**Version 0.2.8**

* Feature: adapted to new `HeaderValue` type in core.

**Version 0.2.7**

* Feature: Document generation for org-mode now includes the RDF version of a module and the dependency graph.
Expand Down
43 changes: 33 additions & 10 deletions sdml-generate/src/convert/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,25 @@ impl GenerateToWriter<SourceGenerationLevel> for SourceGenerator {

let body = module.body();
if body.has_imports() || body.has_annotations() || body.has_definitions() {
writer.write_all(format!("{}\n\n", keyword("is")).as_bytes())?;
writer.write_all(format!("{}\n", keyword("is")).as_bytes())?;

if body.has_imports() {
writer.write_all(EOL)?;
self.write_module_imports(body, writer, &options)?;
}

self.write_module_imports(body, writer, &options)?;
if body.has_annotations() {
writer.write_all(EOL)?;
self.write_annotations(
body.annotations(),
writer,
MODULE_ANNOTATION_INDENT,
&options,
)?;
}
self.write_module_definitions(body, writer, &options)?;
if body.has_definitions() {
self.write_module_definitions(body, writer, &options)?;
}

writer.write_all(format!("\n{}\n", keyword("end")).as_bytes())?;
} else {
Expand Down Expand Up @@ -193,9 +200,7 @@ impl SourceGenerator {
format!("{indentation}{} {imported}\n", keyword("import")).as_bytes(),
)?;
}
writer.write_all(EOL)?;
}

Ok(())
}

Expand Down Expand Up @@ -357,6 +362,9 @@ impl SourceGenerator {
DEFINITION_ANNOTATION_INDENT,
options,
)?;
if body.has_members() {
writer.write_all(EOL)?;
}
}
for member in body.members() {
self.write_member(member, writer, options)?;
Expand Down Expand Up @@ -398,9 +406,11 @@ impl SourceGenerator {
DEFINITION_ANNOTATION_INDENT,
options,
)?;
if body.has_variants() {
writer.write_all(EOL)?;
}
}
if body.has_variants() {
writer.write_all(b"\n")?;
for variant in body.variants() {
self.write_value_variant(variant, writer, options)?;
}
Expand Down Expand Up @@ -477,6 +487,9 @@ impl SourceGenerator {
DEFINITION_ANNOTATION_INDENT,
options,
)?;
if body.has_members() {
writer.write_all(EOL)?;
}
}
for member in body.members() {
self.write_member(member, writer, options)?;
Expand Down Expand Up @@ -523,15 +536,17 @@ impl SourceGenerator {
self.write_type_reference(defn.target_type(), writer, options)?;
if let Some(body) = defn.body() {
if body.has_annotations() && options.generate_member_bodies() {
writer.write_all(b" is")?;
writer.write_all(format!(" {}\n", keyword("is")).as_bytes())?;
self.write_annotations(
body.annotations(),
writer,
DEFINITION_ANNOTATION_INDENT,
MEMBER_ANNOTATION_INDENT,
options,
)?;
writer.write_all(b"end")?;
writer.write_all(format!("{indentation}{}\n", keyword("end")).as_bytes())?;
}
} else {
writer.write_all(EOL)?;
}
} else {
unreachable!()
Expand Down Expand Up @@ -603,7 +618,6 @@ impl SourceGenerator {
writer.write_all(paren_end().as_bytes())?;
}
}
writer.write_all(EOL)?;
Ok(())
}

Expand Down Expand Up @@ -633,6 +647,9 @@ impl SourceGenerator {
DEFINITION_ANNOTATION_INDENT,
options,
)?;
if body.has_roles() {
writer.write_all(EOL)?;
}
}
// TODO: roles
writer.write_all(format!("\n{indentation}{}\n", keyword("end")).as_bytes())?;
Expand Down Expand Up @@ -715,6 +732,9 @@ impl SourceGenerator {
DEFINITION_ANNOTATION_INDENT,
options,
)?;
if body.has_members() {
writer.write_all(EOL)?;
}
}
for member in body.members() {
self.write_member(member, writer, options)?;
Expand Down Expand Up @@ -756,6 +776,9 @@ impl SourceGenerator {
DEFINITION_ANNOTATION_INDENT,
options,
)?;
if body.has_variants() {
writer.write_all(EOL)?;
}
}
if body.has_variants() {
for variant in body.variants() {
Expand Down

0 comments on commit 42cb4ba

Please sign in to comment.