From 4a073cbc795b64686083eb06ce401526a6412c93 Mon Sep 17 00:00:00 2001 From: Peter Verhas Date: Tue, 5 Dec 2023 17:04:56 +0100 Subject: [PATCH] jrf files now contain comments to make them more readable --- README.adoc | 2 +- README.jrf | 3 ++ jamal-snippet/README.adoc | 4 +- jamal-snippet/sample.jrf | 3 ++ .../java/javax0/jamal/snippet/References.java | 47 +++++++++++++----- .../src/test/resources/demoConverted.docx | Bin 12793 -> 12793 bytes .../test/resources/includetestConverted.docx | Bin 34572 -> 34572 bytes .../src/test/resources/pictureConverted.docx | Bin 21869 -> 21869 bytes .../src/test/resources/sampleConverted.docx | Bin 40809 -> 40815 bytes 9 files changed, 44 insertions(+), 15 deletions(-) diff --git a/README.adoc b/README.adoc index a71535b6c..66e144f0d 100644 --- a/README.adoc +++ b/README.adoc @@ -536,4 +536,4 @@ See the separate document: link:FAQ.adoc[FAQ]. -The documents of this project are formatted as Asciidoc documents with Jamal meta markup. \ No newline at end of file +The documents of this project are formatted as Asciidoc documents with Jamal meta markup. diff --git a/README.jrf b/README.jrf index 0fc242d77..bf2003f1e 100644 --- a/README.jrf +++ b/README.jrf @@ -1 +1,4 @@ +# This is a Jama reference file containing serialized base64 encoded macros +# id|openStr|closeStr|verbatim|tailParameter|pure|content|parameters +# TOC VE9D|eyU=|JX0=|0|0|0|Ci4gPDxJbnN0YWxsYXRpb24+PgouIDw8R1M+PgouIDw8Q29uZmlndXJhdGlvbj4+Ci4gPDxGZWF0dXJlcz4+Ci4gPDxDb250cmlidXRpbmc+PgouIDw8RG9jdW1lbnRhdGlvbj4+Ci4gPDxMaWNlbnNlPj4KLiA8PENoYW5nZWxvZz4+Ci4gPDxSb2FkbWFwPj4KLiA8PFN1cHBvcnQ+PgouIDw8RkFRPj4KLiA8PE1haW50ZW5hbmNlPj4=| diff --git a/jamal-snippet/README.adoc b/jamal-snippet/README.adoc index b88410ec8..e73e9fa34 100644 --- a/jamal-snippet/README.adoc +++ b/jamal-snippet/README.adoc @@ -3339,7 +3339,7 @@ will result - ShellVar.java: 3,837 bytes - Locate.java: 5,965 bytes - XmlDocument.java: 5,671 bytes -- References.java: 7,745 bytes +- References.java: 9,022 bytes - Java.java: 11,623 bytes - ReplaceLines.java: 3,479 bytes - SkipLines.java: 2,801 bytes @@ -3600,7 +3600,7 @@ will result in the output [source] ---- -2023-12-05 15:42:11 +2023-12-05 17:02:16 ---- diff --git a/jamal-snippet/sample.jrf b/jamal-snippet/sample.jrf index b9e2cb5cf..d8572f9b7 100644 --- a/jamal-snippet/sample.jrf +++ b/jamal-snippet/sample.jrf @@ -1 +1,4 @@ +# This is a Jama reference file containing serialized base64 encoded macros +# id|openStr|closeStr|verbatim|tailParameter|pure|content|parameters +# a YQ==|ew==|fQ==|0|0|0|VGhlIHZhbHVlIG9mIGE=| diff --git a/jamal-snippet/src/main/java/javax0/jamal/snippet/References.java b/jamal-snippet/src/main/java/javax0/jamal/snippet/References.java index 2f118f563..fb0e11e32 100644 --- a/jamal-snippet/src/main/java/javax0/jamal/snippet/References.java +++ b/jamal-snippet/src/main/java/javax0/jamal/snippet/References.java @@ -57,7 +57,7 @@ public String evaluate(final Input in, final Processor processor) throws BadSynt closer.addSerializedLines(macrosSerialized); final var deserializer = getDeserializerMacroObject(processor); for (var macroSerialized : macrosSerialized) { - if (macroSerialized.length() > 0) {// empty lines are ignored + if (notComment(macroSerialized)) {// empty and comment lines are ignored final var macro = deserializer.deserialize(macroSerialized); processor.defineGlobal(macro); } @@ -70,6 +70,10 @@ public String evaluate(final Input in, final Processor processor) throws BadSynt return ""; } + private static boolean notComment(String macroSerialized) { + return !macroSerialized.isEmpty() && macroSerialized.charAt(0) != '#'; + } + /** * Create a macro object that will be used to deserialize the strings into macro objects. * This deserializer macro object will (should) NOT be registered in the macro registry, hence the name is not @@ -140,7 +144,8 @@ void addSerializedLines(final List serialized) { @Override public void close() throws Exception { - final var sb = new StringBuilder(); + final var sb = new StringBuilder("# This is a Jama reference file containing serialized base64 encoded macros\n" + + "# id|openStr|closeStr|verbatim|tailParameter|pure|content|parameters\n"); final var missing = new ArrayList(); for (final var ref : holder.getObject()) { final var serialized = processor.getRegister() @@ -149,32 +154,50 @@ public void close() throws Exception { .map(macro -> (UserDefinedMacro) macro) .map(Serializing::serialize); if (serialized.isPresent()) { + sb.append("# ").append(ref).append('\n'); sb.append(serialized.get()).append('\n'); } else { missing.add(ref); } } - Files.writeString(Paths.get(file.toURI()), sb.toString(), StandardCharsets.UTF_8, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE); - BadSyntax.when(missing.size() > 0, "The following references are missing: " + String.join(", ", missing)); + Files.writeString(Paths.get(file.toURI()), sb.toString(), StandardCharsets.UTF_8, + StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE); + BadSyntax.when(!missing.isEmpty(), "The following references are missing: " + String.join(", ", missing)); if (macrosSerialized != null) { final var diff = checkIdempotency(macrosSerialized, sb.toString().split("\n")); - IdempotencyFailed.when(diff.length() > 0, "The following references are not idempotent: " + diff); + IdempotencyFailed.when(!diff.isEmpty(), "The following references are not idempotent: " + diff); } } + /** + * Check if the two sets of serialized macros are idempotent. The first set is the old set, and the second set is + * the new set. The method returns a string that contains the list of the macros that are new, deleted or + * changed. + *

