-
Notifications
You must be signed in to change notification settings - Fork 1
/
forgottenformat.sh
executable file
·45 lines (38 loc) · 1.18 KB
/
forgottenformat.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
#!/usr/bin/env bash
set -e
ANY_DOUBLE="([^\\\\\"]|\\\\\")*"
ANY_SINGLE="([^\\\\']|\\\\')*"
IS_CURLY="([{][^{]|[^}][}])"
EAT_DOUBLE="\"${ANY_DOUBLE}\""
EAT_SINGLE="'${ANY_SINGLE}'"
EAT_STRINGS="^([^\"'#]|${EAT_DOUBLE}|${EAT_SINGLE})*"
INVALID_F_DOUBLE="f\"([^\\\\\"}{]|\\\\\")*\""
INVALID_F_SINGLE="f'([^\\\\'}{]|\\\\')*'"
INVALIDS="${INVALID_F_DOUBLE}|${INVALID_F_SINGLE}"
NO_F_DOUBLE="[^rf]\"${ANY_DOUBLE}${IS_CURLY}${ANY_DOUBLE}\"" # we also allow r
NO_F_SINGLE="'${ANY_SINGLE}${IS_CURLY}${ANY_SINGLE}'" # we disallow any curls
NO_FS="${NO_F_DOUBLE}|${NO_F_SINGLE}"
MAIN_MATCH="(${NO_FS}|${INVALIDS})"
REGEX="${EAT_STRINGS}${MAIN_MATCH}"
echo ${REGEX}
! read -r -d '' PY_FILTER <<'EOF'
import sys
stdin = sys.stdin
stdout = sys.stdout
is_triple = False
while True:
line = stdin.readline()
if not line:
break
if line.count('"""') % 2 != 0:
is_triple = not is_triple
continue
if not is_triple:
stdout.write(line)
stdout.flush()
EOF
find . \( -name '*.py' -o -name '*.pyi' \) -and -not -path './venv/*' \
| xargs grep -nE "['\"]" \
| python3 -c "${PY_FILTER}" \
| grep -E "${REGEX}" \
| grep --color=always -nE "${MAIN_MATCH}"