AArevia
Workflows

Coding workflows · Rectangular CSS grid areas

03
Built around your work

A concrete starting point

Validate rectangular named areas in a grid of ASCII identifiers and single-dot empty cells. Check empty input, ragged rows and disconnected names, returning exclusive bounds only when every named area fills its rectangle.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Rectangular CSS grid areas

A concrete starting point
import re

def grid_areas(rows):
    if type(rows) is not list or any(type(r) is not str for r in rows):
        raise ValueError("grid.rows")
    if not rows:
        return {}
    cells = [r.split() for r in rows]
    width = len(cells[0])
    if not width or any(len(r) != width for r in cells):
        raise ValueError("grid.width")
    groups = {}
    for y, row in enumerate(cells):
        for x, name in enumerate(row):
            if name == ".":
                continue
            if not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_-]*", name):
                raise ValueError("grid.name")
            groups.setdefault(name, []).append((y, x))
    result = {}
    for name, points in groups.items():
        top, bottom = min(y for y,x in points), max(y for y,x in points)+1
        left, right = min(x for y,x in points), max(x for y,x in points)+1
        if len(points) != (bottom-top)*(right-left):
            raise ValueError("grid.rectangle")
        result[name] = (top, bottom, left, right)
    return result

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