Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
match.c File Reference

Implements the OP_PCRE2_MATCH opcode (conditional build). More...

Go to the source code of this file.

Functions

 free_value (a)
 free_value (b)
 free_value (c)
 push_value (vm, make_nil())

Variables

case OP_PCRE2_MATCH
Value b = pop_value(vm)
Value c = pop_value(vm)
 break

Detailed Description

Implements the OP_PCRE2_MATCH opcode (conditional build).

Executes a single PCRE2 pattern match against a subject string and returns a map describing the first match and its capture groups when FUN_WITH_PCRE2 is enabled. Returns Nil when there is no match or on error. When PCRE2 support is disabled at build time, the opcode always returns Nil.

Definition in file match.c.

Function Documentation

◆ free_value() [1/3]

free_value(a)

◆ free_value() [2/3]

free_value(b)

◆ free_value() [3/3]

free_value(c)

◆ push_value()

push_value(vm,
make_nil() )

Variable Documentation

◆ b

Value b = pop_value(vm)

Definition at line 119 of file match.c.

◆ break

break

Definition at line 125 of file match.c.

◆ c

Value c = pop_value(vm)

Definition at line 121 of file match.c.

◆ OP_PCRE2_MATCH

case OP_PCRE2_MATCH

OP_PCRE2_MATCH: (pattern:any, text:any, flags:int|bool=0) -> map|Nil

Behavior when FUN_WITH_PCRE2 is enabled:

  • Pops: pattern, text, flags. Converts pattern/text to strings.
  • Flags bits:
    • 1 = PCRE2_CASELESS (I)
    • 2 = PCRE2_MULTILINE (M)
    • 4 = PCRE2_DOTALL (S)
    • 8 = PCRE2_UTF (U)
    • 16 = PCRE2_EXTENDED (X)
  • On successful match, returns a map with keys:
    • "full": matched substring (group 0)
    • "start": start index (int)
    • "end": end index (int, exclusive)
    • "groups": array of captured group strings (excluding group 0)
  • On no match or compile error, returns Nil.

Behavior when FUN_WITH_PCRE2 is disabled:

  • Pops three values and returns Nil.

Definition at line 43 of file match.c.