# This file is part of NIT ( http://www.nitlanguage.org ).
#
# Copyright 2009 Jean Privat <jean@pryen.org>
+# Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
outfile=$2
tmpfile=`mktemp "$2.XXXXXX"`
-echo -n "/* This file is autogenerated, do not modify it */" > "$outfile"
+printf "/* This file is autogenerated, do not modify it */" > "$outfile"
cat "$infile" >> "$outfile"
# The perl code is used to list all the available parameters in the extended grammar
-for token in `perl -ne 'if (/\~(\w+)/ && !$found{$1}) {print "$1\n"; $found{$1}=1}' "$infile"`
+for token in `perl -ne 'while (/\~([a-zA-Z]+)/g) {if (!$found{$1}) {print "$1\n"; $found{$1}=1}}' "$infile"`
do
echo "Parameter ~$token"
# first, sed starts from first line to the AST line and removes ~xxx and !xxx
- sed -n -e "1,/^Abstract Syntax Tree/{/^Abstract Syntax Tree/b;s/[\~!]$token//g;p}" "$outfile" > "$tmpfile"
+ sed -n -e "
+ 1,/^Abstract Syntax Tree/{
+ /^Abstract Syntax Tree/b
+ s/[\~!]$token//g
+ p
+ }
+ " "$outfile" > "$tmpfile"
# second, sed clones ~xxx parametrized productions, substitute ~xxx with _xxx and delete !xxx lines
- sed -n -e "/\~$token/,/;/{s/\~$token/_$token/g;/!$token/d;p}" "$outfile" >> "$tmpfile"
+ sed -n -e "
+ /\~$token/,/;/{
+ s/\~$token/_$token/g
+ /!$token/d
+ p
+ }
+ " "$outfile" >> "$tmpfile"
# third, sed continues fron AST line to last line and remove ~xxx and !xxx
- sed -n -e "/^Abstract Syntax Tree/,\${s/[\~!]$token//g;p}" "$outfile" >> "$tmpfile"
+ sed -n -e "
+ /^Abstract Syntax Tree/,\${
+ s/[\~!]$token//g
+ p
+ }
+ " "$outfile" >> "$tmpfile"
mv "$tmpfile" "$outfile"
done