Header: re_internal.h

Overview

Bytecode instructions for the NFA engine

Define Summary

#define MRB_RE_INTERNAL_H
#define RE_UNICODE_CASE
#define RE_UNICODE_CTYPE
#define RE_LOOK_NEGATED

RE_LOOK_END::a. The polarity says what a matched sub-pattern means. The landing bit asks that the sub-pattern have ended where the lookaround was entered, and stands only on a lookbehind whose branches take different widths, the one shape that can miss: rewound by a branch two characters wide, a branch one character wide matches and stops short. A lookahead starts where the search stands and a lookbehind of one width is that wide down every path, so neither can land anywhere else and neither pays for the test.

#define RE_LOOK_LANDING
#define RE_LB_PACK

RE_LB_WIDTH::offset packs the two units one width is counted in. Both are at most 255, the widest a lookbehind branch may be.

#define RE_LB_BYTES
#define RE_LB_CHARS
#define RE_CLASS_BITMAP_SIZE

Character class bitmap (ASCII range)

#define RE_CLASS_BYTE

A class member that is a byte rather than a codepoint, held in the same range list with this bit set. A pattern byte that starts no whole character is a byte, and the two spaces collide over U+0080 to U+00FF: the byte 0xB5 and the character U+00B5 both arrive as the number 0xB5, so the number alone cannot say which was written. The tag sits above every codepoint, so a tagged range can never overlap an untagged one.

#define RE_MAX_NAME_LEN

Longest capture name that fits in re_named_capture::name_len. The bound sits beside the field it describes so a later change of width is one line. The widening inside the macro is not cosmetic: on a target whose argument type is no wider than the field, the naive comparison is against a constant that type cannot exceed, and the compiler reports it.

#define RE_NAME_LEN_FITS
#define RE_ANCHOR_NONE

mrb_regexp_pattern::anchor. Ordered by how much each restricts where a match can start, so the weakest guarantee across branches is their min.

#define RE_ANCHOR_BOL
#define RE_ANCHOR_BOT
#define RE_FLAG_IGNORECASE
#define RE_FLAG_MULTILINE
#define RE_FLAG_EXTENDED

. matches \n (Ruby's /m for dot behavior)

#define MRB_REGEXP_STEP_LIMIT
#define MRB_REGEXP_STACK_LIMIT
#define MRB_REGEXP_PARSE_DEPTH_LIMIT
#define RE_OVER_STACK_LIMIT

What a search answers when the backtracking engine stopped before it had an answer (see mrb_re_exec()). The caller raises on it: what the search had found by then is not a shorter or a later match, and reading it as one was the defect. Which one it was names what to do about it: a limit names the knob to turn, where RE_NOMEM says the allocator refused and no knob will help. Turning MRB_REGEXP_STACK_LIMIT up in answer to a refused allocation would make the memory it failed to find scarcer still, so the two are kept apart all the way out of the engine.

#define RE_OVER_STEP_LIMIT
#define RE_NOMEM
#define RE_MAX_CAPTURES

Maximum captures

#define RE_MAX_PASS

A pike_vm step walks a repetition's body once per nesting level, so that a loop's final empty iteration can finish even when the closure resumed inside the body and already marked that iteration's tail (see add_thread). The cap keeps a pathologically nested pattern from growing the thread lists with the square of the program; past it, such a pattern keeps the older, stale-capture behaviour rather than costing memory.

#define RE_PASS_SPAN
#define RE_LIST_CAPA

Capacity of one pike_vm thread list, shared by the VM and by the cache the compiler pre-allocates for it so the two cannot drift. An instruction enqueues at most one thread per pass, and threads waiting on a later sp are carried over from the previous step on top of that.

#define RE_FOLD_LONG_S

The two foldings whose result is an ASCII letter. Every build carries them, whether or not it has the Unicode table, so that folding "ASCII only" covers the whole of the equivalence class an ASCII letter belongs to rather than the part of it that is ASCII: without them /k/i would miss U+212A and, the sign flipped, [^k] under /i would accept it.

#define RE_FOLD_KELVIN
#define RE_CLASS_HAS_CTYPE

Whether the class says anything about a character's type at all.

#define mrb_re_needs_case_data

Function Details