Module Parslet::Atoms::CanFlatten
In: lib/parslet/atoms/can_flatten.rb

A series of helper functions that have the common topic of flattening result values into the intermediary tree that consists of Ruby Hashes and Arrays.

This module has one main function, flatten, that takes an annotated structure as input and returns the reduced form that users expect from Atom#parse.

NOTE: Since all of these functions are just that, functions without side effects, they are in a module and not in a class. Its hard to draw the line sometimes, but this is beyond.

Methods

Public Instance methods

Takes a mixed value coming out of a parslet and converts it to a return value for the user by dropping things and merging hashes.

Named is set to true if this result will be embedded in a Hash result from naming something using .as(…). It changes the folding semantics of repetition.

Flatten results from a repetition of a single parslet. named indicates whether the user has named the result or not. If the user has named the results, we want to leave an empty list alone - otherwise it is turned into an empty string.

@api private

Flatten results from a sequence of parslets.

@api private

Lisp style fold left where the first element builds the basis for an inject.

@api private

That annoying warning ‘Duplicate subtrees while merging result’ comes from here. You should add more ’.as(…)’ names to your intermediary tree.

[Validate]