Personal tools

Literate programming/Bird conversion via awk

From HaskellWiki

< Literate programming
Revision as of 12:34, 28 March 2008 by Samason (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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"
}