Skip to content

Commit

Permalink
OnigurumaFlags to string
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Nov 19, 2024
1 parent b07f88e commit 890d8e1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function toRegExp(
type OnigurumaToEsOptions = {
accuracy?: 'strict' | 'default' | 'loose';
avoidSubclass?: boolean;
flags?: OnigurumaFlags;
flags?: string;
global?: boolean;
hasIndices?: boolean;
maxRecursionDepth?: number | null;
Expand Down Expand Up @@ -111,7 +111,7 @@ Returns an Oniguruma AST generated from an Oniguruma pattern.
function toOnigurumaAst(
pattern: string,
options?: {
flags?: OnigurumaFlags;
flags?: string;
}
): OnigurumaAst;
```
Expand Down
5 changes: 5 additions & 0 deletions scripts/onig-match.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {areMatchDetailsEqual, color, cp, err, ok, onigurumaResult, r, transpiledRegExpResult, value} from './utils.js';

// To run this script:
// - npm run onig:match '\w' 'a'
// - npm run onig:match '\n' '\u{A}'
// Don't use pnpm because it auto-escapes backslashes in string args

exec(process.argv.slice(2));

// Basic Oniguruma tester for the console; also reports a comparison with Oniguruma-to-ES
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {recursion} from 'regex-recursion';
@typedef {{
accuracy?: keyof Accuracy;
avoidSubclass?: boolean;
flags?: import('./tokenize.js').OnigurumaFlags;
flags?: string;
global?: boolean;
hasIndices?: boolean;
maxRecursionDepth?: number | null;
Expand Down Expand Up @@ -78,7 +78,7 @@ function toDetails(pattern, options) {
Returns an Oniguruma AST generated from an Oniguruma pattern.
@param {string} pattern Oniguruma regex pattern.
@param {{
flags?: import('./tokenize.js').OnigurumaFlags;
flags?: string;
}} [options]
@returns {import('./parse.js').OnigurumaAst}
*/
Expand Down
6 changes: 1 addition & 5 deletions src/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ const charClassTokenRe = new RegExp(r`
`.replace(/\s+/g, ''), 'gsu');

/**
@typedef {'i' | ''} FlagI
@typedef {'m' | ''} FlagM
@typedef {'x' | ''} FlagX
@typedef {`${FlagI}${FlagM}${FlagX}` | `${FlagI}${FlagX}${FlagM}` | `${FlagM}${FlagI}${FlagX}` | `${FlagM}${FlagX}${FlagI}` | `${FlagX}${FlagI}${FlagM}` | `${FlagX}${FlagM}${FlagI}`} OnigurumaFlags
@typedef {{
type: keyof TokenTypes;
raw: string;
Expand All @@ -133,7 +129,7 @@ const charClassTokenRe = new RegExp(r`
*/
/**
@param {string} pattern
@param {OnigurumaFlags} [flags] Oniguruma flags. Flag `m` is equivalent to JS flag `s`.
@param {string} [flags] Oniguruma flags. Flag `m` is equivalent to JS flag `s`.
@returns {TokenizerResult}
*/
function tokenize(pattern, flags = '') {
Expand Down

0 comments on commit 890d8e1

Please sign in to comment.