build
This commit is contained in:
parent
a977a9b444
commit
ea7c079e30
2 changed files with 22 additions and 0 deletions
17
docs/dist/parse.js
vendored
17
docs/dist/parse.js
vendored
|
|
@ -27,6 +27,12 @@ function reify(thing) {
|
|||
}
|
||||
return pure(thing);
|
||||
}
|
||||
function minify(thing) {
|
||||
if (typeof thing === "string") {
|
||||
return mini(thing);
|
||||
}
|
||||
return reify(thing);
|
||||
}
|
||||
const applyOptions = (parent) => (pat, i) => {
|
||||
const ast = parent.source_[i];
|
||||
const options = ast.options_;
|
||||
|
|
@ -39,6 +45,9 @@ const applyOptions = (parent) => (pat, i) => {
|
|||
}
|
||||
console.warn(`operator "${operator.type_}" not implemented`);
|
||||
}
|
||||
if (options?.weight) {
|
||||
return pat;
|
||||
}
|
||||
const unimplemented = Object.keys(options || {}).filter((key) => key !== "operator");
|
||||
if (unimplemented.length) {
|
||||
console.warn(`option${unimplemented.length > 1 ? "s" : ""} ${unimplemented.map((o) => `"${o}"`).join(", ")} not implemented`);
|
||||
|
|
@ -52,6 +61,10 @@ export function patternifyAST(ast) {
|
|||
if (ast.arguments_.alignment === "v") {
|
||||
return stack(...children);
|
||||
}
|
||||
const weightedChildren = ast.source_.some((child) => !!child.options_?.weight);
|
||||
if (weightedChildren) {
|
||||
return timeCat(...ast.source_.map((child, i) => [child.options_?.weight || 1, children[i]]));
|
||||
}
|
||||
return sequence(...children);
|
||||
case "element":
|
||||
if (ast.source_ === "~") {
|
||||
|
|
@ -94,6 +107,10 @@ export const mini = (...strings) => {
|
|||
return pattern;
|
||||
};
|
||||
const m = mini;
|
||||
const s = (...strings) => {
|
||||
const patternified = strings.map((s2) => minify(s2));
|
||||
return stack(...patternified);
|
||||
};
|
||||
export const h = (string) => {
|
||||
const ast = krill.parse(string);
|
||||
return patternifyAST(ast);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue