mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 11:38:37 +00:00
feat: can now set a string parser for reify
This commit is contained in:
parent
c93fd900bc
commit
ea3e9de7ab
@ -13,6 +13,12 @@ import { unionWithObj } from './value.mjs';
|
|||||||
import { compose, removeUndefineds, flatten, id, listRange, curry, mod, numeralArgs, parseNumeral } from './util.mjs';
|
import { compose, removeUndefineds, flatten, id, listRange, curry, mod, numeralArgs, parseNumeral } from './util.mjs';
|
||||||
import drawLine from './drawLine.mjs';
|
import drawLine from './drawLine.mjs';
|
||||||
|
|
||||||
|
let stringParser;
|
||||||
|
// parser is expected to turn a string into a pattern
|
||||||
|
// if set, the reify function will parse all strings with it
|
||||||
|
// intended to use with mini to automatically interpret all strings as mini notation
|
||||||
|
export const setStringParser = (parser) => (stringParser = parser);
|
||||||
|
|
||||||
/** @class Class representing a pattern. */
|
/** @class Class representing a pattern. */
|
||||||
export class Pattern {
|
export class Pattern {
|
||||||
_Pattern = true; // this property is used to detect if a pattern that fails instanceof Pattern is an instance of another Pattern
|
_Pattern = true; // this property is used to detect if a pattern that fails instanceof Pattern is an instance of another Pattern
|
||||||
@ -1561,6 +1567,9 @@ export function reify(thing) {
|
|||||||
if (isPattern(thing)) {
|
if (isPattern(thing)) {
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
if (stringParser && typeof thing === 'string') {
|
||||||
|
return stringParser(thing);
|
||||||
|
}
|
||||||
return pure(thing);
|
return pure(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user