mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
Adds `/regex/` as a regex constructor. A couple of fun points: 1. This makes generic the idea of arbitrary stuff adding a constant. Both SFunction and LRegex create a statically initialized constant. Both go through Locals to do this because they LRegex isn't directly iterable from SScript. 2. Differentiating `/` as-in-division from `/` as-in-start-of-regex is hard. See: http://www-archive.mozilla.org/js/language/js20-2002-04/rationale/syntax.html#regular-expressions The javascript folks have a way, way tougher time of it then we do because they have semicolon insertion. We have the much simpler delimiter rules. Even with our simpler life we still have to add a hack to get lexing `/regex/` to work properly. I chose to add token-level lookbehind because it seems to be a pretty contained hack. I considered and rejected lexer modes, a lexer member variable, having the parser set variables on the lexer (this is a fairly common solution for js, I believe), and moving regex parsing to the parser level. 3. I've only added a very small subset of java.util.regex to the whitelist because it is the subset I needed to test LRegex sanely. More deserves to be added, and maybe more regex syntax like `=~` and `==~`. Those can probably be added without too much pain.