Class SyntaxUtils

java.lang.Object
org.praxislive.project.SyntaxUtils

public class SyntaxUtils extends Object
Various utility functions for parsing and writing values.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    escape(String input)
    Escape the provided input for writing to a script, such that it can be parsed as a single value.
    static String
    Escape the provided input for writing to a script, such that it can be parsed as a single value.
    static boolean
    Validate whether the provided input can be safely written as-is between braces without needing to be quote escaped.
    static org.praxislive.core.Value
    valueFromToken(URI context, org.praxislive.core.syntax.Token token)
    Extract a value from the provided token.
    static org.praxislive.core.Value
    valueFromToken(org.praxislive.core.syntax.Token token)
    Extract a value from the provided token.
    static String
    valueToToken(URI context, org.praxislive.core.Value value)
    Return the provided value as suitable token text to be included in a script.
    static String
    valueToToken(org.praxislive.core.Value value)
    Return the provided value as suitable token text to be included in a script.
    static void
    writeValue(URI context, org.praxislive.core.Value value, Appendable out)
    Write the provided value as suitable token text to the provided output.
    static void
    writeValue(org.praxislive.core.Value value, Appendable out)
    Write the provided value as suitable token text to the provided output.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • escape

      public static String escape(String input)
      Escape the provided input for writing to a script, such that it can be parsed as a single value. The value might be wrapped in quotation marks if necessary.
      Parameters:
      input - text input
      Returns:
      escaped text
    • escapeQuoted

      public static String escapeQuoted(String input)
      Escape the provided input for writing to a script, such that it can be parsed as a single value. The value will be wrapped in quotation marks.
      Parameters:
      input - text input
      Returns:
      escaped text
    • isSafeBraced

      public static boolean isSafeBraced(String input)
      Validate whether the provided input can be safely written as-is between braces without needing to be quote escaped. The check iterates through the input checking that any braces in the input text are correctly matched.
      Parameters:
      input - text input
      Returns:
      true if safe to write input in braces without escaping
    • valueFromToken

      public static org.praxislive.core.Value valueFromToken(org.praxislive.core.syntax.Token token)
      Extract a value from the provided token. Will attempt to parse plain tokens to the correct value type. Array and map subcommands will be parsed to the correct value types, including when nested.
      Parameters:
      token - script token
      Returns:
      value
    • valueFromToken

      public static org.praxislive.core.Value valueFromToken(URI context, org.praxislive.core.syntax.Token token)
      Extract a value from the provided token. Will attempt to parse plain tokens to the correct value type. Array and map subcommands will be parsed to the correct value types, including when nested. File subcommands will be resolved based on the provided context.
      Parameters:
      context - resource context
      token - script token
      Returns:
      value
    • valueToToken

      public static String valueToToken(org.praxislive.core.Value value)
      Return the provided value as suitable token text to be included in a script. Equivalent to passing a StringBuilder to writeValue(org.praxislive.core.Value, java.lang.Appendable) and returning the result.
      Parameters:
      value - value to write
      Returns:
      value as script
    • valueToToken

      public static String valueToToken(URI context, org.praxislive.core.Value value)
      Return the provided value as suitable token text to be included in a script. Equivalent to passing a StringBuilder to writeValue(java.net.URI, org.praxislive.core.Value, java.lang.Appendable) and returning the result. Resources will be relativized, if possible, to the provided context.
      Parameters:
      context - resource context
      value - value to write
      Returns:
      value as script
    • writeValue

      public static void writeValue(org.praxislive.core.Value value, Appendable out) throws IOException
      Write the provided value as suitable token text to the provided output. Values will be quoted as necessary, and map and array values will be converted to the equivalent subcommands.
      Parameters:
      value - value to write
      out - target to write the value to
      Throws:
      IOException - if write fails
    • writeValue

      public static void writeValue(URI context, org.praxislive.core.Value value, Appendable out) throws IOException
      Write the provided value as suitable token text to the provided output. Values will be quoted as necessary, and map and array values will be converted to the equivalent subcommands. Resources will be relativized, if possible, to the provided context using the file subcommand.
      Parameters:
      context - resource context
      value - value to write
      out - target to write the value to
      Throws:
      IOException - if write fails