Spaces:
Running
Running
| import re | |
| content = """ | |
| Blockly.Blocks['ui_section'] = { | |
| init: function() { | |
| // ... | |
| this.setPreviousStatement(true, "basic_body_element"); | |
| } | |
| }; | |
| """ | |
| # Pattern 1: Original (Suspected broken) | |
| p1 = re.compile(r"\.setPreviousStatement\s*\(\s*true(?:,\s*(?:\[(.*?)\]|[\"\'](.*?)\"\']))?\s*\)", re.DOTALL) | |
| # Pattern 2: Simplified | |
| p2 = re.compile(r"\.setPreviousStatement\s*\(\s*true(?:,\s*(?:\[(.*?)\]|[\"'](.*?)[\"']))?\s*\)", re.DOTALL) | |
| # Pattern 3: Very Simple | |
| p3 = re.compile(r"\.setPreviousStatement\s*\(\s*true\s*,\s*[\"'](.*?)[\"']", re.DOTALL) | |
| def test(name, pattern, text): | |
| m = pattern.search(text) | |
| if m: | |
| print(f"{name}: MATCH! Groups: {m.groups()}") | |
| else: | |
| print(f"{name}: NO MATCH") | |
| print("--- Testing ui_section ---") | |
| test("Pattern 1", p1, content) | |
| test("Pattern 2", p2, content) | |
| test("Pattern 3", p3, content) | |