memgraph/tools/lcp
Lovro Lugovic 0b2240e6e4 LCP: Split up PROCESS-FILE
Summary:
Split up `process-file` so that looking at the generated code for an LCP form is
easier from the REPL.

`process-lcp`, `generate-hpp` and `generate-cpp` now perform the generation of
C++ code, but take a list of "C++ elements" (the results of LCP forms) as input
and write their output to streams. They do no reading/evaluating of LCP forms of
their own.

`read-lcp` and `read-lcp-file` are used to read and evaluate a stream of LCP
forms. The latter is a specialized version for file streams which also reports
the position of the form within the file when an error happens.

`process-lcp-string` and `process-lcp-file` are convenient wrappers around the
main functionality that take a string (file) and output to strings (files).
Using `read-lcp` and `read-lcp-file` they process LCP forms and pass them off to
`process-lcp` for code generation.

Reviewers: mtomic, teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2097
2019-06-12 09:38:41 +02:00

58 lines
1.4 KiB
Bash
Executable File

#!/bin/bash -e
if [[ ! ($# -ge 1 && $# -le 3) ]]; then
echo "Usage: $0 [--debug] LCP_FILE [SLK_SERIALIZE]"
echo "Convert a LCP_FILE to C++ header file and output to stdout."
echo "If SLK_SERIALIZE is provided, then SLK serialization is generated."
exit 1
fi
debug=false
if [[ "$1" == "--debug" ]]; then
debug=true
shift
fi
if [[ ! -r "$1" ]]; then
echo "File '$1' doesn't exist or isn't readable"
exit 1
fi
lcp_file=`realpath $1`
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
quicklisp_install_dir="$HOME/quicklisp"
if [[ -v QUICKLISP_HOME ]]; then
quicklisp_install_dir="${QUICKLISP_HOME}"
fi
slk_serialize=""
if [[ "$2" == "SLK_SERIALIZE" ]]; then
slk_serialize=":slk-serialize-p t"
fi
if [[ $debug == "true" ]]; then
echo \
"
(load \"${quicklisp_install_dir}/setup.lisp\")
(ql:quickload :lcp :silent t)
(let ((*debugger-hook* #'lcp.debug:lcp-debugger-hook))
(lcp:process-lcp-file \"$lcp_file\" $slk_serialize))
" | sbcl --noinform --noprint
else
echo \
"
(load \"${quicklisp_install_dir}/setup.lisp\")
(ql:quickload :lcp :silent t)
(lcp:process-lcp-file \"$lcp_file\" $slk_serialize)
" | sbcl --script
fi
filename=`basename $lcp_file .lcp`
hpp_file="$(dirname $lcp_file)/$filename.hpp"
clang-format -style=file -i $hpp_file
if [[ -w "$lcp_file.cpp" ]]; then
clang-format -style=file -i "$lcp_file.cpp"
fi