Class YamlComments

java.lang.Object
org.acemq.workloads.scenario.YamlComments

public final class YamlComments extends Object
Finds the comments in a YAML document, so that substitution can leave them alone.

Why this is needed at all

${VAR} is resolved over the whole file before anything parses it, which is the only way to let a placeholder appear anywhere — a rate, a queue name, a URL — without teaching the substituter the shape of the document. The cost of that was that it also ran over the comments, so a file explaining its own syntax to the next reader could not write the syntax down: # export ${BROKER_PASSWORD} before running this aborted the run with an unset-variable error, and the workaround was to describe the placeholder in words instead.

A comment is not part of the document. Nothing in it reaches the parser, so nothing in it has any business stopping the run.

What counts as a comment

A # that starts a line or follows a space or a tab, up to the end of that line — YAML's rule. A # inside a quoted scalar is a character like any other, so quoting is tracked, and a quote does not carry across a line break.

Block scalars (| and >) are not tracked: a # inside one is literal text to YAML and a comment to this. No file this tool reads has ever needed one, and the cost of being wrong is a placeholder left unresolved inside a block of prose rather than anything reaching a broker.

  • Method Details

    • mask

      public static boolean[] mask(String text)
      Parameters:
      text - a YAML document
      Returns:
      one flag per character, true where that character is inside a comment