+++ /dev/null
-#!/usr/bin/env bash
-/var/user_data/Thomas-developer/GQL_to_Cypher/tool/jdk-22.0.1+8/bin/java -cp /var/user_data/Thomas-developer/GQL_to_Cypher/tool/executor/antlr-4.11.1-complete.jar:jvm:jvm/PrintRuleNameList.jar PrintRuleNameList $@
+++ /dev/null
-#!/usr/bin/env bash
-/var/user_data/Thomas-developer/GQL_to_Cypher/tool/jdk-22.0.1+8/bin/java -cp /var/user_data/Thomas-developer/GQL_to_Cypher/tool/executor/antlr-4.11.1-complete.jar:jvm:jvm/Test__SyntaxTree_Arithmetic.jar Test__SyntaxTree_Arithmetic $@
#!/usr/bin/env bash
-#!/usr/bin/env bash
# Clean targets:
#
echo "Usage: clean <all [<program_name>] | program [<program_name>] | grammar [<name>] | class | temp[orary]>"
}
+# Function to clean a directory
+clean_directory() {
+ local dir="$1"
+ find "$dir" -type f ! -name '.githolder' -exec rm -f {} +
+}
+
+# Function to check if a program is in PROGRAM_FPL
+is_program_in_fpl() {
+ local program="$1"
+ for prog in $PROGRAM_FPL; do
+ if [[ "$prog" == *"$program"* ]]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+# Function to delete a program
+delete_program() {
+ local program="$1"
+ if is_program_in_fpl "$program"; then
+ echo "Deleting program files for '$program'"
+ rm -f "executor/$program" "$JAVA_COMP_OUT_DIR/$program.jar" "$JAVA_COMP_OUT_DIR/$program.class"
+ else
+ echo "Error: Program '$program' is not recognized or is not listed in PROGRAM_FPL."
+ return 1
+ fi
+}
+
# Command parser
clean_command_parser() {
local token_list=($@)
elif [ "$token_count" -eq 2 ]; then
case "$command" in
"all")
- clean_file_list "executor/$arg $JAVA_COMP_OUT_DIR/$arg.jar $JAVA_COMP_OUT_DIR/$arg.class"
- # program specific cleaning
+ # Program name is $arg.
+ delete_program "$arg"
+ # Custom cleaning for each program.
case "$arg" in
"SyntaxTree_Test")
clean_grammar "GQL_Test"
esac
;;
"program")
- clean_file_list "executor/$arg"
- clean_file_list "$JAVA_COMP_OUT_DIR/$arg.jar"
+ # Program name is $arg.
+ delete_program "$arg"
;;
"grammar")
+ # Grammar name is $arg.
clean_grammar "$arg"
;;
*)
fi
}
+source env_build
clean_command_parser $@
#!/usr/bin/env bash
if [ -z "$1" ]; then
- echo "Error: File list name is not provided."
+ exit 0
+fi
+
+# Determine the directory where the script is located
+script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Use `env -i` to clear the environment and then source `env_build` from the script's directory
+env -i bash -c "
+
+source '${script_dir}/env_build'
+
+var_name='$1'
+#echo 'var_name is: ' \$var_name
+if [ -z \"\$var_name\" ]; then
+ echo 'USAGE: clean_file_list <env_variable_name>'
exit 1
fi
-file_list=$(eval echo \$$1)
+# Check if the variable is defined in the current environment
+if [ -z \"\$(eval echo \\$\$var_name)\" ]; then
+ echo 'Error: Environment variable \"\$var_name\" is not defined in env_build.'
+ exit 1
+fi
-if [ -z "$file_list" ]; then
- echo "Error: File list $1 is empty or not set."
+# Check if the variable name contains 'PRIMARY' (case insensitive)
+if [[ \"\$var_name\" =~ [Pp][Rr][Ii][Mm][Aa][Rr][Yy] ]]; then
+ echo 'Error: Environment variable \"\$var_name\" contains \"PRIMARY\" so listed files were not deleted.'
exit 1
fi
-echo "Cleaning files: $file_list"
-for file in $file_list; do
- if [ -e "$file" ]; then
- echo rm -f "$file"
- rm -f "$file"
+# Check if the variable name ends with '_FPL'
+if [[ ! \"\$var_name\" =~ _FPL$ ]]; then
+ echo 'Error: Environment variable \"\$var_name\" must end with \"_FPL\".'
+ exit 1
+fi
+
+# Get the file list from the environment variable
+file_list=\$(eval echo \\$\$var_name)
+echo \$var_name \"=\" \$file_list
+
+if [ -z \"\$file_list\" ]; then
+ exit 0
+fi
+
+for file in \$file_list; do
+ if [ -e \"\$file\" ]; then
+ echo rm -f \"\$file\"
+ rm -f \"\$file\"
fi
done
+" "$1"
# Function to delete a specific grammar
delete_grammar() {
local grammar=$1
- echo "Attempting to delete grammar: $grammar"
+ # echo "Attempting to delete grammar: $grammar"
if [ -z "$grammar" ]; then
echo "Error: Grammar name is empty"
elif echo "$ANTLR_GRAMMAR_LIST" | grep -qw "$grammar"; then
# ANTLR files
#
-export ANTLR_IN_FPL=$(ls ${ANTLR_IN_PRIMARY_DIR}/*.g4 2>/dev/null | tr '\n' ' ')
-export ANTLR_GRAMMAR_LIST=$(basename -s .g4 ${ANTLR_IN_FPL})
-if [ -z "${ANTLR_IN_FPL}" ]; then
+export ANTLR_IN_PRIMARY_FPL=$(ls ${ANTLR_IN_PRIMARY_DIR}/*.g4 2>/dev/null | tr '\n' ' ')
+export ANTLR_GRAMMAR_LIST=$(basename -s .g4 ${ANTLR_IN_PRIMARY_FPL})
+if [ -z "${ANTLR_IN_PRIMARY_FPL}" ]; then
echo "No ANTLR input grammar files found"
fi
$(ANTLR_OUT_DIR)/%Lexer.java \
$(ANTLR_OUT_DIR)/%Parser.java \
$(ANTLR_OUT_DIR)/%BaseVisitor.java \
-$(ANTLR_OUT_DIR)/%Visitor.java: $(ANTLR_IN_PRIMARY_DIR)/%.g4
+$(ANTLR_OUT_DIR)/%Visitor.java: $(ANTLR_IN_PRIMARY_FPL)
@echo "making grammar from:" $<
$(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $<