Skip to content

Commit

Permalink
getSB usage was eliminated from the macros
Browse files Browse the repository at this point in the history
  • Loading branch information
verhas committed Dec 10, 2024
1 parent 4a3efe8 commit a8522d0
Show file tree
Hide file tree
Showing 52 changed files with 397 additions and 129 deletions.
2 changes: 1 addition & 1 deletion README.jrf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is a Jamal reference file containing serialized base64 encoded macros
# Created: 2024-12-06 15:26:42 +0100
# Created: 2024-12-10 17:58:05 +0100
# id|openStr|closeStr|verbatim|tailParameter|pure|content|parameters
# TOC
VE9D|eyU=|JX0=|0|0|0|Ci4gPDxJbnN0YWxsYXRpb24+PgouIDw8R1M+PgouIDw8Q29uZmlndXJhdGlvbj4+Ci4gPDxGZWF0dXJlcz4+Ci4gPDxDb250cmlidXRpbmc+PgouIDw8RG9jdW1lbnRhdGlvbj4+Ci4gPDxMaWNlbnNlPj4KLiA8PENoYW5nZWxvZz4+Ci4gPDxSb2FkbWFwPj4KLiA8PFN1cHBvcnQ+PgouIDw8RkFRPj4KLiA8PE1haW50ZW5hbmNlPj4=|
23 changes: 22 additions & 1 deletion RELEASES.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,35 @@
NOTE: The known bugs sections in the releases are updated after the release.
Plese consult the latest SNAPSHOT version available online at https://github.com/verhas/jamal/blob/master/RELEASES.adoc[GitHub Jamal RELEASES.adoc]

== https://github.com/verhas/jamal/tree/2.8.1[2.8.1]
== https://github.com/verhas/jamal/tree/2.8.2[2.8.2]

=== Known Bugs

__currently there are no known bugs in this release__

=== New Features

* The installation kit installed command line version includes the debugger.

* When starting the command line version using `-debug` without value it will start the HTTP debugger on the port `8080`.
If you need to start it on a different port use the ``-debug=http:port`` option.
Here `http:` is a literal string, and `port` is the port number.

* There is a macro module to read a local GIT repository, which is experimental in this release.

== https://github.com/verhas/jamal/tree/2.8.1[2.8.1]

=== Known Bugs

The command line version of the application does not include the debugger.
It is not a bug, per se.
You can start the debugger from the command line, but you have to start the application editing some shell scripts adding the dependency.
Because the jbang version does include the debugger, it was not considered a bug.
Starting with the release 2.8.1 there is an installation kit.
When using the Jamal command line installed with the installation kit, the debugger is not available.

=== New Features

* Functions depending on environment variables also read possible values from `.env` files.
This functionality can be achieved in prior versions using tools like `direnv`.
From this release Jamal itself reads the `.env` files.
Expand Down
23 changes: 22 additions & 1 deletion RELEASES.adoc.jam
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,35 @@
NOTE: The known bugs sections in the releases are updated after the release.
Plese consult the latest SNAPSHOT version available online at https://github.com/verhas/jamal/blob/master/RELEASES.adoc[GitHub Jamal RELEASES.adoc]

{%RELEASE KOMLO%}
{%RELEASE HARKIV%}

=== Known Bugs

__currently there are no known bugs in this release__

=== New Features

* The installation kit installed command line version includes the debugger.

* When starting the command line version using `-debug` without value it will start the HTTP debugger on the port `8080`.
If you need to start it on a different port use the ``-debug=http:port`` option.
Here `http:` is a literal string, and `port` is the port number.

* There is a macro module to read a local GIT repository, which is experimental in this release.

{%RELEASE KOMLO%}

=== Known Bugs

The command line version of the application does not include the debugger.
It is not a bug, per se.
You can start the debugger from the command line, but you have to start the application editing some shell scripts adding the dependency.
Because the jbang version does include the debugger, it was not considered a bug.
Starting with the release {%RELEASE:KOMLO%} there is an installation kit.
When using the Jamal command line installed with the installation kit, the debugger is not available.

=== New Features

* Functions depending on environment variables also read possible values from `.env` files.
This functionality can be achieved in prior versions using tools like `direnv`.
From this release Jamal itself reads the `.env` files.
Expand Down
3 changes: 2 additions & 1 deletion RELEASES.jim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ You can find some bare release numbers in the documentation even though the exis
my parents were there once
{@define ! RELEASE:ULANBATOR=1.12.3}

The first "next" (non-retrospect) release is named after the city where I lived in most of the my life.
The first "next" (non-retrospect) release is named after the city where I was born and where I lived in most of the my life.

{@define ! RELEASE:BUDAPEST=2.0.0}

Expand Down Expand Up @@ -65,4 +65,5 @@ a town very north in Russia
{@define ! RELEASE:PECSVARAD=2.7.0}
{@define ! RELEASE:PECS=2.8.0}
{@define ! RELEASE:KOMLO=2.8.1}
{@define ! RELEASE:HARKIV=2.8.2} to remember the heroic effort of the Ukrainian people on the 1000-th day of the Russian war

5 changes: 4 additions & 1 deletion documentation/macros/debug.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ When this option is on, the fact that a global and external debugger is defined

NOTE: The macro does not work inside the interactive embeddings like IntelliJ or AsciidocFx.
Starting up the debugger may cause several different issues in an environment like that.
Insread the macro in those environments returns a constant string that gets into the document, so you can see while editing.
Insread the macro in those environments returns a constant string that gets into the document, so you can see while editing.



2 changes: 1 addition & 1 deletion documentation/macros/include.adoc.jam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{%@import macrodoc.jim%}
{%MACRO name="include" since={%RELEASE:ZURICH%}%}
{%@snip:check file=../../jamal-core/src/main/java/javax0/jamal/builtins/Include.java hash=d09e14c9 %}
{%@snip:check file=../../jamal-core/src/main/java/javax0/jamal/builtins/Include.java hash=826bb6cc %}
{%@import ../../environmentvariables.jim%}
== Syntax

Expand Down
25 changes: 22 additions & 3 deletions jamal-api/src/main/java/javax0/jamal/api/Input.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package javax0.jamal.api;

