-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgrammar_check.sh
67 lines (50 loc) · 1.47 KB
/
grammar_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# this file provides the SCL grammar checker
if [[ $# -ne 1 ]]
then
echo "need 1 argument (name of input file)"
exit 1
fi
if [[ ! -e $1 ]]
then
echo "file \"$1\" doesn't exist"
exit 1
fi
# context constants
ln_ctxt_size=6 # this is the lines before OR after, (so 2x+1 total lines printed)
# FIRST CHECK IF THIS IS A VALID ST FILE
cd matiec
compiler_output="$(./iec2iec -f -p ../$1 2>&1 > /dev/null | head -n -2)"
cd ..
if [ "$compiler_output" == "" ]
then
echo "SCL output passed compiler validation"
else
echo "SCL output failed compiler validation"
echo
echo "$compiler_output"
echo
echo "generating repair prompts for LLM"
echo
IFS=$'\n'
for l in $compiler_output
do
echo "This generated code did not work. Please see the following error message generated by an SCL compiler."
echo $l
echo "For reference, the context of the generated code around this error is provided below."
err_lns=$(echo $l | sed -r 's/^.*:([0-9]+-[0-9]+..[0-9]+-[0-9]+).*/\1/')
err_ln_start=$(echo $err_lns | sed -r 's/([0-9]+)-.*/\1/g')
err_ln_end=$(echo $err_lns | sed -r 's/[0-9]+-[0-9]+..([0-9]+).*/\1/g')
#echo
err_ln_start=$(($err_ln_start-ln_ctxt_size))
err_ln_start=$((err_ln_start < 1 ? 1 : err_ln_start))
err_ln_end=$(($err_ln_end+ln_ctxt_size))
#echo $err_ln_start
#echo $err_ln_end
sed -n "$err_ln_start,$err_ln_end p" $1
echo
# for auto_collect.sh to work
break
done
exit 1
fi