@jeefo/parser
Advanced tools
Comparing version 0.0.27 to 0.0.28
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : ast_node_definition.js | ||
* Created at : 2019-01-26 | ||
* Updated at : 2019-10-17 | ||
* Updated at : 2021-01-06 | ||
* Author : jeefo | ||
@@ -50,17 +50,11 @@ * Purpose : | ||
const Node = (new Function("I_AST_Node", ` | ||
class ${ class_name } extends I_AST_Node { | ||
constructor () { | ||
super(); | ||
this._id = "${ | ||
ast_node_definition.id | ||
}"; | ||
this._type = "${ | ||
ast_node_definition.type | ||
}"; | ||
this._precedence = ${ | ||
ast_node_definition.precedence | ||
}; | ||
} | ||
function ${class_name} () { | ||
I_AST_Node.call(this); | ||
this._id = "${ast_node_definition.id}"; | ||
this._type = "${ast_node_definition.type}"; | ||
this._precedence = ${ast_node_definition.precedence}; | ||
} | ||
return ${ class_name }; | ||
${class_name}.prototype = Object.create(I_AST_Node.prototype); | ||
return ${class_name}; | ||
`))(I_AST_Node); | ||
@@ -67,0 +61,0 @@ // jshint evil:false |
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : i_ast_node.js | ||
* Created at : 2019-01-27 | ||
* Updated at : 2019-09-03 | ||
* Updated at : 2021-01-06 | ||
* Author : jeefo | ||
@@ -21,55 +21,53 @@ * Purpose : | ||
class I_AST_Node { | ||
constructor () { | ||
if (new.target === I_AST_Node) { | ||
throw new Error("Interface class cannot be instantiated."); | ||
} | ||
function I_AST_Node () { | ||
if (new.target === I_AST_Node) { | ||
throw new Error("Interface class cannot be instantiated."); | ||
} | ||
} | ||
print () { | ||
const properties = Object.keys(this); | ||
if (! properties.includes("id")) { | ||
properties.unshift("id"); | ||
} | ||
if (! properties.includes("type")) { | ||
insert_at(properties, "type", 1); | ||
} | ||
if (! properties.includes("precedence")) { | ||
insert_at(properties, "precedence", 2); | ||
} | ||
I_AST_Node.prototype.print = function () { | ||
const properties = Object.keys(this); | ||
if (! properties.includes("id")) { | ||
properties.unshift("id"); | ||
} | ||
if (! properties.includes("type")) { | ||
insert_at(properties, "type", 1); | ||
} | ||
if (! properties.includes("precedence")) { | ||
insert_at(properties, "precedence", 2); | ||
} | ||
let max_length = Math.max.apply(null, properties.map(property => property.length)); | ||
let rows = properties.map(property => { | ||
let value = this[property]; | ||
if (Array.isArray(value)) { | ||
value = `[${ value }]`; | ||
if (value.length > 80) { | ||
value = value.split(',').join(",\n"); | ||
} | ||
} else if (typeof value === "string") { | ||
value = value.replace(NEW_LINE_REGEXP, "\\n"); | ||
let max_length = Math.max.apply(null, properties.map(property => property.length)); | ||
let rows = properties.map(property => { | ||
let value = this[property]; | ||
if (Array.isArray(value)) { | ||
value = `[${ value }]`; | ||
if (value.length > 80) { | ||
value = value.split(',').join(",\n"); | ||
} | ||
} else if (typeof value === "string") { | ||
value = value.replace(NEW_LINE_REGEXP, "\\n"); | ||
} | ||
return `${ property }${ ' '.repeat(max_length - property.length) } : ${ value }`; | ||
}); | ||
return `${ property }${ ' '.repeat(max_length - property.length) } : ${ value }`; | ||
}); | ||
max_length = Math.max.apply(null, rows.map(row => row.split('\n')[0].length)); | ||
rows = rows.map(row => `| ${ row }${ ' '.repeat(max_length - row.split('\n')[0].length) } |`); | ||
max_length = Math.max.apply(null, rows.map(row => row.split('\n')[0].length)); | ||
rows = rows.map(row => `| ${ row }${ ' '.repeat(max_length - row.split('\n')[0].length) } |`); | ||
const dash_line = `+${ '-'.repeat(max_length + 2) }+`; | ||
rows.unshift( | ||
dash_line, | ||
`| AST_Node${ ' '.repeat(max_length - "AST_Node".length) } |`, | ||
dash_line | ||
); | ||
rows.push(dash_line); | ||
const dash_line = `+${ '-'.repeat(max_length + 2) }+`; | ||
rows.unshift( | ||
dash_line, | ||
`| AST_Node${ ' '.repeat(max_length - "AST_Node".length) } |`, | ||
dash_line | ||
); | ||
rows.push(dash_line); | ||
console.log(rows.join('\n')); | ||
} | ||
console.log(rows.join('\n')); | ||
}; | ||
toString () { | ||
return `<${ this.constructor.name }>`; | ||
} | ||
} | ||
I_AST_Node.prototype.toString = function () { | ||
return `<${this.constructor.name}>`; | ||
}; | ||
module.exports = I_AST_Node; |
{ | ||
"name": "@jeefo/parser", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"description": "A library for parsing AST nodes. (under developing...)", | ||
@@ -5,0 +5,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
30520
779