@zenuml/core 4.0.0 → 4.1.0
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/cli/zenuml.mjs +54 -0
- package/dist/cli/zenuml.mjs.map +1 -1
- package/dist/parser/index.cjs +3 -0
- package/dist/parser/index.cjs.map +1 -0
- package/dist/parser/index.mjs +23285 -0
- package/dist/parser/index.mjs.map +1 -0
- package/dist/zenuml.esm.mjs +1753 -1729
- package/dist/zenuml.esm.mjs.map +1 -1
- package/dist/zenuml.js +482 -482
- package/dist/zenuml.js.map +1 -1
- package/package.json +18 -7
- package/types/parser/index.d.ts +37 -0
package/dist/cli/zenuml.mjs
CHANGED
|
@@ -9648,6 +9648,21 @@ class SeqErrorListener extends antlr4.error.ErrorListener {
|
|
|
9648
9648
|
}
|
|
9649
9649
|
}
|
|
9650
9650
|
|
|
9651
|
+
// Reentrant error listener: collects syntax errors into its OWN instance array
|
|
9652
|
+
// instead of the shared module-level `errors`/`errorDetails`. This is what lets
|
|
9653
|
+
// validate()/parse() below run repeatedly or concurrently (e.g. server-side)
|
|
9654
|
+
// without the clear-before/clear-after dance the legacy globals require.
|
|
9655
|
+
class CollectingErrorListener extends antlr4.error.ErrorListener {
|
|
9656
|
+
constructor() {
|
|
9657
|
+
super();
|
|
9658
|
+
/** @type {{ line: number, column: number, msg: string }[]} */
|
|
9659
|
+
this.errorDetails = [];
|
|
9660
|
+
}
|
|
9661
|
+
syntaxError(recognizer, offendingSymbol, line, column, msg) {
|
|
9662
|
+
this.errorDetails.push({ line, column, msg });
|
|
9663
|
+
}
|
|
9664
|
+
}
|
|
9665
|
+
|
|
9651
9666
|
function createParser(code, { silent = false } = {}) {
|
|
9652
9667
|
const chars = new antlr4.InputStream(code);
|
|
9653
9668
|
const lexer = new sequenceLexer(chars);
|
|
@@ -9722,6 +9737,43 @@ antlr4.ParserRuleContext.prototype.getComment = function () {
|
|
|
9722
9737
|
);
|
|
9723
9738
|
};
|
|
9724
9739
|
|
|
9740
|
+
/**
|
|
9741
|
+
* Parse ZenUML DSL with a per-call (reentrant) error listener and return both
|
|
9742
|
+
* the error-recovered parse tree and a structured error list. Safe to call
|
|
9743
|
+
* repeatedly/concurrently — it does not touch the module-level Errors/ErrorDetails.
|
|
9744
|
+
*
|
|
9745
|
+
* @param {string} code ZenUML DSL source
|
|
9746
|
+
* @returns {{ rootContext: object, pass: boolean, errorDetails: { line: number, column: number, msg: string }[] }}
|
|
9747
|
+
*/
|
|
9748
|
+
function parse(code) {
|
|
9749
|
+
const listener = new CollectingErrorListener();
|
|
9750
|
+
const chars = new antlr4.InputStream(code);
|
|
9751
|
+
const lexer = new sequenceLexer(chars);
|
|
9752
|
+
lexer.removeErrorListeners();
|
|
9753
|
+
lexer.addErrorListener(listener);
|
|
9754
|
+
const tokens = new antlr4.CommonTokenStream(lexer);
|
|
9755
|
+
const parser = new sequenceParser(tokens);
|
|
9756
|
+
parser.removeErrorListeners();
|
|
9757
|
+
parser.addErrorListener(listener);
|
|
9758
|
+
const tree = parser.prog();
|
|
9759
|
+
return {
|
|
9760
|
+
rootContext: tree,
|
|
9761
|
+
pass: listener.errorDetails.length === 0,
|
|
9762
|
+
errorDetails: listener.errorDetails,
|
|
9763
|
+
};
|
|
9764
|
+
}
|
|
9765
|
+
|
|
9766
|
+
/**
|
|
9767
|
+
* Validate ZenUML DSL syntax without exposing the parse tree. Reentrant.
|
|
9768
|
+
*
|
|
9769
|
+
* @param {string} code ZenUML DSL source
|
|
9770
|
+
* @returns {{ pass: boolean, errorDetails: { line: number, column: number, msg: string }[] }}
|
|
9771
|
+
*/
|
|
9772
|
+
function validate(code) {
|
|
9773
|
+
const { pass, errorDetails } = parse(code);
|
|
9774
|
+
return { pass, errorDetails };
|
|
9775
|
+
}
|
|
9776
|
+
|
|
9725
9777
|
sequenceParser.ProgContext;
|
|
9726
9778
|
const RootContext = rootContext;
|
|
9727
9779
|
sequenceParser.GroupContext;
|
|
@@ -9740,6 +9792,8 @@ const Parser = {
|
|
|
9740
9792
|
const toCollector = ToCollector;
|
|
9741
9793
|
return toCollector.getParticipants(ctx);
|
|
9742
9794
|
},
|
|
9795
|
+
parse,
|
|
9796
|
+
validate,
|
|
9743
9797
|
Errors: errors,
|
|
9744
9798
|
ErrorDetails: errorDetails,
|
|
9745
9799
|
/**
|