3
#######################################################################
5
# pgAdmin III - PostgreSQL Tools
6
# Copyright (C) 2002 - 2009, The pgAdmin Development Team
7
# This software is released under the BSD Licence
9
# parser.sh - Runs Flex and Bison and processes the generated files
11
#######################################################################
13
# Directory containing pgScript includes (relative to the src directory)
14
INCLUDEDIR="include/pgscript"
15
# Directory containing pgScript sources (relative to the src directory)
17
# Headers generated by Bison that need to be moved to ${INCLUDEDIR}
18
FILESTOMOVE=( "location.hh" "parser.tab.hh" "position.hh" "stack.hh" )
21
LEXER="pgscript/lex.pgs.cc"
23
AUX="pgscript/auxfile"
25
PARSER="pgscript/parser.tab.cc"
27
#######################################################################
29
# Find the current directory
33
# Go to the directory on top of the script directory
34
echo -n "cd ${THISDIR}/.. ... "
41
echo -n "+ Generating Bison output... "
42
bison -o"${PARSER}" "${SOURCEDIR}/pgsParser.yy"
46
echo -n "+ Generating Flex output... "
47
flex -o"${LEXER}" "${SOURCEDIR}/pgsScanner.ll"
50
# Add pgAdmin3.h include at the beginning and change <FlexLexer.h> to
51
# "pgscript/FlexLexer.h" for the Flex output
52
echo -n "+ Processing Flex output... "
53
cat "${LEXER}" | awk 'BEGIN {print "#include \"pgAdmin3.h\"\n\n"}{print $0}' \
54
| sed -e 's/<FlexLexer\.h>/"pgscript\/FlexLexer\.h"/g' > "${AUX}"
55
mv -f "${AUX}" "${LEXER}"
58
# Add pgAdmin3.h include at the beginning and a pragma and change
59
# "parser.tab.hh" to "pgscript/parser.tab.hh" to the Bison output
60
echo -n "+ Processing Bison output... "
61
cat "${PARSER}" | awk 'BEGIN {print "#include \"pgAdmin3.h\"\n#if _MSC_VER > 1000\n#pragma warning(disable: 4800)\n#endif\n"}{print $0}' | \
62
sed -e 's/"parser.tab.hh"/"pgscript\/parser\.tab\.hh"/g' > "${AUX}"
64
mv -f "${AUX}" "${PARSER}"
67
# Move Bison include files to the include directory
68
echo + "Moving Bison header files... "
69
for file in ${FILESTOMOVE[@]}
71
echo " + mv ${SOURCEDIR}/${file} ${INCLUDEDIR}/${file}"
72
mv "${SOURCEDIR}/${file}" "${INCLUDEDIR}/${file}"
76
# Go back to the previous directory
78
echo -n "cd $PREVDIR ... "