-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindent.bash
More file actions
78 lines (60 loc) 路 1.46 KB
/
Copy pathindent.bash
File metadata and controls
78 lines (60 loc) 路 1.46 KB
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
68
69
70
71
72
73
74
75
76
77
declare -gA IndentStack
IndentStack[index]=0
IndentStack[starting-block]=false
IndentStack[0]=0
ast:new-indentation() {
local indent
ast:indentation-required indent
ast:push-indentation $((indent+1))
IndentStack[starting-block]=true
}
ast:test-indentation() { #<<NOSHADOW>>
local value="$1" class="$2" out="$3"
local req found result temp_result
ast:indentation-required req
ast:count-indentation "$value" $class found
if ${IndentStack[starting-block]}; then
if [ $found -ge $req ]; then
IndentStack[starting-block]=false
IndentStack[${IndentStack[index]}]=$found
result=ok
else
result=error-start
fi
else
if [ $found -eq -1 ]; then
result=error-eof
elif [ $found -eq $req ]; then
result=ok
elif [ $found -lt $req ]; then
result=end
else
result=error-exact
fi
fi
setvar "$out" $result
}
noshadow ast:test-indentation 2
ast:update-indentation() {
IndentStack[${IndentStack[index]}]=$1
}
ast:pop-indentation() {
IndentStack[index]=$((${IndentStack[index]}-1))
}
ast:push-indentation() {
IndentStack[index]=$((${IndentStack[index]}+1))
ast:update-indentation $1
}
ast:indentation-required() {
setvar "$1" ${IndentStack[${IndentStack[index]}]}
}
ast:count-indentation() {
case "$2" in
whitespace) setvar "$3" "$1" ;;
eof) setvar "$3" -1 ;;
*) setvar "$3" 0 ;;
esac
}
ast:indentation-layers() {
setvar "$1" ${IndentStack[index]}
}