2 # Compiles all .rl files for Ohcount.
3 # Written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
8 if [ -z "`grep '#EMBED' $file`" ]
10 # no embedded language
11 ragel $file -o "`cut -d '.' -f1 <<< "$file"`.h"
13 # embedded language(s)
14 elangs=`grep -o "#EMBED([a-z_]\+)" $file |
15 sed -e 's/#EMBED(\([a-z_]\+\))/\1/'`
17 # embed all languages into this temporary file to be compiled
20 # grab all lines before #EMBED statements
21 e_line=`grep -n -m 1 "#EMBED([a-z_]\+)" $file | cut -d ':' -f1`
22 sed -n -e "1,$e_line p" $file > $parser
24 # embed each language in the temporary file
27 echo -e "}%%\n%%{\n" >> $parser
30 # extract the embedded language contents for embedding
31 s_line=`grep -n "^%%{" $e_parser | cut -d ':' -f1`
32 e_line=`grep -n "^}%%" $e_parser | cut -d ':' -f1`
33 s_line=`expr $s_line + 1`
34 e_line=`expr $e_line - 1`
35 sed -n "$s_line,$e_line p;" $e_parser |
36 sed -e "s/^[ \t]*machine[^;]\+;//;
37 s/^[ \t]*write[^;]\+;//;
38 s/^[ \t]*include[^;]\+;//;" >> $parser
41 # grab all lines after #EMBED statements
42 s_line=`grep -n "#EMBED([a-z_]\+)" $file | cut -d ':' -f1 | sort -r |
44 sed -n -e "$s_line,$ p" $file >> $parser
46 ragel $parser -o "`cut -d '.' -f1 <<< "$file"`.h"