Skip to content

stdlib: regular expressions (Python-compatible subset) #962

Closed

Description

@godofecht

Gap

Flow has no regular expressions in the standard library.

Use case

challenges/flow-specific/catalog.json states each challenge's required and
forbidden syntax as Python regular expressions (116 distinct patterns:
classes, \s \w \d \b, groups, alternation, bounded repeats such as
[\s\S]{0,120}, lazy quantifiers, MULTILINE and DOTALL). Porting the
checker from Python to Flow meant matching them without re.

POSIX regcomp is not a substitute: its ERE has no \s, \d or lazy
repeats, glibc and macOS disagree on the extensions, and it works on bytes,
so {0,120} counts bytes where Python counts characters.

Current workaround

scripts/tools/lib/regex.flow: a backtracking matcher over code points for
the Python subset above, with continuation frames on an explicit stack and a
fast path for single-character repeats. It agrees with CPython on 80,172
catalog checks over every tracked .flow file and on 43 recorded
re.search cases (scripts/tools/challenge_check/regex_cases.json).
Backreferences and lookaround are rejected.

Request

A stdlib/regex.flow with compile, search, match, fullmatch and capture
groups. The tools copy could be the starting point if the API is acceptable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions