D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
forge
/
josepharmacy.online
/
Filename :
trace_blade.py
back
Copy
import re def trace_blade(filepath): with open(filepath, 'r') as f: lines = f.readlines() stack = [] pairs = { '@if': '@endif', '@foreach': '@endforeach', '@section': '@endsection', '@push': '@endpush', '@isset': '@endisset', '@empty': '@endempty', '@can': '@endcan', } for i, line in enumerate(lines, 1): # Use regex to find directives as whole words starting with @ matches = re.finditer(r'@(if|endif|foreach|endforeach|section|endsection|push|endpush|isset|endisset|empty|endempty|can|endcan|else|elseif)\b', line) for m in matches: directive = m.group(0) # Handle shorthand section: @section('name', 'value') if directive == '@section' and re.search(r"@section\s*\(\s*['\"].*?['\"]\s*,\s*", line): continue if directive in pairs: stack.append((directive, i)) elif directive in pairs.values(): if not stack: print(f"ERROR: {directive} on line {i} has no opener") continue opener, opener_line = stack[-1] if pairs[opener] == directive: stack.pop() else: print(f"ERROR: {directive} on line {i} tried to close {opener} from line {opener_line}") # Try to find the correct opener in the stack to recover found = False for j in range(len(stack) - 1, -1, -1): if pairs[stack[j][0]] == directive: print(f"Found matching {stack[j][0]} at line {stack[j][1]}, popping everything above it") stack = stack[:j] found = True break if not found: print(f"Could not find matching opener for {directive}") elif directive in ['@else', '@elseif']: if not stack or stack[-1][0] != '@if': print(f"ERROR: {directive} on line {i} is not inside an @if block") if stack: print("\nUNCLOSED BLOCKS:") for s in stack: print(f"{s[0]} opened on line {s[1]}") else: print("\nALL CLEAR") trace_blade('/home/mohamad-ayman/Desktop/pharmacy/resources/themes/default/web-views/users-profile/account-order-details.blade.php')