tricu

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

app.tri (498B)


      1 !import text_support *
      2 !export normalizeNewlines
      3 
      4 -- Normalize CRLF and bare CR to LF; keep other Unicode code points intact.
      5 -- State remembers whether the preceding consumed character was CR.
      6 -- This demo requires the experimental staged source profile.
      7 normalizeNewlines text = (stageList text false
      8   (_ : [])
      9   (char afterCR : (stageIf (equal? char 13)
     10     (pair 10 (stageNext true))
     11     (stageIf (and? afterCR (equal? char 10))
     12       (stageNext false)
     13       (pair char (stageNext false))))))