Skip to content

ReactionCascade

A ReactionCascade holds an ordered list of Reaction objects where each step’s products are the next step’s reactants. Source spelling is a chain of arrows.

FieldTypeDescription
stepsArray of ReactionOrdered list; steps[0] is the first
┌─────────────────────────────────────────────┐
│ ReactionCascade │
│ │
│ steps[0] Reaction(A -> B) │
│ steps[1] Reaction(B -> C) │
│ steps[2] Reaction(C -> D) │
│ ... │
│ │
│ (each step's reactants are the previous │
│ step's products) │
└─────────────────────────────────────────────┘

A single reaction stays as Reaction. Two or more chained reactions promote to ReactionCascade. The grammar tries reaction_cascade (first reaction + at least one more arrow) before reaction.

AsciiChem.parse("A -> B").nodes.first.class # => Reaction
AsciiChem.parse("A -> B -> C").nodes.first.class # => ReactionCascade
reaction_cascade := reaction (arrow terms)+

The first leg is a full reaction. Each subsequent leg is arrow + terms; the transform’s CascadeBuilder constructs each new Reaction using the previous step’s products as reactants.

Formatters iterate the steps, emitting each step’s full reaction for the head and only arrow + products for subsequent steps (the intermediate reactants are implicit):

A -> B -> C -> D
^^^^^^^^^ first step (full reaction)
^^^^ second step (arrow + products)
^^^^ third step (arrow + products)
FormatterChain rendering
MathML<mrow> with reactants + arrow + products + arrow + products + ...
TextA -> B -> C -> D
HTMLUnicode arrows between terms
LaTeX\ce{A -> B -> C -> D} (mhchem native)
SVGLinear ASCII chain
AsciiChem.parse("A -> B -> C").to_text # => "A -> B -> C"
AsciiChem.parse("A -> B -> C -> D").to_text # => "A -> B -> C -> D"
AsciiChem.parse("A <=>[Fe][T] B -> C").to_text # => "A <=>[Fe][T] B -> C"
AsciiChem.parse("2A -> 2B -> 2C").to_text # => "2A -> 2B -> 2C"

Each step can have a different arrow kind:

A <=>[Fe][T] B -> C
A Fe T B C

steps[0].arrow = :equilibrium, steps[1].arrow = :forward. Both render correctly in every formatter.

class ReactionCascade
def children
steps
end
end

The linter walks each step (which is a Reaction) and recurses into its reactants and products.