swarm-0.6.0.0: 2D resource gathering game with programmable robots
LicenseBSD-3-Clause
Safe HaskellSafe-Inferred
LanguageHaskell2010

Swarm.Language.Parser.Comment

Description

Facilities for re-inserting parsed comments back into an AST. Actual parsing of comments is handled in Swarm.Language.Parser.Lex.

Synopsis

Comment AST insertion

populateComments :: Seq Comment -> Syntax -> Syntax Source #

Re-insert parsed comments into an AST. Prerequisite: the sequence of comments must be in order by SrcLoc.

populateStandaloneComments :: [Comment] -> Syntax -> Syntax Source #

Given a list of standalone comments sorted by SrcLoc, insert them into the given AST, attaching each comment to the earliest node in a preorder traversal which begins after it.

populateSuffixComments :: [Comment] -> Syntax -> Syntax Source #

Given a list of suffix comments sorted by SrcLoc, insert them into the given AST, attaching each comment to the latest node in a postorder traversal which begins before it.

Generic tree traversals

preorder :: (Plated a, Monad m) => (a -> m a) -> a -> m a Source #

Preorder traversal of a Plated structure with a monadic transformation. Apply the transformation at the root, then recursively transform each of the children.

>>> showTree (evalState (preorder next exampleTree) 0)
"0(1 2(3 4 5) 6(7))"

revpostorder :: (Plated a, Monad m) => (a -> m a) -> a -> m a Source #

Reverse postorder traversal of a Plated structure with a monadic transformation. Apply the transformation recursively to all the children in reverse order, then transform the root.

>>> showTree (evalState (revpostorder next exampleTree) 0)
"7(6 5(4 3 2) 1(0))"