tricu

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

consumer_layout_lexical.tri (1538B)


      1 -- Existing hand-built layout parser through the lexical target.
      2 !import "consumers.layout" Layout
      3 !import "consumers.structural" S
      4 !import "consumers.lexical-worker" X
      5 !import "prelude" !Local
      6 !import "parser" P
      7 !import "source.lexer" Source
      8 
      9 -- Intentional fixture copy from the demo: strip the artificial "x =" prefix.
     10 -- This fixture exercises the lexical lowering of a layout transition.
     11 bodyTokens source = (matchList t (_ rest :
     12   matchList t (_ remaining : remaining) rest)
     13   (P.parserReplyPayload (Source.lexGateSource source)))
     14 
     15 plain = X.lCompile Layout.layout
     16 committed = X.lCompile Layout.layoutWithCommit
     17 renamed = X.lCompile Layout.renamedLayout
     18 matches program worker source = (equal?
     19   (X.lRunChecked worker (bodyTokens source))
     20   (S.runConsumer program (bodyTokens source)))
     21 checks = foldl and? true [
     22   (resultIsOk plain)
     23   (resultIsOk committed)
     24   (resultIsOk renamed)
     25   (matches Layout.layout (resultOr t plain) "x = y")
     26   (matches Layout.layout (resultOr t plain) "x =\n  y")
     27   (matches Layout.layout (resultOr t plain) "x =\ny")
     28   (matches Layout.layout (resultOr t plain) "x =\n  7")
     29   (matches Layout.layout (resultOr t plain) "x = 7")
     30   (matches Layout.layout (resultOr t plain) "x =\n")
     31   (matches Layout.layout (resultOr t plain) "x =")
     32   (matches Layout.layoutWithCommit (resultOr t committed) "x = 7")
     33   (matches Layout.layoutWithCommit (resultOr t committed) "x =\n  7")
     34   (matches Layout.renamedLayout (resultOr t renamed) "x =\n")]
     35 main = matchBool "layout-lexical-ok" "layout-lexical-DIFFER" checks
     36 main