#!/bin/sh
#
# This file is part of the Phalcon Framework.
#
# (c) Phalcon Team <team@phalconphp.com>
#
# For the full copyright and license information, please view the
# LICENSE.txt file that was distributed with this source code.

find . -name \*.o -o -name \*.lo -o -name \*.loT | xargs rm -f
find . -name lemon -o -name parser.c | xargs rm -f
find . -name .libs | xargs rm -rf

if [ ! -f $(pwd)/lemon ]; then
	gcc -g lemon.c -o ./lemon
    chmod +x ./lemon
fi

re2c -W --no-debug-info --no-generation-date -o scanner.c scanner.re

./lemon -s parser.php7.lemon
echo '#include "php_phalcon.h"' > parser.c

cat parser.php7.c >> parser.c
cat base.c >> parser.c

sed s/"#line"/"\/\/"/g parser.c > xx && mv -f xx parser.c
sed s/"define TOKEN"/"define VTOKEN"/g parser.c > xx && mv -f xx parser.c
sed s/YY/VV/g scanner.c > xx && mv -f xx scanner.c
sed s/yy/vv/g scanner.c > xx && mv -f xx scanner.c
sed s/YY/VV/g parser.c > xx && mv -f xx parser.c
sed s/yy/vv/g parser.c > xx && mv -f xx parser.c
