Difference between revisions of "Literate programming/Bird conversion via sed"

From HaskellWiki
Jump to navigation Jump to search
(Breaking out from main page of literate programming)
 
(Problems with no newline after last line of code)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
 
# bird2code.sed
 
# bird2code.sed
^> !p
+
/^>/ !p
^> {
+
/^>/ {
 
i\
 
i\
 
\\begin{code}
 
\\begin{code}
Line 20: Line 20:
 
}
 
}
 
</pre>
 
</pre>
  +
  +
should be run as:
  +
  +
sed -nf bird2code.sed < code.lhs > code.tex
  +
  +
Note that the above sed script does not handle all input well. For example, if the last line of an input file is a line of bird-style code and there is no newline before end-of-file, than the last "/end{code}" is omitted. You are advised to consider using the alternative [[Literate programming/Bird conversion via awk|awk script]].
  +
 
[[Category:Development tools]]
 
[[Category:Development tools]]

Latest revision as of 10:10, 7 November 2013

# bird2code.sed
/^>/ !p
/^>/ {
  i\
\\begin{code}

  :loop
  N
  /\n>[^\n]*$/{
    b loop
  }
  s/^> //
  s/\(\n\)> /\1/g
  s/\n$//
  a\
\\end{code}\

  p
}

should be run as:

sed -nf bird2code.sed < code.lhs > code.tex

Note that the above sed script does not handle all input well. For example, if the last line of an input file is a line of bird-style code and there is no newline before end-of-file, than the last "/end{code}" is omitted. You are advised to consider using the alternative awk script.