tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

stagedFormatterParsed.tri (1220B)


      1 -- Replacement fragment for the experimental formatter, not a standalone unit.
      2 -- The harness inserts it into the real formatter body, preserving all headers
      3 -- and dependencies before supplying their exact trees to the unit compiler.
      4 tfParsed line offset tokens = (let
      5   failed _ _ _ _ = nothing
      6   parsed (name, (patterns, assign)) body _ _ = (let
      7     nameEnd = sub (sourcePositionOffset (sourceTokenEnd name)) offset
      8     end = sub (tfLastEnd patterns (sourcePositionOffset (sourceTokenEnd name))) offset
      9     equalStart = sub (sourcePositionOffset (sourceTokenStart assign)) offset
     10     populated = and? (not? (emptyList? patterns)) (not? (emptyList? body))
     11     singleLine = and? (emptyList? (tfDepth body [])) (tfWithin tokens (add offset (length line)))
     12     cleanGaps = and? (tfGaps patterns line offset nameEnd) (tfSpaces (tfSlice end equalStart line))
     13     in (stageIf (and? populated (and? singleLine cleanGaps))
     14       (just (pair
     15         (pair (tfSpanCell line offset (sourceTokenStart name) (sourceTokenEnd name))
     16           (map (tfPatternCell line offset) patterns))
     17         (tfSlice equalStart (length line) line)))
     18       nothing))
     19   parsed _ _ _ _ = nothing
     20   in parserMatchReply failed parsed (tfHead tokens))