Skip to content

Commit 77ed975

Browse files
authored
Improve embedded document for dlang codegen (#630)
1 parent 941f9bc commit 77ed975

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

schema_salad/dlang_codegen.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,30 @@ def __init__(
3535

3636
def prologue(self) -> None:
3737
"""Trigger to generate the prolouge code."""
38-
self.target.write(
39-
f"""/**
40-
* Generated by schema-salad code generator
41-
*
42-
* Date: {datetime.date.today().isoformat()}
43-
"""
44-
)
38+
39+
module_comment = []
40+
41+
if self.parser_info:
42+
module_comment.append(self.parser_info + "\n")
43+
44+
module_comment += [
45+
"This module was generated using schema-salad code generator.",
46+
"",
47+
"The embedded document is subject to the license of the original schema.",
48+
]
49+
4550
if self.copyright:
46-
self.target.write(f" * Copyright: {self.copyright}\n")
51+
module_comment.append(f"The original schema is {self.copyright}.")
52+
53+
module_comment += [
54+
"",
55+
"License: Apache-2.0",
56+
f"Date: {datetime.date.today().isoformat()}",
57+
]
58+
59+
self.target.write(self.to_doc_comment(module_comment))
4760
self.target.write(
48-
f""" */
49-
module {self.package};
61+
f"""module {self.package};
5062
5163
import salad.meta.dumper : genDumper;
5264
import salad.meta.impl : genCtor, genIdentifier, genOpEq;
@@ -121,7 +133,15 @@ def to_doc_comment(self, doc: Union[None, str, List[str]]) -> str:
121133
else:
122134
lines = sum((d.split("\n") for d in doc), [])
123135

124-
doc_lines = "\n".join((f" * {line}" for line in lines if line))
136+
if not lines[-1]:
137+
lines = lines[0:-1]
138+
139+
lines = [
140+
line.replace("`(`", "`$(LPAREN)`").replace("`)`", "`$(RPAREN)`")
141+
for line in lines
142+
]
143+
144+
doc_lines = "\n".join((f" * {line}" for line in lines))
125145

126146
return f"""/**
127147
{doc_lines}
@@ -248,11 +268,12 @@ def parse_enum(self, stype: Dict[str, Any]) -> str:
248268
return "\n///\npublic import salad.primitives : Expression;"
249269

250270
classname = self.safe_name(name)
251-
syms = [
252-
f' s{i} = "{shortname(sym)}"'
253-
for i, sym in enumerate(stype["symbols"])
254-
]
255-
syms_def = ",\n".join(syms)
271+
syms = "\n".join(
272+
(
273+
f' s{i} = "{shortname(sym)}", ///'
274+
for i, sym in enumerate(stype["symbols"])
275+
)
276+
)
256277

257278
if stype.get("documentRoot", False):
258279
doc_root_annotation = "@documentRoot "
@@ -268,9 +289,10 @@ def parse_enum(self, stype: Dict[str, Any]) -> str:
268289
return f"""
269290
{doc_comment}{doc_root_annotation}class {classname} : SchemaBase
270291
{{
292+
///
271293
enum Symbol
272294
{{
273-
{syms_def}
295+
{syms}
274296
}}
275297
276298
Symbol value;

0 commit comments

Comments
 (0)