Answer the final checks: the decision exemption's wording, info strings never close a fence, one formula length limit
This commit is contained in:
@@ -29,12 +29,11 @@ def sections(text: str) -> dict[str, list[str]]:
|
||||
blocks: list[tuple[str | None, list[str]]] = []
|
||||
opener = ""
|
||||
for line in text.splitlines():
|
||||
# A fence closes only on the opener's character, at least as long.
|
||||
if fence := FENCE.match(line):
|
||||
marker = fence.group(1)
|
||||
if not opener:
|
||||
opener = marker
|
||||
elif marker[0] == opener[0] and len(marker) >= len(opener):
|
||||
elif marker[0] == opener[0] and len(marker) >= len(opener) and not line[fence.end():].strip():
|
||||
opener = ""
|
||||
fenced = bool(opener or fence)
|
||||
if not fenced and line.startswith("## "):
|
||||
|
||||
+5
-4
@@ -57,7 +57,7 @@ import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
# Kept inside loop_claude/ so reload's fingerprint covers them; this tool shares the error type and README parser.
|
||||
# Kept inside loop_claude/ so reload's fingerprint covers them.
|
||||
from loop_claude.failure import Failure
|
||||
from loop_claude.file_writes import replace_file
|
||||
from loop_claude.project.premises import FENCE, sections
|
||||
@@ -65,6 +65,7 @@ from loop_claude.project.premises import FENCE, sections
|
||||
EXEMPTIONS = ("", "decision", "defect", "question", "security")
|
||||
ITEMS_HEADER = "| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |"
|
||||
LARGEST_FORMULA = 200
|
||||
LONGEST_FORMULA = 4 * LARGEST_FORMULA
|
||||
OPERATORS = (ast.Add, ast.BinOp, ast.Div, ast.Expression, ast.Load, ast.Mult, ast.Sub, ast.UAdd, ast.UnaryOp, ast.USub)
|
||||
VARIABLES = ("A", "G", "R", "S", "W")
|
||||
WEIGHTS_HEADER = "| Goal | W |"
|
||||
@@ -154,7 +155,7 @@ def read_all(todo: pathlib.Path) -> tuple[str, str, str] | Failure:
|
||||
|
||||
|
||||
def write(path: pathlib.Path, text: str) -> Failure | None:
|
||||
unwritten = replace_file(path, text.encode("utf-8"))
|
||||
unwritten = replace_file(path.resolve(), text.encode("utf-8"))
|
||||
return Failure(f"{path}: {unwritten.reason}") if unwritten else None
|
||||
|
||||
|
||||
@@ -279,8 +280,8 @@ def parse_formula(source: str | Failure) -> ast.Expression | Failure:
|
||||
if isinstance(source, Failure):
|
||||
return source
|
||||
# Deep nesting makes the parser itself run out of memory before LARGEST_FORMULA can count the parts.
|
||||
if len(source) > 4 * LARGEST_FORMULA:
|
||||
return Failure(f"the formula {source[:40]!r}... holds more than {4 * LARGEST_FORMULA} characters")
|
||||
if len(source) > LONGEST_FORMULA:
|
||||
return Failure(f"the formula {source[:40]!r}... holds more than {LONGEST_FORMULA} characters")
|
||||
try:
|
||||
tree = ast.parse(source, mode="eval")
|
||||
except (SyntaxError, ValueError):
|
||||
|
||||
@@ -310,6 +310,7 @@ class Sections(unittest.TestCase):
|
||||
def test_closes_a_fence_only_on_its_own_marker(self):
|
||||
text = "## Goals\n````md\n~~~\n## Quoted\n```\n````\n ~~~\n## Also quoted\n ~~~\n1. one\n## Audience\nme\n"
|
||||
self.assertEqual(list(premises.sections(text)), ["Goals", "Audience"])
|
||||
self.assertEqual(list(premises.sections("```\nquoted:\n```python\n## Inside\n```\n## Goals\n1. one\n")), ["Goals"])
|
||||
|
||||
|
||||
class Render(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user