Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

modl-interpreter

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modl-interpreter - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

dist/grammar/antlr4/MODLLexer.d.ts

2

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.interpreter = void 0;
var Interpreter_1 = require("./modl-interpreter/Interpreter");
const Interpreter_1 = require("./modl-interpreter/Interpreter");
exports.interpreter = new Interpreter_1.Interpreter();
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Interpreter = void 0;
var ModlToJson_1 = require("./ModlToJson");
var Parser_1 = require("./Parser");
var Interpreter = (function () {
function Interpreter() {
const ModlToJson_1 = require("./ModlToJson");
const Parser_1 = require("./Parser");
class Interpreter {
interpretToJsonString(s) {
const jsonObject = this.interpretToJsonObject(s);
return JSON.stringify(jsonObject);
}
Interpreter.prototype.interpretToJsonString = function (s) {
var jsonObject = this.interpretToJsonObject(s);
return JSON.stringify(jsonObject);
};
Interpreter.prototype.interpretToPrettyJsonString = function (s) {
var jsonObject = this.interpretToJsonObject(s);
interpretToPrettyJsonString(s) {
const jsonObject = this.interpretToJsonObject(s);
return JSON.stringify(jsonObject, undefined, 4);
};
Interpreter.prototype.interpretToJsonObject = function (s) {
var modl = this.interpret(s);
}
interpretToJsonObject(s) {
const modl = this.interpret(s);
return ModlToJson_1.modlToJson(modl);
};
Interpreter.prototype.interpret = function (s) {
}
interpret(s) {
return new Parser_1.Parser().parse(s);
};
return Interpreter;
}());
}
}
exports.Interpreter = Interpreter;
//# sourceMappingURL=Interpreter.js.map

@@ -11,4 +11,4 @@ export declare class Modl {

export declare class ModlArray {
readonly items: [ModlValue];
constructor(items: [ModlValue]);
readonly items: ModlValue[];
constructor(items: ModlValue[]);
}

@@ -15,0 +15,0 @@ export declare class ModlPair {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModlBoolNull = exports.ModlString = exports.ModlQuoted = exports.ModlNumber = exports.ModlPair = exports.ModlArray = exports.ModlMap = exports.Modl = void 0;
var Modl = (function () {
function Modl(s) {
class Modl {
constructor(s) {
this.s = s;
}
return Modl;
}());
}
exports.Modl = Modl;
var ModlMap = (function () {
function ModlMap(items) {
class ModlMap {
constructor(items) {
this.items = items;
}
return ModlMap;
}());
}
exports.ModlMap = ModlMap;
var ModlArray = (function () {
function ModlArray(items) {
class ModlArray {
constructor(items) {
this.items = items;
}
return ModlArray;
}());
}
exports.ModlArray = ModlArray;
var ModlPair = (function () {
function ModlPair(key, value) {
class ModlPair {
constructor(key, value) {
this.key = key;
this.value = value;
}
return ModlPair;
}());
}
exports.ModlPair = ModlPair;
var ModlNumber = (function () {
function ModlNumber(value) {
class ModlNumber {
constructor(value) {
this.value = value;
}
return ModlNumber;
}());
}
exports.ModlNumber = ModlNumber;
var ModlQuoted = (function () {
function ModlQuoted(value) {
class ModlQuoted {
constructor(value) {
this.value = value;
}
return ModlQuoted;
}());
}
exports.ModlQuoted = ModlQuoted;
var ModlString = (function () {
function ModlString(value) {
class ModlString {
constructor(value) {
this.value = value;
}
return ModlString;
}());
}
exports.ModlString = ModlString;

@@ -54,0 +47,0 @@ var ModlBoolNull;

@@ -0,2 +1,3 @@

import { ModlContext } from '../grammar/antlr4/MODLParser';
import { Modl } from './Model';
export declare function visitModl(ctx: any): Modl;
export declare function visitModl(ctx: ModlContext): Modl;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.visitModl = void 0;
var Model_1 = require("./Model");
const TerminalNode_1 = require("antlr4ts/tree/TerminalNode");
const Model_1 = require("./Model");
function visitModl(ctx) {
var children = ctx.children.filter(nonTerminal);
var _a;
const children = (_a = ctx.children) === null || _a === void 0 ? void 0 : _a.filter(nonTerminal);
if (children.length === 1 && children[0].__proto__.constructor.name === 'Modl_primitiveContext') {
return new Model_1.Modl(visitModl_primitive(children[0]));
}
var structures = children.map(visitModl_structure);
return new Model_1.Modl(structures);
const structures = children.map(visitModl_structure);
if (structures) {
return new Model_1.Modl(structures);
}
return new Model_1.Modl(new Array());
}
exports.visitModl = visitModl;
function nonTerminal(ctx) {
return ctx.__proto__.constructor.name !== 'TerminalNodeImpl';
return ctx.__proto__.constructor.name !== 'TerminalNode';
}
function visitModl_structure(ctx) {
var ctxClassName = ctx.__proto__.constructor.name;
const ctxClassName = ctx.__proto__.constructor.name;
switch (ctxClassName) {

@@ -36,21 +41,36 @@ case 'Modl_mapContext':

function visitModl_map(ctx) {
var children = ctx.children.filter(nonTerminal).map(visitChild);
return new Model_1.ModlMap(children);
var _a;
const children = (_a = ctx.children) === null || _a === void 0 ? void 0 : _a.filter(nonTerminal).map(visitChild);
if (children) {
return new Model_1.ModlMap(children);
}
return;
}
function visitModl_array(ctx) {
var children = ctx.children.filter(nonTerminal).map(visitChild);
return new Model_1.ModlArray(children);
var _a;
const children = (_a = ctx.children) === null || _a === void 0 ? void 0 : _a.filter(nonTerminal).map(visitChild);
if (children) {
return new Model_1.ModlArray(children);
}
return;
}
function visitModl_pair(ctx) {
var key = ctx.children[0].getText();
if (!ctx.children) {
return;
}
const key = ctx.children[0].text;
validateKey(key);
var value = ctx.children[1].__proto__.constructor.name === 'TerminalNodeImpl' ? ctx.children[2] : ctx.children[1];
var pairValue = visitChild(value);
const value = ctx.children[1] instanceof TerminalNode_1.TerminalNode ? ctx.children[2] : ctx.children[1];
const pairValue = visitChild(value);
return new Model_1.ModlPair(key, pairValue);
}
function visitModl_value(ctx) {
return visitChild(ctx.children[0]);
const children = ctx.children;
if (children) {
return visitChild(children[0]);
}
return;
}
function visitModl_primitive(ctx) {
var text = ctx.getText();
const text = ctx.text;
if (!text || text === 'null' || text === '000') {

@@ -65,7 +85,7 @@ return Model_1.ModlBoolNull.ModlNull;

}
var intValue = Number.parseInt(text, 10);
const intValue = Number.parseInt(text, 10);
if (intValue.toString() === text) {
return new Model_1.ModlNumber(intValue);
}
var floatValue = Number.parseFloat(text);
const floatValue = Number.parseFloat(text);
if (floatValue.toString() === text) {

@@ -77,3 +97,3 @@ return new Model_1.ModlNumber(floatValue);

function visitChild(child) {
var childClassName = child.__proto__.constructor.name;
const childClassName = child.__proto__.constructor.name;
switch (childClassName) {

@@ -93,4 +113,4 @@ case 'Modl_structureContext':

default:
console.error("Unknown object: " + childClassName);
return new Model_1.ModlString("Unknown object: " + childClassName);
console.error(`Unknown object: ${childClassName}`);
return new Model_1.ModlString(`Unknown object: ${childClassName}`);
}

@@ -100,5 +120,5 @@ }

if (k.includes('%')) {
throw new Error("Interpreter Error: Invalid key - spaces and % characters are not allowed: " + k);
throw new Error(`Interpreter Error: Invalid key - spaces and % characters are not allowed: ${k}`);
}
}
//# sourceMappingURL=ModlParsedVisitor.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.modlToJson = void 0;
var Model_1 = require("./Model");
var Utils_1 = require("./Utils");
const Model_1 = require("./Model");
const Utils_1 = require("./Utils");
function modlToJson(modl) {

@@ -12,9 +12,9 @@ if (modl.s instanceof Array) {

else {
var result_1 = {};
modl.s.forEach(function (structure) {
const result = {};
modl.s.forEach((structure) => {
if (structure instanceof Model_1.ModlPair) {
pairToJson(structure, result_1);
pairToJson(structure, result);
}
if (structure instanceof Model_1.ModlMap) {
mapToJson(structure, result_1);
mapToJson(structure, result);
}

@@ -25,3 +25,3 @@ if (structure instanceof Model_1.ModlArray) {

});
return Object.keys(result_1).length === 0 ? null : result_1;
return Object.keys(result).length === 0 ? null : result;
}

@@ -64,5 +64,5 @@ }

}
var stringEscapeReplacer = Utils_1.createStringEscapeReplacer();
const stringEscapeReplacer = Utils_1.createStringEscapeReplacer();
function pairToJson(p, result) {
var key = stringEscapeReplacer.replace(p.key instanceof Model_1.ModlQuoted ? unquote(p.key.value) : unquote(p.key));
const key = stringEscapeReplacer.replace(p.key instanceof Model_1.ModlQuoted ? unquote(p.key.value) : unquote(p.key));
result[key] = toJson(p.value);

@@ -72,3 +72,3 @@ return result;

function mapToJson(m, result) {
m.items.forEach(function (i) {
m.items.forEach((i) => {
pairToJson(i, result);

@@ -79,4 +79,4 @@ });

function arrayToJson(a) {
var result = new Array();
a.items.forEach(function (x) {
const result = new Array();
a.items.forEach((x) => {
if (x instanceof Model_1.ModlArray) {

@@ -83,0 +83,0 @@ result.push(arrayToJson(x));

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParseCancellationException = exports.Parser = void 0;
var antlr4_1 = require("antlr4");
var ErrorListener_1 = require("antlr4/error/ErrorListener");
var modl = __importStar(require("modl-parser"));
var ModlParsedVisitor_1 = require("./ModlParsedVisitor");
var Parser = (function () {
function Parser() {
}
Parser.prototype.parse = function (s) {
var inputStream = new antlr4_1.InputStream(s);
var lexer = new modl.MODLLexer(inputStream);
var commonTokenStream = new antlr4_1.CommonTokenStream(lexer);
var parser = new modl.MODLParser(commonTokenStream);
const antlr4ts_1 = require("antlr4ts");
const MODLLexer_1 = require("../grammar/antlr4/MODLLexer");
const MODLParser_1 = require("../grammar/antlr4/MODLParser");
const ModlParsedVisitor_1 = require("./ModlParsedVisitor");
class Parser {
parse(s) {
const inputStream = antlr4ts_1.CharStreams.fromString(s);
const lexer = new MODLLexer_1.MODLLexer(inputStream);
const commonTokenStream = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new MODLParser_1.MODLParser(commonTokenStream);
lexer.addErrorListener(ThrowingErrorListener.INSTANCE);
parser.addErrorListener(ThrowingErrorListener.INSTANCE);
var context = parser.modl();
const context = parser.modl();
return ModlParsedVisitor_1.visitModl(context);
};
return Parser;
}());
}
}
exports.Parser = Parser;
var ParseCancellationException = (function () {
function ParseCancellationException(message, name) {
class ParseCancellationException {
constructor(message, name) {
this.message = message;
this.name = name;
}
return ParseCancellationException;
}());
}
exports.ParseCancellationException = ParseCancellationException;
var ThrowingErrorListener = (function (_super) {
__extends(ThrowingErrorListener, _super);
function ThrowingErrorListener() {
return _super !== null && _super.apply(this, arguments) || this;
}
ThrowingErrorListener.prototype.syntaxError = function (recognizer, offendingSymbol, line, column, msg) {
class ThrowingErrorListener {
syntaxError(recognizer, offendingSymbol, line, column, msg) {
if (recognizer) {
var message = "line " + line + ":" + column + " " + msg + " " + offendingSymbol;
const message = `line ${line}:${column} ${msg} ${offendingSymbol}`;
throw new ParseCancellationException(message, 'Syntax Error');

@@ -77,6 +37,5 @@ }

}
};
ThrowingErrorListener.INSTANCE = new ThrowingErrorListener();
return ThrowingErrorListener;
}(ErrorListener_1.ErrorListener));
}
}
ThrowingErrorListener.INSTANCE = new ThrowingErrorListener();
//# sourceMappingURL=Parser.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStringEscapeReplacer = void 0;
exports.createStringEscapeReplacer = function () {
exports.createStringEscapeReplacer = () => {
return new StringEscapeReplacerImpl();
};
var StringEscapeReplacerImpl = (function () {
function StringEscapeReplacerImpl() {
}
StringEscapeReplacerImpl.prototype.replace = function (stringToTransform) {
var result = convertUnicodeSequences(stringToTransform);
var _loop_1 = function (i) {
replacements.forEach(function (v, k) {
class StringEscapeReplacerImpl {
replace(stringToTransform) {
let result = convertUnicodeSequences(stringToTransform);
for (let i = 0; i < result.length; i++) {
replacements.forEach((v, k) => {
if (result.startsWith(k, i)) {

@@ -18,11 +16,7 @@ result = result.substring(0, i) + v + result.substring(i + k.length);

});
};
for (var i = 0; i < result.length; i++) {
_loop_1(i);
}
return result;
};
return StringEscapeReplacerImpl;
}());
var replacements = new Map([
}
}
const replacements = new Map([
['\\t', '\t'],

@@ -59,15 +53,15 @@ ['\\n', '\n'],

]);
var BACKSLASH_U = '\\u';
var TILDE_U = '~u';
var TILDE = '~';
var BACKSLASH = '\\';
var HEX = 16;
var digits = '0123456789';
var convertUnicodeSequences = function (str) {
var start = 0;
var result = str;
const BACKSLASH_U = '\\u';
const TILDE_U = '~u';
const TILDE = '~';
const BACKSLASH = '\\';
const HEX = 16;
const digits = '0123456789';
const convertUnicodeSequences = (str) => {
let start = 0;
let result = str;
while (start < result.length) {
var backslashUIndex = result.indexOf(BACKSLASH_U, start);
var tildeUIndex = result.indexOf(TILDE_U, start);
var unicodeStrIdx = void 0;
const backslashUIndex = result.indexOf(BACKSLASH_U, start);
const tildeUIndex = result.indexOf(TILDE_U, start);
let unicodeStrIdx;
if (tildeUIndex < 0 && backslashUIndex < 0) {

@@ -85,7 +79,7 @@ break;

}
var tryParseResult = tryParse(result, unicodeStrIdx + 2);
const tryParseResult = tryParse(result, unicodeStrIdx + 2);
start = unicodeStrIdx + 1;
if (!escapeSequenceIsEscaped(result, unicodeStrIdx)) {
if (tryParseResult.codePoint > 0) {
var chars = String.fromCodePoint(tryParseResult.codePoint);
const chars = String.fromCodePoint(tryParseResult.codePoint);
result = replace(result, chars, unicodeStrIdx, tryParseResult.length + 2);

@@ -97,12 +91,12 @@ }

};
var escapeSequenceIsEscaped = function (result, unicodeStrIdx) {
const escapeSequenceIsEscaped = (result, unicodeStrIdx) => {
return (unicodeStrIdx > 0 && (result.charAt(unicodeStrIdx - 1) === TILDE || result.charAt(unicodeStrIdx - 1) === BACKSLASH));
};
var replace = function (s, value, unicodeStrIdx, length) {
var left = s.substring(0, unicodeStrIdx);
var end = Math.min(s.length, unicodeStrIdx + length);
var right = s.substring(end);
const replace = (s, value, unicodeStrIdx, length) => {
const left = s.substring(0, unicodeStrIdx);
const end = Math.min(s.length, unicodeStrIdx + length);
const right = s.substring(end);
return left + value + right;
};
var isValidRange = function (value) {
const isValidRange = (value) => {
return ((value >= 0x100000 && value <= 0x10FFFF) ||

@@ -113,6 +107,6 @@ (value >= 0x10000 && value <= 0xFFFFF) ||

};
var hasEnoughDigits = function (s, idx, n) {
var i = 0;
const hasEnoughDigits = (s, idx, n) => {
let i = 0;
while (i < n && idx + i < s.length) {
var c = s[idx + i];
const c = s[idx + i];
if (!digits.includes(c) && 'abcdefABCDEF'.indexOf(c) <= -1) {

@@ -125,5 +119,5 @@ return false;

};
var tryParse = function (str, idx) {
const tryParse = (str, idx) => {
if (hasEnoughDigits(str, idx, 6)) {
var value = getPossibleUnicodeValue(str, idx, 6);
const value = getPossibleUnicodeValue(str, idx, 6);
if (isValidRange(value)) {

@@ -134,3 +128,3 @@ return new TryParseResult(value, 6);

if (hasEnoughDigits(str, idx, 5)) {
var value = getPossibleUnicodeValue(str, idx, 5);
const value = getPossibleUnicodeValue(str, idx, 5);
if (isValidRange(value)) {

@@ -141,3 +135,3 @@ return new TryParseResult(value, 5);

if (hasEnoughDigits(str, idx, 4)) {
var value = getPossibleUnicodeValue(str, idx, 4);
const value = getPossibleUnicodeValue(str, idx, 4);
if (isValidRange(value)) {

@@ -149,12 +143,11 @@ return new TryParseResult(value, 4);

};
var getPossibleUnicodeValue = function (str, idx, i) {
const getPossibleUnicodeValue = (str, idx, i) => {
return Number.parseInt(str.substring(idx, idx + i), HEX);
};
var TryParseResult = (function () {
function TryParseResult(codePoint, length) {
class TryParseResult {
constructor(codePoint, length) {
this.codePoint = codePoint;
this.length = length;
}
return TryParseResult;
}());
}
//# sourceMappingURL=Utils.js.map
{
"name": "modl-interpreter",
"version": "0.0.5",
"version": "0.0.6",
"description": "A MODL interpreter in TypeScript",

@@ -8,4 +8,3 @@ "main": "index.js",

"dependencies": {
"@types/antlr4": "^4.7.2",
"antlr4": "^4.7.3",
"antlr4ts": "^0.5.0-alpha.4",
"fp-ts": "^2.8.2",

@@ -15,3 +14,2 @@ "fs": "0.0.1-security",

"loglevel-plugin-prefix": "^0.8.4",
"modl-parser": "0.0.7",
"ts-loader": "^7.0.5",

@@ -25,2 +23,3 @@ "typescript": "^4.0.2"

"@types/node": "^14.0.13",
"antlr4ts-cli": "^0.5.0-alpha.4",
"chai": "^4.2.0",

@@ -34,2 +33,3 @@ "deep-eql": "^4.0.0",

"scripts": {
"antlr4ts": "antlr4ts -visitor -o ./src/grammar ../grammar/antlr4/MODLLexer.g4 ../grammar/antlr4/MODLParser.g4",
"test": "mocha --require ts-node/register 'test/**/*.ts'",

@@ -59,2 +59,2 @@ "debug": "mocha --require ts-node/register 'test/**/*.ts'",

]
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc