pala M-market-1b: CDC corrige (taxe 5% §3.8 confirmee, expiry TODO) + scripts/parencheck.py
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compteur de profondeur (parentheses) par ligne, strings/comments maskees.
|
||||
Usage: parencheck.py <fichier.java> [start] [end]
|
||||
Exige FINAL: 0."""
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
start = int(sys.argv[2]) if len(sys.argv) > 2 else 1
|
||||
end = int(sys.argv[3]) if len(sys.argv) > 3 else None
|
||||
|
||||
with open(path) as f:
|
||||
lines = f.readlines()
|
||||
|
||||
depth = 0
|
||||
in_block = False
|
||||
for i, raw in enumerate(lines, 1):
|
||||
line = raw.rstrip("\n")
|
||||
masked = []
|
||||
j = 0
|
||||
in_str = False
|
||||
in_char = False
|
||||
while j < len(line):
|
||||
if in_block:
|
||||
if line[j:j+2] == "*/":
|
||||
in_block = False
|
||||
j += 2
|
||||
else:
|
||||
j += 1
|
||||
continue
|
||||
if in_str:
|
||||
if line[j] == "\\":
|
||||
j += 2
|
||||
continue
|
||||
if line[j] == '"':
|
||||
in_str = False
|
||||
j += 1
|
||||
continue
|
||||
if in_char:
|
||||
if line[j] == "\\":
|
||||
j += 2
|
||||
continue
|
||||
if line[j] == "'":
|
||||
in_char = False
|
||||
j += 1
|
||||
continue
|
||||
if line[j:j+2] == "//":
|
||||
break
|
||||
if line[j:j+2] == "/*":
|
||||
in_block = True
|
||||
j += 2
|
||||
continue
|
||||
if line[j] == '"':
|
||||
in_str = True
|
||||
j += 1
|
||||
continue
|
||||
if line[j] == "'":
|
||||
in_char = True
|
||||
j += 1
|
||||
continue
|
||||
masked.append(line[j])
|
||||
j += 1
|
||||
code = "".join(masked)
|
||||
opens = code.count("(") - code.count(")")
|
||||
depth += opens
|
||||
if (end is None or (start <= i <= end)) and (opens != 0 or "Commands.literal" in line
|
||||
or "dispatcher.register" in line or ".executes(" in line):
|
||||
print(f"{i:5d} d={depth:+3d} ({opens:+3d}) {line.strip()[:100]}")
|
||||
|
||||
print(f"FINAL: {depth}")
|
||||
Reference in New Issue
Block a user