Skip to content

Add the simple stack machine display functions from other annotated prettyprinters #13

@quchen

Description

@quchen

This is a simpler kind of stack machine based rendering, when all we’re concerned about is printing output, pushing and popping based on certain SimpleDoc constructors. This won’t allow fancy stack machines that peek, double-push and what not.

e.g. annotated-wl-pprint contains:

displayDecoratedA :: (Applicative f, Monoid b)
                  => (String -> f b) -> (a -> f b) -> (a -> f b)
                  -> SimpleDoc a -> f b
displayDecoratedA str start end sd = display [] sd
  where display []        SEmpty              = pure mempty
        display stk       (SChar c x)         = (str [c]) <++> (display stk x)
        display stk       (SText l s x)       = (str s) <++> (display stk x)
        display stk       (SLine ind x)       = (str ('\n':indentation ind)) <++> (display stk x)
        display stk       (SAnnotStart ann x) = (start ann) <++> (display (ann:stk) x)
        display (ann:stk) (SAnnotStop x)      = (end ann) <++> (display stk x)

        -- malformed documents
        display []        (SAnnotStop _)      = error "stack underflow"
        display stk       SEmpty              = error "stack not consumed by rendering"

        (<++>) = liftA2 mappend

Convinced this is a good idea in #12.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions