Skip to content

Instantly share code, notes, and snippets.

@rhuanjl
rhuanjl / Regex System.md
Created April 25, 2020 18:25
Draft introductory documentation of ChakraCore's Regex System

Regex System

Introduction

The Regex implementation within ChakraCore has a few seperate components:

  • The Regex constructor object, prototype and library methods - these are implemented as part of the Javascript Library (inside lib/Runtime/Library) and call into the other Regex components when they need to.
  • The Regex Parser lib/Parser/RegexParser.cpp invoked by the main parser at parse time (for Regex literals) OR the Regex Constructor at runtime. Analyses the Regex creating an abstract syntax tree for it including sets of characters for each operation.
  • The Regex Pattern class lib/Parser/RegexPattern.cpp instances of this class are created when parsing a RegEx, and stored in an internal slot of any Js Regex object - they are then used whenever that Reh
  • The Regex Compiler lib/Parser/RegexCompileTime.cpp processes the parser output creating a RegexProgramme - a sequence of instructions with attached data (sets of characters) to be executed whenever the Regex is used, the created Programme is store
function inArrayNative(arr, value)
{
return (arr.indexOf(value) !== -1);
}
function inArrayJS(arr, value)
{
let length = arr.length;
let i = 0;
for(; i < length && arr[i] !== value; ++i);