Literate programming/Bird conversion via awk

From HaskellWiki
< Literate programming
Revision as of 12:39, 11 July 2018 by Victor (talk | contribs) (Support files with lines which end right after the initial ">".)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Thanks to Peter Tillier from the comp.lang.awk newsgroup.

# bird2code.awk
/^[^>]/ || /^$/ {print; next}

/^>/ {
  print "\\begin{code}"
  sub(/^>( |$)/,"")
  print
  rc = getline
  while(($0 ~ /^>/) && (rc > 0)) {
    sub(/^>( |$)/,"")
    print
    rc = getline
  }
  print "\\end{code}\n"
}