Personal tools

Literate programming/Bird conversion via awk

From HaskellWiki

< Literate programming(Difference between revisions)
Jump to: navigation, search
(Breaking out from main literate programming page)
 
(fix missing slashes)
 
Line 3: Line 3:
 
<pre>
 
<pre>
 
# bird2code.awk
 
# bird2code.awk
^[^>] || ^$ {print; next}
+
/^[^>]/ || /^$/ {print; next}
   
^> {
+
/^>/ {
 
print "\\begin{code}"
 
print "\\begin{code}"
 
sub(/^> /,"")
 
sub(/^> /,"")
 
print
 
print
 
rc = getline
 
rc = getline
while(($0 ~ ^>) && (rc > 0)) {
+
while(($0 ~ /^>/) && (rc > 0)) {
 
sub(/^> /,"")
 
sub(/^> /,"")
 
print
 
print

Latest revision as of 12:34, 28 March 2008

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