react-dsl-editor 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -62,6 +62,10 @@ export declare const eof: GrammarNode<never>;
62
62
 
63
63
  export declare function error<T extends string>(param: ParserError<T>): ParserError<T>;
64
64
 
65
+ export declare function extractAll<T extends string>(parserResult: ParserSuccess<T>, type: T): string[];
66
+
67
+ export declare function extractFirst<T extends string>(result: ParserSuccess<T>, name: T): string | undefined;
68
+
65
69
  export declare type FaultToleranceMode = 'skip-parser' | 'skip-input' | 'fuzzy-match' | 'partial-match';
66
70
 
67
71
  export declare interface GrammarNode<T extends string = never> {
@@ -1082,6 +1082,18 @@ function visit(o, h, g = (o) => o.text) {
1082
1082
  function visitPredicate(o, h, g = (o) => o.text) {
1083
1083
  return isParserError(o) ? [] : (h(o) ? [g(o)] : []).concat(...o.children?.flatMap((o) => visitPredicate(o, h, g)) ?? []);
1084
1084
  }
1085
+ function extractAll(o, h) {
1086
+ return visit(o, [h]);
1087
+ }
1088
+ function extractFirst(o, h) {
1089
+ if (!isParserError(o)) {
1090
+ if (nodeName(o) === h) return o.text;
1091
+ if (o.children?.length > 0) for (let g of o.children) {
1092
+ let o = extractFirst(g, h);
1093
+ if (o) return o;
1094
+ }
1095
+ }
1096
+ }
1085
1097
  function getSuggestions(o, h, g = () => void 0) {
1086
1098
  let _ = cstPathAt(o, h), v = t$1(_, t((o) => {
1087
1099
  if (nodeName(o) !== void 0) {
@@ -1466,4 +1478,4 @@ function DslEditor({ code: o, onChange: h, onParsed: v, grammar: S, wrap: T = !1
1466
1478
  })
1467
1479
  });
1468
1480
  }
1469
- export { DSLParser, DslEditor, ParsingError, alternative, asException, defaultSyntaxColors, eof, error, isParserError, isParserSuccess, named, newline, nodeName, optional, pathToString, pattern, rational, repeat, seq, sequence, success, term, visit, visitPredicate, ws };
1481
+ export { DSLParser, DslEditor, ParsingError, alternative, asException, defaultSyntaxColors, eof, error, extractAll, extractFirst, isParserError, isParserSuccess, named, newline, nodeName, optional, pathToString, pattern, rational, repeat, seq, sequence, success, term, visit, visitPredicate, ws };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-dsl-editor",
3
3
  "license": "MIT",
4
- "version": "0.4.5",
4
+ "version": "0.4.6",
5
5
  "repository": {
6
6
  "url": "git+https://github.com/rzymek/react-dsl-editor.git"
7
7
  },