@nidomiro/relation-tuple-parser
Version:
[](https://www.npmjs.com/package/@nidomiro/relation-tuple-parser)
75 lines • 3.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MyParserErrorListener = exports.MyRelationTupleVisitor = void 0;
const tree_1 = require("antlr4ts/tree");
const relation_tuple_syntax_error_1 = require("./errors/relation-tuple-syntax.error");
class MyRelationTupleVisitor extends tree_1.AbstractParseTreeVisitor {
defaultResult() {
return {
namespace: '',
object: '',
relation: '',
};
}
aggregateResult(aggregate, nextResult) {
Object.assign(aggregate, nextResult);
return aggregate;
}
visitRelationTuple(ctx) {
var _a, _b, _c, _d, _e, _f;
const aggregate = this.visitChildren(ctx);
const namespacedObjectContext = ctx.namespacedObject();
aggregate.relation = (_b = (_a = ctx._relation) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '';
aggregate.namespace = (_d = (_c = namespacedObjectContext._namespace) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : '';
aggregate.object = (_f = (_e = namespacedObjectContext._object) === null || _e === void 0 ? void 0 : _e.text) !== null && _f !== void 0 ? _f : '';
return aggregate;
}
visitSubjectId(ctx) {
const aggregate = this.visitChildren(ctx);
aggregate.subjectIdOrSet = ctx.text;
return aggregate;
}
visitSubjectSet(ctx) {
var _a, _b, _c, _d, _e;
const aggregate = this.visitChildren(ctx);
let namespacedObjectContext;
try {
namespacedObjectContext = ctx.namespacedObject();
}
catch (e) {
throw new relation_tuple_syntax_error_1.RelationTupleSyntaxError(`Expected SubjectSet to contain an namespaced object`);
}
const subjectIdOrSet = {
namespace: (_b = (_a = namespacedObjectContext._namespace) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '',
object: (_d = (_c = namespacedObjectContext._object) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : '',
};
if (((_e = ctx._subjectRelation) === null || _e === void 0 ? void 0 : _e.text) != null) {
subjectIdOrSet.relation = ctx._subjectRelation.text;
}
aggregate.subjectIdOrSet = subjectIdOrSet;
return aggregate;
}
}
exports.MyRelationTupleVisitor = MyRelationTupleVisitor;
class MyParserErrorListener {
constructor(wholeInput) {
this.wholeInput = wholeInput;
this._errors = [];
}
get errors() {
return this._errors;
}
syntaxError(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
recognizer, offendingSymbol, line, charPositionInLine) {
const errorDetail = {
wholeInput: this.wholeInput,
line,
charPositionInLine,
offendingSymbol: offendingSymbol === null || offendingSymbol === void 0 ? void 0 : offendingSymbol.text,
};
this._errors.push(errorDetail);
}
}
exports.MyParserErrorListener = MyParserErrorListener;
//# sourceMappingURL=relation-tuple-antlr.js.map