module

Krikri::PythonPattern

Class methods

python_error(pattern : String) : String | Nil

Full "compile it the way Python would" check: nil when the pattern is valid under Python's own parser AND PCRE2, otherwise the re.error text Python's executor would wrap. Lets a plugin express the scan + compile + translate pipeline as one question instead of repeating its three steps.

Source
python_pcre_error(pcre_message : String, scan : Scan) : String

Translates a PCRE2 compile error (Crystal's wording, " at <byte offset>" suffix) into the re.error text Python's own parser raises for the same pattern, wherever the mapping is exact. PCRE2's offsets count BYTES; Python's re.error positions count CHARACTERS of the pattern as the user wrote it, so the offset goes byte -> translated char -> source char (the \uXXXX/\Uhhhhhhhh rewrites can move it). Cases without an exact mapping keep the PCRE2 wording - still inside the crash wrapper, which is the part users actually script against.

Source
quantifier_brace?(chars : Array(Char), close : Int32) : Bool

Whether the '}' at chars[close] closes a real {m,n}/ quantifier (used to tell Python's "multiple repeat" from "nothing to repeat" when PCRE2 reports an unusable quantifier after a brace).

Source
scan(pattern : String) : Scan
Source
source_index(scan : Scan, translated_char_index : Int32) : Int32

Translated-pattern char index -> original-pattern char index, through the \u/\U rewrites (each maps its whole output span to the source index of its backslash).

Source

Nested types