New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

krl-parser

Package Overview
Dependencies
Maintainers
2
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

krl-parser - npm Package Compare versions

Comparing version 0.24.0 to 0.24.1

9

package.json
{
"name": "krl-parser",
"version": "0.24.0",
"version": "0.24.1",
"description": "Parse KRL source code into an AST",

@@ -13,3 +13,3 @@ "main": "src/index.js",

"test": "npm run test-all-but-ambiguityFinder -s && node tests/ambiguityFinder.js",
"test-all-but-ambiguityFinder": "npm run lint -s && npm run build -s && node tests",
"test-all-but-ambiguityFinder": "npm run lint -s && npm run build -s && node tests | faucet",
"build": "npm run build:grammar -s && npm run build:spec -s",

@@ -36,3 +36,4 @@ "build:grammar": "nearleyc src/grammar.ne > src/grammar.js",

"diff-lines": "^1.1.0",
"eslint": "^3.19.0",
"eslint": "^4.4.1",
"faucet": "0.0.1",
"krl-generator": "^0.7.2",

@@ -47,4 +48,4 @@ "lodash": "^4.13.1",

"line-column": "^1.0.2",
"nearley": "2.9.x"
"nearley": "2.10.x"
}
}

@@ -1273,3 +1273,4 @@ // Generated automatically by nearley

var d = data[0];
var pattern = d.src.substring(3, d.src.lastIndexOf("#")).replace(/\\#/g, "#");
var pattern = d.src.substring(3, d.src.lastIndexOf("#"))
.replace(/\\#/g, "#");
var modifiers = d.src.substring(d.src.lastIndexOf("#") + 1);

@@ -1302,3 +1303,4 @@ return {

type: 'String',
value: d.src.replace(/>\\>/g, '>>')
value: d.src.replace(/\\>/g, ">")
.replace(/\\#{/g, "#{").replace(/\\\\/g, "\\")
};

@@ -1310,3 +1312,4 @@ }

var d = data[0];
var v = d.src.replace(/(^")|("$)/g, "").replace(/\\"/g, "\"");
var v = d.src.replace(/(^")|("$)/g, "")
.replace(/\\"/g, '"').replace(/\\\\/g, "\\");
return {

@@ -1313,0 +1316,0 @@ loc: d.loc,

@@ -37,3 +37,3 @@ var nearley = require("nearley");

&& t.type !== "BLOCK-COMMENT"
;
;
});

@@ -40,0 +40,0 @@

@@ -1,255 +0,254 @@

module.exports = function(src, opts){
opts = opts || {};
var raw_toks = [
"<=>",
"<=",
"<",
"||",
"|",
"==",
"=>",
"=",
":=",
":",
">=",
"><",
">",
"&&",
"!=",
"(",
")",
"{",
"}",
"[",
"]",
",",
"/",
".",
"-",
"%",
"+",
";",
"*",
];
var r = [];
module.exports = function(src){
var c;
var next_is_escaped;
var tokens = [];
var beesting_stack = [];
var buff = "";
var buff = ""; // modified by pushTok and addToBuffer
var peek;
var i = 0;
var next_loc = 0;
var c = src[0];
var pushTok = function(type){
var loc = {start: next_loc, end: next_loc + buff.length};
r.push({
type: type,
src: buff,
loc: loc
});
next_loc = loc.end;
buff = "";
var pushTok = (function(){
var next_loc = 0;
return function(value, name){
var loc = {start: next_loc, end: next_loc + value.length};
tokens.push({
type: name,
src: value,
loc: loc
});
next_loc = loc.end;
buff = "";
};
}());
var advance = function(n){
i += n;
c = src[i];
};
var ctxChange = function(){
// loop invariant: c = src[i] follows the last character buff contained
var addToBuffer = function(stopCond, doEscaping){
var escaped = false;
while(i < src.length && (!stopCond() || escaped)){
if(escaped){
escaped = false;
}else if(doEscaping){
escaped = c === "\\";
}
buff += c;
advance(1);
}
};
var handleChevronBody = function(){
addToBuffer(function(){
peek = src.substring(i, i + 2);
return peek === "#{" || peek === ">>";
}, true);
if(buff.length > 0){
pushTok("RAW");
pushTok(buff, "CHEVRON-STRING");
}
buff = c;
if(peek === "#{"){
pushTok("#{", "CHEVRON-BEESTING-OPEN");
beesting_stack.push({curly_count: 0});
}else if(peek === ">>"){
pushTok(">>", "CHEVRON-CLOSE");
}
advance(2);
};
while(i < src.length){
c = src[i];
if(/\s/.test(c)){
addToBuffer(function(){
return !/\s/.test(c);
});
///////////////////////////////////////////////////////////////////////////
//whitespace
if(/^\s$/.test(c)){
ctxChange();
while(i < src.length){
c = src[i];
if(!/^\s$/.test(src[i + 1])){
break;
}
buff += c;
i++;
}
pushTok("WHITESPACE");
pushTok(buff, "WHITESPACE");
///////////////////////////////////////////////////////////////////////////
//string
}else if(c === "\""){
ctxChange();
i++;
next_is_escaped = false;
while(i < src.length){
c = src[i];
buff += c;
if(next_is_escaped){
next_is_escaped = false;
continue;
}
if(c === "/"){
peek = src[i + 1];
if(peek === "/"){
addToBuffer(function(){
return c === "\n" || c === "\r";
});
if(i < src.length){
pushTok(buff + c, "LINE-COMMENT");
advance(1);
}else{
if(c === "\\"){
next_is_escaped = true;
}
if(c === "\""){
break;
}
pushTok(buff, "LINE-COMMENT");
}
i++;
continue;
}
pushTok("STRING");
if(peek === "*"){
addToBuffer(function(){
return c === "*" && src[i + 1] === "/"
&& buff.length > 1; // '/*/' isn't valid
});
///////////////////////////////////////////////////////////////////////////
//chevron
}else if(false
|| (c === "<" && (src[i + 1] === "<"))
|| (c === "}" && (beesting_stack.length > 0) && (beesting_stack[beesting_stack.length-1].curly_count === 0))
){
ctxChange();
if(c === "}" && beesting_stack.length > 0){
pushTok("CHEVRON-BEESTING-CLOSE");
i++;
beesting_stack.pop();
}else{
buff = src.substring(i, i + 2);
i += 2;
pushTok("CHEVRON-OPEN");
}
next_is_escaped = false;
while(i < src.length){
c = src[i];
if(next_is_escaped){
next_is_escaped = false;
if(i < src.length){
pushTok(buff + "*/", "BLOCK-COMMENT");
advance(2);
}else{
if(c === "\\"){
next_is_escaped = true;
}
if(c === ">" && (src[i + 1] === ">")){
if(buff.length > 0){
pushTok("CHEVRON-STRING");
}
buff = src.substring(i, i + 2);
i += 1;
pushTok("CHEVRON-CLOSE");
break;
}
if(c === "#" && (src[i + 1] === "{")){
if(buff.length > 0){
pushTok("CHEVRON-STRING");
}
buff = src.substring(i, i + 2);
i += 1;
pushTok("CHEVRON-BEESTING-OPEN");
beesting_stack.push({curly_count: 0});
break;
}
pushTok(buff, "ILLEGAL");
}
buff += c;
i++;
continue;
}
///////////////////////////////////////////////////////////////////////////
//number
}else if(/^[0-9]$/.test(c) || (c === "." && /^[0-9]$/.test(src[i + 1]))){
ctxChange();
buff = "";
var has_seen_decimal = c === ".";
while(i < src.length){
c = src[i];
buff += c;
if(!/^[0-9]$/.test(src[i + 1])){
if(src[i+1] === "." && !has_seen_decimal){
has_seen_decimal = true;
}else{
break;
}
}
i++;
// fallthrough
}
if(/[0-9]/.test(c)){
addToBuffer(function(){
return !/[0-9]/.test(c);
});
if(c !== "." || !/[0-9]/.test(src[i + 1])){
pushTok(buff, "NUMBER");
continue;
}
if(buff[buff.length - 1] === "."){
buff = buff.substring(0, buff.length - 1);
pushTok("NUMBER");
buff = ".";
// fallthrough
}
if(c === "." && /[0-9]/.test(src[i + 1])){
buff += ".";
advance(1);
addToBuffer(function(){
return !/[0-9]/.test(c);
});
pushTok(buff, "NUMBER");
continue;
}
if(c === '"'){
addToBuffer(function(){
return c === '"' && buff.length > 0;
}, true);
if(i < src.length){
pushTok(buff + '"', "STRING");
advance(1);
}else{
pushTok("NUMBER");
pushTok(buff, "ILLEGAL");
}
///////////////////////////////////////////////////////////////////////////
//regexp
}else if(c === "r" && src[i+1] === "e" && src[i+2] === "#"){
ctxChange();
buff = src.substring(i, i + 3);
i += 3;
next_is_escaped = false;
while(i < src.length){
c = src[i];
buff += c;
if(next_is_escaped){
next_is_escaped = false;
}else{
if(c === "\\"){
next_is_escaped = true;
}
if(c === "#"){
if(src[i + 1] === "i"){
i++;
c = src[i];
buff += c;
if(src[i + 1] === "g"){
i++;
c = src[i];
buff += c;
}
}else if(src[i + 1] === "g"){
i++;
c = src[i];
buff += c;
if(src[i + 1] === "i"){
i++;
c = src[i];
buff += c;
}
}
break;
}
}
i++;
}
pushTok("REGEXP");
continue;
}
if(c === "r" && src.substring(i + 1, i + 3) === "e#"){
addToBuffer(function(){
return c === "#" && buff.length > 2;
}, true);
///////////////////////////////////////////////////////////////////////////
//symbol
}else if(/^[a-zA-Z_$]$/.test(c)){
ctxChange();
buff = "";
while(i < src.length){
c = src[i];
buff += c;
if(!/^[a-zA-Z0-9_$]$/.test(src[i + 1])){
break;
}
i++;
peek = src.substring(i + 1, i + 3);
if(peek === "gi" || peek === "ig"){
pushTok(buff + "#" + peek, "REGEXP");
advance(3);
}else if(peek[0] === "i" || peek[0] === "g"){
pushTok(buff + "#" + peek[0], "REGEXP");
advance(2);
}else if(i < src.length){
pushTok(buff + "#", "REGEXP");
advance(1);
}else{
pushTok(buff, "ILLEGAL");
}
pushTok("SYMBOL");
///////////////////////////////////////////////////////////////////////////
//line-comment
}else if(c === "/" && (src[i + 1] === "/")){
ctxChange();
i++;
while(i < src.length){
c = src[i];
buff += c;
if(c === "\n" || c === "\r"){
break;
}
i++;
}
pushTok("LINE-COMMENT");
continue;
}
if(c === "<" && src[i + 1] === "<"){
pushTok("<<", "CHEVRON-OPEN");
advance(2);
///////////////////////////////////////////////////////////////////////////
//block-comment
}else if(c === "/" && (src[i + 1] === "*")){
ctxChange();
i++;
while(i < src.length){
c = src[i];
buff += c;
if(c === "/" && (src[i-1] === "*")){
break;
}
i++;
}
pushTok("BLOCK-COMMENT");
handleChevronBody();
///////////////////////////////////////////////////////////////////////////
//raw
}else if("(){}[];".indexOf(c) >= 0){//single char groups
ctxChange();
pushTok("RAW");
if(beesting_stack.length > 0){
if(c === "{"){
beesting_stack[beesting_stack.length-1].curly_count++;
}else if(c === "}"){
continue;
}
if(/[a-zA-Z_$]/.test(c)){
addToBuffer(function(){
return !/[a-zA-Z0-9_$]/.test(c);
});
pushTok(buff, "SYMBOL");
continue;
}
if(beesting_stack.length > 0){
if(c === "{"){
beesting_stack[beesting_stack.length-1].curly_count++;
}else if(c === "}"){
if(beesting_stack[beesting_stack.length-1].curly_count === 0){
pushTok("}", "CHEVRON-BEESTING-CLOSE");
advance(1);
beesting_stack.pop();
handleChevronBody();
continue;
}else{
beesting_stack[beesting_stack.length-1].curly_count--;
}
}
}else{
buff += c;
}
i++;
var tok = 0;
while(tok < raw_toks.length){
if(raw_toks[tok] === src.substring(i, i + raw_toks[tok].length)){
pushTok(raw_toks[tok], "RAW");
advance(raw_toks[tok].length);
break;
}
tok++;
}
if(tok === raw_toks.length){
pushTok(c, "ILLEGAL");
advance(1);
}
}
ctxChange();
return r;
return tokens;
};

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