/**
*
* The input Jamal is working with.
* This is essentially a stream of characters along with the position reference.
* When a macro is processed many times the output is also the input of the surrounding macro.
* When a macro is processed many times, the output is also the input of the surrounding macro.
* Therefore, many times the class implementing this interface is also used as output.
* The naming, therefore is a bit confusing.
* The naming, therefore, is a bit confusing.
* <p>
* An input has a string builder and also a file name from where the input is coming from.
* The string builder is used to fetch the characters.
Expand All @@ -15,12 +14,20 @@
*/
public interface Input extends CharSequence {
/**
* Do not use this method in code using the implementations of this interface.
* The implementations should
* <ul>
* <li>either perform the operation as described here to support the default implementations, or
* <li>implement the methods in a way that they do not use this method.
* </ul>
*
* Get the {@link StringBuilder} that contains the characters of the input. The processing many times works directly
* on the {@link StringBuilder} deleting characters from the start of it as the processing progresses, thus
* essentially modifying/mutating the {@code Input} object.
*
* @return the {@link StringBuilder} containing the characters of the input.
*/
@Deprecated()
StringBuilder getSB();

/**
Expand Down Expand Up @@ -118,6 +125,18 @@ default Input append(Object obj) {
return this;
}

/**
* replaces the current content of the input with the string representation of the {@code Object} argument.
*
* @param obj the object to be converted to string and replace the content of the input
* @return {@code this}
*/
default Input replace(Object obj) {
this.reset();
this.append(obj);
return this;
}

/**
* Delete all character from the input. Invokes {@link StringBuilder#setLength(int) setLength(0)} on the underlying
* StringBuilder.
Expand Down
2 changes: 1 addition & 1 deletion jamal-asciidoc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.18.1</version>
<version>1.18.3</version>
</dependency>
</dependencies>
<repositories>
Expand Down
4 changes: 1 addition & 3 deletions jamal-core/src/main/java/javax0/jamal/builtins/Defer.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ public void close() throws Exception {
}
final var reader = MacroReader.macro(processor);
final String result = reader.readValue(outputName).orElse(out);
final StringBuilder sb = output.getSB();
sb.setLength(0);
sb.append(result);
output.replace(result);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions jamal-core/src/main/java/javax0/jamal/builtins/Escape.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ public void close() throws Exception {
if (!processor.errors().isEmpty()) {
processor.throwUp();
}
output.getSB().setLength(0);
output.append(result);
output.replace(result);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion jamal-core/src/main/java/javax0/jamal/builtins/Include.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public String evaluate(Input input, Processor processor) throws BadSyntax {
final var weArePseudoDefault = processor.getRegister().open().equals("{") && processor.getRegister().close().equals("}");
final var useDefaultSeparators = in.length() > 1 && in.charAt(0) == IMPORT_SHEBANG1 && in.charAt(1) == IMPORT_SHEBANG2 && !weArePseudoDefault;
if (lines.isPresent()) {
Range.Lines.filter(in.getSB(), lines.get());
final var sb = new StringBuilder(in);
Range.Lines.filter(sb, lines.get());
in.replace(sb);
}
if (verbatim.is()) {
result = in.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,7 @@ public static class Postprocessor implements Macro, AutoCloseable, ProcessorAwar

@Override
public void close() {
final var sb = output.getSB();
final var text = sb.toString().toUpperCase(Locale.ENGLISH);
sb.setLength(0);
sb.append(text);
output.replace(output.toString().toUpperCase(Locale.ENGLISH));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public String fetch(Processor processor, Input input) throws BadSyntaxAt {
}
lines[j++] = lines[i];
}
final var sb = input.getSB();
sb.delete(0, sb.length());
sb.append(Arrays.stream(lines).limit(j).collect(Collectors.joining("\n")));
input.replace(Arrays.stream(lines).limit(j).collect(Collectors.joining("\n")));
return Macro.super.fetch(processor, input);
}

Expand Down
2 changes: 1 addition & 1 deletion jamal-groovy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-jsr223</artifactId>
<version>3.0.22</version>
<version>3.0.23</version>
</dependency>
</dependencies>
</project>
10 changes: 6 additions & 4 deletions jamal-groovy/src/main/java/javax0/jamal/groovy/GroovyCloser.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ private Closer(Shell shell, String closerScript) {

@Override
public void close() throws Exception {
shell.property("result", result.getSB());
final var resultSB = new StringBuilder(result);
shell.property("result", resultSB);
try {
final var sb = shell.evaluate(closerScript, null);
if (sb != null && sb != result.getSB()) {// NOT EQUALS, does it return the same object or not
result.getSB().setLength(0);
result.getSB().append(sb);
if (sb != null ) {
result.replace(sb);
}else{
result.replace(resultSB);
}
} catch (Exception e) {
throw new BadSyntax("There was an exception '"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public String evaluate(Input in, Processor processor) throws BadSyntax {
final var shell = Shell.getShell(in, processor, this);
final var scriptName = InputHandler.fetch2EOL(in).trim();
final Input script;
if (scriptName.length() > 0) {
if (!scriptName.isEmpty()) {
final var fileName = FileTools.absolute(in.getReference(), scriptName);
script = FileTools.getInput(fileName, processor);
} else {
script = in;
}
script.getSB().append(";''");
script.append(";''");
try {
shell.evaluate(script.toString(), scriptName);
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion jamal-groovy/src/main/java/javax0/jamal/groovy/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Shell(String id) {
}

public Object evaluate(String script, String fileName) {
if (fileName != null && fileName.length() > 0) {
if (fileName != null && !fileName.isEmpty()) {
return shell.evaluate(script, fileName);
} else {
return shell.evaluate(script, id + ".groovy");
Expand Down
6 changes: 2 additions & 4 deletions jamal-java/src/main/java/javax0/jamal/java/Jdsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ private static class State implements AutoCloseable, Closer.OutputAware {

@Override
public void close() throws Exception {
final var sb = output.getSB();
sb.delete(0, sb.length());
sb.append(result);
output.replace(result);
}

@Override
Expand All @@ -40,7 +38,7 @@ public String fetch(Processor processor, Input input) throws BadSyntaxAt {
final var original = Macro.super.fetch(processor, input);

processor.state(this, State::new).source = input.toString();
input.getSB().delete(0, input.length());
input.reset();
return original;
}

Expand Down
2 changes: 1 addition & 1 deletion jamal-ruby/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<version>9.4.8.0</version>
<version>9.4.9.0</version>
</dependency>
</dependencies>
</project>
5 changes: 2 additions & 3 deletions jamal-ruby/src/main/java/javax0/jamal/ruby/RubyCloser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ private Closer(Shell shell, String closerScript) {

@Override
public void close() throws Exception {
shell.property("$result", RubyString.newString(shell.shell.getProvider().getRuntime(), result.getSB()));
shell.property("$result", RubyString.newString(shell.shell.getProvider().getRuntime(), result));
try {
final var sb = shell.evaluate(closerScript, null);
BadSyntax.when(sb == null, "Ruby closer script '%s' returned null", shell.getId());
result.getSB().setLength(0);
result.getSB().append(sb);
result.replace(sb);
} catch (Exception e) {
throw new BadSyntax(String.format("There was an exception '%s' executing the ruby closer script in the shell '%s'.",
e.getMessage(), shell.getId()), e);
Expand Down
2 changes: 1 addition & 1 deletion jamal-ruby/src/main/java/javax0/jamal/ruby/RubyImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public String evaluate(Input in, Processor processor) throws BadSyntax {
} else {
script = in;
}
script.getSB().append("\n''");
script.append("\n''");
try {
shell.evaluate(script.toString(), scriptName);
} catch (Exception e) {
Expand Down
Loading

0 comments on commit a8522d0

Please sign in to comment.