neo4j/neo4j — pull request #3258 by boggle (2014-10-09 23:08:44+00:00)
Title: Rewrite of perty to avoid stack build-up and erasure issues

Changes perty such that instead of building Docs for pretty printing
directly, we now build a flat heap representation (DocRecipes).
DocRecipes are abstract, i.e. contain unrendered values.
This is exactly how stack build-up is avoided: Each doc generator
just renders a tiny part of the document, keeping sub-components
abstract in the generated flat representation. An outer
loop continously processes the flat representation and tries
to render any abstract component it finds. Finally,
if all abstract components have been rendered, the flat
representation is turned into a Doc for actual pretty printing,
as before. This is done via simple, heap-based interpreter.

To keep things nice, each generator builds it's slice of
the flat representation using a tiny stack-based DSL.
However this should not be a stack build-up problem as
the nesting level for each individual generator (say
pretty printing of a FunctionInvocation) is just
a few levels deep.

This is the first version of perty with a working
astStructureDocGen (the ability to show both ast
and scala-like representation of ast nodes side by side).

Finally, this also uses scala reflection instead
of using pattern matching to help with some type
erasure problems we say with the old perty.

It is not yet clear wether the overhead is worth the
benefit, we'll have to try it for a while to know.
If it gets in the way, it should be straightforward
to remove using scala reflect.

This version of perty does not yet cover the whole ast
but it is now a in good shape to get started on that.

For reference, here's a condensed list of original
commits. History was squashed since almost all individual
commits where not in a green state.

o Adding scala-reflect dependency
o Add reflective perty (& bling) packages
o Refactor Extractors to be more practical
o Replace use of fix points with a flat reprensentation:
Add DocSteps, recipes, expand, and eval
o Rebuild pprintToString
o Move Doc helpers to Pretty DSL and fix scalaDocGen
o Fix Pretty DSL so that we can work with different types without calling pretty
o Make scalaDocGenWorkAgain
o Re-enable scalaDocGen using fancy type magic tricks
o Re-enable ast and plan doc gens
o Re-enable AstStructureDocGen
o More ast support for perty
o Update LICENSE files for scala reflect