+ * The serialization set may contain empty and comment lines. These are ignored. + * + * @param oldSet the old set of serialized macros as string + * @param newSet the new set of serialized macros as string + * @return the list of the macros that are new, deleted or changed, essentially a difference + * @throws BadSyntax if the deserialization of the serialized macro fails + */ private String checkIdempotency(String[] oldSet, String[] newSet) throws BadSyntax { final var diffMap = new HashMap(); final var deserializer = getDeserializerMacroObject(processor); for (final var line : oldSet) { - final var id = deserializer.deserialize(line).getId(); - diffMap.put(id, new String[]{line, null}); + if (notComment(line)) { + final var id = deserializer.deserialize(line).getId(); + diffMap.put(id, new String[]{line, null}); + } } for (final var line : newSet) { - final var id = deserializer.deserialize(line).getId(); - if (diffMap.containsKey(id)) { - diffMap.get(id)[1] = line; - } else { - diffMap.put(id, new String[]{null, line}); + if (notComment(line)) { + final var id = deserializer.deserialize(line).getId(); + if (diffMap.containsKey(id)) { + diffMap.get(id)[1] = line; + } else { + diffMap.put(id, new String[]{null, line}); + } } } final var err = new StringBuilder(); diff --git a/jamal-word/src/test/resources/demoConverted.docx b/jamal-word/src/test/resources/demoConverted.docx index ba10e2ebceedb94416489a21da081eb9b8008f2c..48f7cee4ad3fb98e9f3b079a77bf08a5ef68cc13 100644 GIT binary patch delta 169 zcmeyF{4<#+z?+#xgn@&DgCV+OBhNlY#*WRW8C5~lN2X2?Rn0O5NKF=CI|bz2W;5po zQo=&!ASrL*86fJ3$Z}>N)guAc?JaeZ7swOUxXlLC_EFCPNE+!|0Lg59TOheo-wsH= j&u`~)VA3_;?BhBiQQouM}XVEQ=C delta 169 zcmeyF{4<#+z?+#xgn@&DgCV+hBhNlY#@fxN8C5~lN2X2?Rn0O5NKF=CI|bz2W;5po zQo=&!ASrL*86fJ3$Z}>N)guAc?JaeZ7swOUxXlLC_EFCPNE+!|0Lg59TOheo-wsH= j&u`~)VA3_;?BhBiQQouM}X5t28> diff --git a/jamal-word/src/test/resources/includetestConverted.docx b/jamal-word/src/test/resources/includetestConverted.docx index b2fc6c13ee88b48c480667a6495d502bea85f95a..70a82cc3532f110079fea887b81a74ca4996f486 100644 GIT binary patch delta 176 zcmeC_W9sQ+;tB9(W)WfF;NW10?%2pPi;=No^KwRM5OtX82Z-9kQVgOD*kU+=R4>05 zh<8IkjR{Eo7rGk4*fH6FO?>m4^bc%6k-K?&c!1Qb>YE^5NmCb4_2mD}4nWeO#R5oH tw%7v6?Jagd@*9{mZS@4Q>s#%Cq*$ delta 176 zcmeC_W9sQ+;tB9(W)WfF;NW10uHDEpi;=N*^KwRM5OtX82Z-9kQVgOD*kU+=R4>05 zh<8IkjR{Eo7rGk4SUcH(O?>m4^bc%6k-K?&c!1Qb>YE^5NmCb4_2mD}4nWeO#R5oH tw%7v6?Jagd@*9{mZS@4Q>s#%CY@1q9w2qdX8{gCQa#WDNG1f@0?B!Sc0lrOAV^#;2*i#J@&uC0gY1Fi^B`v+sT~Yr iX9t61R|VUE#DkrHq*jP8kgN!a0FoC&0)eD*s22bp&rY@1q9w2qdX8{gCQa#WDNG1f@0?B!Sc0lrOAV^#;2*i#J@&uC0gY1Fi^B`v+sT~Yr iX9t61R|VUE#DkrHq*jP8kgN!a0FoC&0)eD*s22c$NKtwK diff --git a/jamal-word/src/test/resources/sampleConverted.docx b/jamal-word/src/test/resources/sampleConverted.docx index d986cd131e77cc5f201645ea94996c9adaf9d803..8c81f34a0aaec7941f54f363114449fc4e40c18c 100644 GIT binary patch delta 2269 zcmYk8cRbtM8^^^AZ3SH@LXDtkt=c0-QKQi|w58H&Y09-FsPS#hphiV&MXZ)uu}ahk z*DS4ZdyT3cHA7Gr!No7`U%&Im`~5l3^E&7Jd7fno>pF$?G{TaN{TvGz3}$h_Rh{kz zfp9fLpi3v(U_Jg%>;X*Sr}!?`0Gv~-%!U&;=0roMl27Eq8+f8AzJ7kD$}bn4970N2 zpA-vZhVL>J6r9f7om_#J3*!au`;BV~giWJnzq^m{gQ()jIjc=0n+p7w8e+BvE>cRS ziSxa}6^DaqvPIlGm1Qew)${ga;rqrK!YB>l7+`-dPeF;E;IY-vkol&lf3@xI^X&QI z1-G5A71VGsX{V z$D5u*i#F}cL5we*hd_=sm7-7>7EBFk_usAU6H}*jHaq22VcdRRV0E~Fj|jpDr-wdX z@>wmqw&N2QA%}qV4{GlcfE>_%)GPgX%0P6$CuOcaKb@eRP;5s*wysXi)+j+s^;%iX zdbJVEX|b6^|HqCz?iassK%gcq@Xp5;)G^+b3FT?*^|}QEnwA;Q5R&@Cn4l_@T32E6 zhP`SpVXTQuyl-W@`ft%xoauOazTk@G1Hm&rb*MkelpgopN`b?4NLl1My4BAL!zHx* zhP3+pBZ`>6^*iIn8tp@LHM+Dk;dyXS>8a#t9AdBKaIr^+{OxH5Z4CyWUaKJOi|NJN z*UXR`N1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