2 # Compiles all .rl files for Ohcount.
3 # Written by Mitchell Foral. mitchell<att>caladbolg<dott>net.
5 # check to make sure we have ragel
6 if `type ragel > /dev/null 2> /dev/null`
8 echo "Found ragel, compiling..."
10 echo "ragel not found, aborting" >&2
16 echo "Compiling $file"
17 if [ -z "`grep '#EMBED' $file`" ]
19 # no embedded language
20 ragel $file -o "`cut -d '.' -f1 <<< "$file"`.h"
22 # embedded language(s)
23 elangs=`grep -o "#EMBED([a-z_][a-z_]*)" $file |
24 sed -e 's/#EMBED(\([a-z_][a-z_]*\))/\1/'`
26 # embed all languages into this temporary file to be compiled
29 # grab all lines before #EMBED statements
30 e_line=`grep -n -m 1 "#EMBED([a-z_][a-z_]*)" $file | cut -d ':' -f1`
32 sed -n -e "1,$e_line p" $file > $parser
34 # embed each language in the temporary file
37 echo -e "}%%\n%%{\n" >> $parser
40 # extract the embedded language contents for embedding
41 s_line=`grep -n "^%%{" $e_parser | cut -d ':' -f1`
42 e_line=`grep -n "^}%%" $e_parser | cut -d ':' -f1`
43 s_line=`expr $s_line + 1`
44 e_line=`expr $e_line - 1`
45 sed -n "$s_line,$e_line p;" $e_parser |
46 sed -e "s/^[ \t]*machine[^;][^;]*;//;
47 s/^[ \t]*write[^;][^;]*;//;
48 s/^[ \t]*include[^;][^;]*;//;" >> $parser
51 # grab all lines after #EMBED statements
52 s_line=`grep -n "#EMBED([a-z_][a-z_]*)" $file | cut -d ':' -f1 | sort -r |
53 grep -m 1 "^[0-9][0-9]*"`
54 sed -n -e "$s_line,$ p" $file >> $parser
56 ragel $parser -o "`cut -d '.' -f1 <<< "$file"`.h"