java.lang.Object
org.praxislive.project.SyntaxUtils
Various utility functions for parsing and writing values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringEscape the provided input for writing to a script, such that it can be parsed as a single value.static StringescapeQuoted(String input) Escape the provided input for writing to a script, such that it can be parsed as a single value.static booleanisSafeBraced(String input) Validate whether the provided input can be safely written as-is between braces without needing to be quote escaped.static org.praxislive.core.ValuevalueFromToken(URI context, org.praxislive.core.syntax.Token token) Extract a value from the provided token.static org.praxislive.core.ValuevalueFromToken(org.praxislive.core.syntax.Token token) Extract a value from the provided token.static StringvalueToToken(URI context, org.praxislive.core.Value value) Return the provided value as suitable token text to be included in a script.static StringvalueToToken(org.praxislive.core.Value value) Return the provided value as suitable token text to be included in a script.static voidwriteValue(URI context, org.praxislive.core.Value value, Appendable out) Write the provided value as suitable token text to the provided output.static voidwriteValue(org.praxislive.core.Value value, Appendable out) Write the provided value as suitable token text to the provided output.
-
Method Details
-
escape
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
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
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 contexttoken- script token- Returns:
- value
-
valueToToken
Return the provided value as suitable token text to be included in a script. Equivalent to passing a StringBuilder towriteValue(org.praxislive.core.Value, java.lang.Appendable)and returning the result.- Parameters:
value- value to write- Returns:
- value as script
-
valueToToken
Return the provided value as suitable token text to be included in a script. Equivalent to passing a StringBuilder towriteValue(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 contextvalue- value to write- Returns:
- value as script
-
writeValue
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 writeout- 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 contextvalue- value to writeout- target to write the value to- Throws:
IOException- if write fails
-