Package hydra
Interface Serialization
-
public interface SerializationUtilities for constructing generic program code ASTs, used for the serialization phase of source code generation.
-
-
Method Summary
Static Methods Modifier and Type Method Description static BracketsangleBraces()Angle bracket pair `<` `>` for use with `brackets`static ExprangleBracesList(BlockStyle style, java.util.List<Expr> els)Comma-separate the elements inside angle brackets in the given block style; renders as `<>` when emptystatic ExprbracesListAdaptive(java.util.List<Expr> els)Produce a bracketed list which separates elements by spaces or newlines depending on the estimated width of the expression.static ExprbracketList(BlockStyle style, java.util.List<Expr> els)Comma-separate the elements inside square brackets in the given block style; renders as `[]` when emptystatic ExprbracketListAdaptive(java.util.List<Expr> els)Produce a bracketed list which separates elements by spaces or newlines depending on the estimated width of the expression.static Exprbrackets(Brackets br, BlockStyle style, Expr e)Wrap an expression in the given bracket pair using the given block stylestatic ExprchooseLayout(java.lang.Integer threshold, Expr inlineExpr, Expr blockExpr)Pick between an inline and a multi-line layout for the same logical expression.static ExprcommaSep(BlockStyle v1, java.util.List<Expr> v2)Separate elements with a comma, using the given block stylestatic ExprcommaSepAdaptive(java.util.List<Expr> els)Comma-separate elements inline if the joined width fits, otherwise break onto separate lines.static Exprcst(java.lang.String s)Construct a constant expression from a literal stringstatic ExprcurlyBlock(BlockStyle style, Expr e)Wrap a single expression in curly braces using the given block stylestatic BracketscurlyBraces()Curly brace pair `{` `}` for use with `brackets`static ExprcurlyBracesList(Optional<java.lang.String> msymb, BlockStyle style, java.util.List<Expr> els)Separate the elements inside curly braces using the given symbol (default `,`) in the given block style; renders as `{}` when emptystatic java.lang.StringcustomIndent(java.lang.String idt, java.lang.String s)Indent every non-empty line of `s` by `idt`.static ExprcustomIndentBlock(java.lang.String idt, java.util.List<Expr> els)Render a list of expressions as a block whose first element starts where the surrounding context placed it and subsequent elements break onto fresh lines indented by the given prefixstatic ExprdotSep(java.util.List<Expr> v1)Separate elements with a dot and no surrounding whitespacestatic ExprdoubleNewlineSep(java.util.List<Expr> v1)Separate elements with a blank line between themstatic java.lang.StringdoubleSpace()The two-space string used as the canonical indent unitstatic java.lang.IntegerexpressionLength(Expr e)Find the approximate length (number of characters, including spaces and newlines) of an expression without actually printing it.static BlockStylefullBlockStyle()Block style with double-space indent and newlines both before and after the bracketed contentstatic BlockStylehalfBlockStyle()Block style with double-space indent, a newline before the content but not afterstatic Exprifx(Op op, Expr lhs, Expr rhs)Build an infix expression with the given operator and two operandsstatic java.lang.Stringindent(java.lang.String v1)Indent every non-empty line of a string by `doubleSpace`static ExprindentBlock(java.util.List<Expr> v1)Like `customIndentBlock`, but using `doubleSpace` as the indent prefixstatic ExprindentSubsequentLines(java.lang.String idt, Expr e)Indent every line of an expression except the first by the given prefixstatic ExprinfixWs(java.lang.String op, Expr l, Expr r)Space-separate three elements: left operand, operator string, right operandstatic ExprinfixWsList(java.lang.String op, java.util.List<Expr> opers)Space-separate operands interleaved with the given operator stringstatic BlockStyleinlineStyle()Block style with no indent and no surrounding newlines: contents stay on a single linestatic java.lang.IntegermaxLineWidth()The canonical maximum line width used by Hydra writers.static ExprnewlineSep(java.util.List<Expr> v1)Separate elements by a newline (no leading whitespace)static PaddingnoPadding()Operator padding with no whitespace on either sidestatic ExprnoSep(java.util.List<Expr> v1)Concatenate elements with no separator and no whitespacestatic Exprnum(java.lang.Integer i)Construct a constant expression from an int32static Opop(java.lang.String s, java.lang.Integer p, Associativity assoc)Build an op with single-space padding from a symbol, precedence, and associativitystatic OporOp(java.lang.Boolean newlines)Build the `|` alternative-separator operator.static ExprorSep(BlockStyle style, java.util.List<Expr> l)Separate alternatives with `|`, breaking onto separate lines when the block style requests a newline before contentstatic ExprparenList(java.lang.Boolean newlines, java.util.List<Expr> els)Comma-separate the elements inside parentheses; switches to a half-block style when newlines are requested and there is more than one element.static ExprparenListAdaptive(java.util.List<Expr> els)Produce a parenthesized list which separates elements by spaces or newlines depending on the estimated width of the expression.static Exprparens(Expr v1)Wrap an expression in inline parenthesesstatic Bracketsparentheses()Round parenthesis pair `(` `)` for use with `brackets`static Exprparenthesize(Expr exp)Recursively insert parentheses around subexpressions where required by operator precedence and associativity.static Exprprefix(java.lang.String p, Expr expr)Prepend a prefix string to an expression with no surrounding whitespacestatic java.lang.StringprintExpr(Expr e)Render an expression to a string, expanding bracket pairs, block styles, indents, and operator chainsstatic ExprsemicolonSep(java.util.List<Expr> v1)Separate elements with `;` inlinestatic Exprsep(Op op, java.util.List<Expr> els)Combine a list of expressions into a single OpExpr chain using the given operator.static ExprspaceSep(java.util.List<Expr> v1)Space-separate elements (no break between them)static ExprspaceSepAdaptive(java.util.List<Expr> els)Space-separate elements inline if the joined width fits, otherwise newline-separate them.static BracketssquareBrackets()Square bracket pair `[` `]` for use with `brackets`static ExprstructuralSep(Op op, java.util.List<Expr> els)Like sep, but produces a SeqExpr instead of an OpExpr chain.static ExprstructuralSpaceSep(java.util.List<Expr> v1)Like spaceSep, but produces a SeqExpr.static Exprsuffix(java.lang.String s, Expr expr)Append a suffix string to an expressionstatic Symbolsym(java.lang.String s)Construct a Symbol from a stringstatic ExprsymbolSep(java.lang.String symb, BlockStyle style, java.util.List<Expr> l)Separate elements with the given symbol; trailing whitespace per element is determined by the block style's newline-before/after flags (space, single break, or double break)static ExprtabIndent(Expr e)Indent every line of an expression by four spacesstatic ExprtabIndentDoubleSpace(java.util.List<Expr> exprs)Tab-indent a list of expressions, separated by blank linesstatic ExprtabIndentSingleSpace(java.util.List<Expr> exprs)Tab-indent a list of expressions, separated by single newlinesstatic ExprunsupportedType(java.lang.String label)Render a placeholder for a type the writer does not yet handle, e.g.static ExprunsupportedVariant(java.lang.String label, java.lang.String obj)Render a placeholder for an unsupported variant, including a string representation of the offending valuestatic ExprwithComma(Expr e)Append a trailing comma to an expressionstatic ExprwithSemi(Expr e)Append a trailing semicolon to an expression
-
-
-
Method Detail
-
angleBraces
static Brackets angleBraces()
Angle bracket pair `<` `>` for use with `brackets`
-
angleBracesList
static Expr angleBracesList(BlockStyle style, java.util.List<Expr> els)
Comma-separate the elements inside angle brackets in the given block style; renders as `<>` when empty
-
bracesListAdaptive
static Expr bracesListAdaptive(java.util.List<Expr> els)
Produce a bracketed list which separates elements by spaces or newlines depending on the estimated width of the expression.
-
bracketList
static Expr bracketList(BlockStyle style, java.util.List<Expr> els)
Comma-separate the elements inside square brackets in the given block style; renders as `[]` when empty
-
bracketListAdaptive
static Expr bracketListAdaptive(java.util.List<Expr> els)
Produce a bracketed list which separates elements by spaces or newlines depending on the estimated width of the expression.
-
brackets
static Expr brackets(Brackets br, BlockStyle style, Expr e)
Wrap an expression in the given bracket pair using the given block style
-
chooseLayout
static Expr chooseLayout(java.lang.Integer threshold, Expr inlineExpr, Expr blockExpr)
Pick between an inline and a multi-line layout for the same logical expression. Returns the inline form if its estimated width does not exceed the threshold, otherwise the block form. Note: the threshold is measured against the inline expression in isolation; surrounding indentation may push content beyond the threshold at print time. Callers that know they are nested can pass a smaller threshold to compensate.
-
commaSep
static Expr commaSep(BlockStyle v1, java.util.List<Expr> v2)
Separate elements with a comma, using the given block style
-
commaSepAdaptive
static Expr commaSepAdaptive(java.util.List<Expr> els)
Comma-separate elements inline if the joined width fits, otherwise break onto separate lines.
-
cst
static Expr cst(java.lang.String s)
Construct a constant expression from a literal string
-
curlyBlock
static Expr curlyBlock(BlockStyle style, Expr e)
Wrap a single expression in curly braces using the given block style
-
curlyBraces
static Brackets curlyBraces()
Curly brace pair `{` `}` for use with `brackets`
-
curlyBracesList
static Expr curlyBracesList(Optional<java.lang.String> msymb, BlockStyle style, java.util.List<Expr> els)
Separate the elements inside curly braces using the given symbol (default `,`) in the given block style; renders as `{}` when empty
-
customIndent
static java.lang.String customIndent(java.lang.String idt, java.lang.String s)Indent every non-empty line of `s` by `idt`. Empty lines stay empty (no trailing whitespace) so downstream byte-identity checks don't care about indent depth.
-
customIndentBlock
static Expr customIndentBlock(java.lang.String idt, java.util.List<Expr> els)
Render a list of expressions as a block whose first element starts where the surrounding context placed it and subsequent elements break onto fresh lines indented by the given prefix
-
dotSep
static Expr dotSep(java.util.List<Expr> v1)
Separate elements with a dot and no surrounding whitespace
-
doubleNewlineSep
static Expr doubleNewlineSep(java.util.List<Expr> v1)
Separate elements with a blank line between them
-
doubleSpace
static java.lang.String doubleSpace()
The two-space string used as the canonical indent unit
-
expressionLength
static java.lang.Integer expressionLength(Expr e)
Find the approximate length (number of characters, including spaces and newlines) of an expression without actually printing it.
-
fullBlockStyle
static BlockStyle fullBlockStyle()
Block style with double-space indent and newlines both before and after the bracketed content
-
halfBlockStyle
static BlockStyle halfBlockStyle()
Block style with double-space indent, a newline before the content but not after
-
ifx
static Expr ifx(Op op, Expr lhs, Expr rhs)
Build an infix expression with the given operator and two operands
-
indent
static java.lang.String indent(java.lang.String v1)
Indent every non-empty line of a string by `doubleSpace`
-
indentBlock
static Expr indentBlock(java.util.List<Expr> v1)
Like `customIndentBlock`, but using `doubleSpace` as the indent prefix
-
indentSubsequentLines
static Expr indentSubsequentLines(java.lang.String idt, Expr e)
Indent every line of an expression except the first by the given prefix
-
infixWs
static Expr infixWs(java.lang.String op, Expr l, Expr r)
Space-separate three elements: left operand, operator string, right operand
-
infixWsList
static Expr infixWsList(java.lang.String op, java.util.List<Expr> opers)
Space-separate operands interleaved with the given operator string
-
inlineStyle
static BlockStyle inlineStyle()
Block style with no indent and no surrounding newlines: contents stay on a single line
-
maxLineWidth
static java.lang.Integer maxLineWidth()
The canonical maximum line width used by Hydra writers. Adaptive helpers compare estimated expression widths against this threshold to decide whether to render inline or break across lines. Set to 120 to match the project-wide line-length convention.
-
newlineSep
static Expr newlineSep(java.util.List<Expr> v1)
Separate elements by a newline (no leading whitespace)
-
noPadding
static Padding noPadding()
Operator padding with no whitespace on either side
-
noSep
static Expr noSep(java.util.List<Expr> v1)
Concatenate elements with no separator and no whitespace
-
num
static Expr num(java.lang.Integer i)
Construct a constant expression from an int32
-
op
static Op op(java.lang.String s, java.lang.Integer p, Associativity assoc)
Build an op with single-space padding from a symbol, precedence, and associativity
-
orOp
static Op orOp(java.lang.Boolean newlines)
Build the `|` alternative-separator operator. The flag selects whether the right side breaks onto a new line.
-
orSep
static Expr orSep(BlockStyle style, java.util.List<Expr> l)
Separate alternatives with `|`, breaking onto separate lines when the block style requests a newline before content
-
parenList
static Expr parenList(java.lang.Boolean newlines, java.util.List<Expr> els)
Comma-separate the elements inside parentheses; switches to a half-block style when newlines are requested and there is more than one element. Renders as `()` when empty.
-
parenListAdaptive
static Expr parenListAdaptive(java.util.List<Expr> els)
Produce a parenthesized list which separates elements by spaces or newlines depending on the estimated width of the expression.
-
parentheses
static Brackets parentheses()
Round parenthesis pair `(` `)` for use with `brackets`
-
parenthesize
static Expr parenthesize(Expr exp)
Recursively insert parentheses around subexpressions where required by operator precedence and associativity. The traversal descends into bracket, indent, sequence, and operator expressions and parenthesizes left or right operands whose binding is weaker than the surrounding operator.
-
prefix
static Expr prefix(java.lang.String p, Expr expr)
Prepend a prefix string to an expression with no surrounding whitespace
-
printExpr
static java.lang.String printExpr(Expr e)
Render an expression to a string, expanding bracket pairs, block styles, indents, and operator chains
-
sep
static Expr sep(Op op, java.util.List<Expr> els)
Combine a list of expressions into a single OpExpr chain using the given operator. Returns the empty constant for an empty list.
-
spaceSep
static Expr spaceSep(java.util.List<Expr> v1)
Space-separate elements (no break between them)
-
spaceSepAdaptive
static Expr spaceSepAdaptive(java.util.List<Expr> els)
Space-separate elements inline if the joined width fits, otherwise newline-separate them. Useful for long signatures, type chains, and other space-joined sequences.
-
squareBrackets
static Brackets squareBrackets()
Square bracket pair `[` `]` for use with `brackets`
-
structuralSep
static Expr structuralSep(Op op, java.util.List<Expr> els)
Like sep, but produces a SeqExpr instead of an OpExpr chain. SeqExpr is treated as structural layout and is not subject to parenthesization.
-
structuralSpaceSep
static Expr structuralSpaceSep(java.util.List<Expr> v1)
Like spaceSep, but produces a SeqExpr. Use for structural layout that should not trigger parenthesization of children.
-
sym
static Symbol sym(java.lang.String s)
Construct a Symbol from a string
-
symbolSep
static Expr symbolSep(java.lang.String symb, BlockStyle style, java.util.List<Expr> l)
Separate elements with the given symbol; trailing whitespace per element is determined by the block style's newline-before/after flags (space, single break, or double break)
-
tabIndentDoubleSpace
static Expr tabIndentDoubleSpace(java.util.List<Expr> exprs)
Tab-indent a list of expressions, separated by blank lines
-
tabIndentSingleSpace
static Expr tabIndentSingleSpace(java.util.List<Expr> exprs)
Tab-indent a list of expressions, separated by single newlines
-
unsupportedType
static Expr unsupportedType(java.lang.String label)
Render a placeholder for a type the writer does not yet handle, e.g. `[bigint]`
-
unsupportedVariant
static Expr unsupportedVariant(java.lang.String label, java.lang.String obj)
Render a placeholder for an unsupported variant, including a string representation of the offending value
-
-