krl-parser
Advanced tools
Comparing version 0.52.3 to 1.0.0-alpha.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseRuleset = exports.parseExpression = exports.parse = void 0; | ||
const ParseError_1 = require("./ParseError"); | ||
@@ -434,21 +435,21 @@ const tdop_1 = require("./tdop"); | ||
const action_block = actionBlock(state); | ||
let returns = []; | ||
if (chompMaybe(state, "SYMBOL", "return") || | ||
chompMaybe(state, "SYMBOL", "returns")) { | ||
while (state.curr.token_i < state.tokens.length) { | ||
if (state.curr.token.type === "RAW" && state.curr.token.src === "}") { | ||
break; | ||
} | ||
if (chompMaybe(state, "RAW", ";")) { | ||
break; | ||
} | ||
const val = expression(state); | ||
returns.push(val); | ||
if (state.curr.rule.id !== ",") { | ||
break; | ||
} | ||
advance(state); | ||
} | ||
chompMaybe(state, "RAW", ";"); | ||
if (chompMaybe(state, "RAW", "}")) { | ||
return { | ||
loc, | ||
type: "DefAction", | ||
params, | ||
body, | ||
action_block, | ||
return: null | ||
}; | ||
} | ||
if (chompMaybe(state, "SYMBOL", "returns")) { | ||
throw new ParseError_1.ParseError("defaction can only return one value", state.curr.token); | ||
} | ||
chomp(state, "SYMBOL", "return"); | ||
const returnExpr = expression(state); | ||
if (state.curr.token.type === "RAW" && state.curr.token.src === ",") { | ||
throw new ParseError_1.ParseError("defaction can only return one value", state.curr.token); | ||
} | ||
chompMaybe(state, "RAW", ";"); | ||
chomp(state, "RAW", "}"); | ||
@@ -461,3 +462,3 @@ return { | ||
action_block, | ||
returns | ||
return: returnExpr | ||
}; | ||
@@ -615,2 +616,6 @@ } | ||
chomp(state, "RAW", "{"); | ||
let version = null; | ||
if (chompMaybe(state, "SYMBOL", "version")) { | ||
version = chompString(state); | ||
} | ||
const meta = rulesetMeta(state); | ||
@@ -636,2 +641,3 @@ let global = []; | ||
rid, | ||
version, | ||
meta, | ||
@@ -674,2 +680,3 @@ global, | ||
switch (key.value) { | ||
case "version": | ||
case "name": | ||
@@ -714,6 +721,2 @@ case "description": | ||
const rid = rulesetID(state); | ||
let version = null; | ||
if (chompMaybe(state, "SYMBOL", "version")) { | ||
version = chompString(state); | ||
} | ||
let alias = null; | ||
@@ -730,3 +733,2 @@ if (chompMaybe(state, "SYMBOL", "alias")) { | ||
rid, | ||
version, | ||
alias, | ||
@@ -741,7 +743,3 @@ with: withExpr | ||
const rid = rulesetID(state); | ||
let version = null; | ||
if (chompMaybe(state, "SYMBOL", "version")) { | ||
version = chompString(state); | ||
} | ||
value = { rid, version }; | ||
value = { rid }; | ||
} | ||
@@ -849,30 +847,42 @@ break; | ||
if (chompMaybe(state, "SYMBOL", "select")) { | ||
chomp(state, "SYMBOL", "when"); | ||
const event = eventExpression(state); | ||
const withinStart = state.curr.token.loc.start; | ||
let within = null; | ||
if (chompMaybe(state, "SYMBOL", "within")) { | ||
const expr = expression(state); | ||
if (state.curr.token.type !== "SYMBOL" || | ||
!ast.TIME_PERIOD_ENUM.hasOwnProperty(state.curr.token.src)) { | ||
throw new ParseError_1.ParseError(`Expected time period: [${Object.keys(ast.TIME_PERIOD_ENUM).join(",")}]`, state.curr.token); | ||
if (chompMaybe(state, "SYMBOL", "when")) { | ||
const event = eventExpression(state); | ||
const withinStart = state.curr.token.loc.start; | ||
let within = null; | ||
if (chompMaybe(state, "SYMBOL", "within")) { | ||
const expr = expression(state); | ||
if (state.curr.token.type !== "SYMBOL" || | ||
!ast.TIME_PERIOD_ENUM.hasOwnProperty(state.curr.token.src)) { | ||
throw new ParseError_1.ParseError(`Expected time period: [${Object.keys(ast.TIME_PERIOD_ENUM).join(",")}]`, state.curr.token); | ||
} | ||
const time_period = state.curr.token | ||
.src; | ||
const end = state.curr.token.loc.end; | ||
advance(state); | ||
within = { | ||
loc: { start: withinStart, end }, | ||
type: "EventWithin", | ||
expression: expr, | ||
time_period | ||
}; | ||
} | ||
const time_period = state.curr.token | ||
.src; | ||
const end = state.curr.token.loc.end; | ||
advance(state); | ||
within = { | ||
loc: { start: withinStart, end }, | ||
type: "EventWithin", | ||
expression: expr, | ||
time_period | ||
select = { | ||
loc: { start: selectStart, end: state.curr.token.loc.end }, | ||
type: "RuleSelect", | ||
kind: "when", | ||
event, | ||
within | ||
}; | ||
} | ||
select = { | ||
loc: { start: selectStart, end: state.curr.token.loc.end }, | ||
type: "RuleSelect", | ||
kind: "when", | ||
event, | ||
within | ||
}; | ||
else if (chompMaybe(state, "SYMBOL", "where")) { | ||
select = { | ||
loc: { start: selectStart, end: state.curr.token.loc.end }, | ||
type: "RuleSelect", | ||
kind: "where", | ||
expression: expression(state) | ||
}; | ||
} | ||
else { | ||
throw new ParseError_1.ParseError("Expected `when` or `where`", state.curr.token); | ||
} | ||
} | ||
@@ -879,0 +889,0 @@ const foreach = []; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ParseError = void 0; | ||
const lineColumn = require("line-column"); | ||
@@ -4,0 +5,0 @@ const excerptAtLineCol = require("excerpt-at-line-col"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.easyLookahead = exports.lookahead = exports.advanceBase = void 0; | ||
const ParseError_1 = require("./ParseError"); | ||
@@ -4,0 +5,0 @@ function checkSignificantToken(token) { |
@@ -161,18 +161,16 @@ "use strict"; | ||
}, true); | ||
peek = src.substring(i + 1, i + 3); | ||
if (peek === "gi" || peek === "ig") { | ||
pushTok(buff + "#" + peek, "REGEXP"); | ||
advance(3); | ||
if (src[i] !== "#") { | ||
pushTok(buff, "MISSING-CLOSE", "#"); | ||
continue; | ||
} | ||
else if (peek[0] === "i" || peek[0] === "g") { | ||
pushTok(buff + "#" + peek[0], "REGEXP"); | ||
advance(2); | ||
let flags = ""; | ||
for (let j = i + 1; j < src.length; j++) { | ||
let flag = src[j]; | ||
if (!/[gim]/.test(flag)) { | ||
break; | ||
} | ||
flags += flag; | ||
} | ||
else if (i < src.length) { | ||
pushTok(buff + "#", "REGEXP"); | ||
advance(1); | ||
} | ||
else { | ||
pushTok(buff, "MISSING-CLOSE", "#"); | ||
} | ||
pushTok(buff + "#" + flags, "REGEXP"); | ||
advance(1 + flags.length); | ||
continue; | ||
@@ -179,0 +177,0 @@ } |
@@ -102,3 +102,3 @@ export interface Loc { | ||
action_block: ActionBlock; | ||
returns: Expression[]; | ||
return: Expression | null; | ||
} | ||
@@ -148,2 +148,3 @@ export interface Parameters extends BaseNode { | ||
rid: RulesetID; | ||
version: String | null; | ||
meta: RulesetMeta | null; | ||
@@ -172,3 +173,3 @@ global: Declaration[]; | ||
} | ||
export interface RuleSelect extends BaseNode { | ||
export interface RuleSelect_when extends BaseNode { | ||
type: "RuleSelect"; | ||
@@ -179,2 +180,8 @@ kind: "when"; | ||
} | ||
export interface RuleSelect_where extends BaseNode { | ||
type: "RuleSelect"; | ||
kind: "where"; | ||
expression: Expression; | ||
} | ||
export declare type RuleSelect = RuleSelect_when | RuleSelect_where; | ||
export declare type EventExpression = EventExpressionBase | EventOperator | EventGroupOperator; | ||
@@ -181,0 +188,0 @@ export interface EventExpressionBase extends BaseNode { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LEVEL_ENUM = exports.TIME_PERIOD_ENUM = exports.RESERVED_WORDS_ENUM = void 0; | ||
exports.RESERVED_WORDS_ENUM = { | ||
@@ -4,0 +5,0 @@ defaction: true, |
{ | ||
"name": "krl-parser", | ||
"version": "0.52.3", | ||
"version": "1.0.0-alpha.0", | ||
"description": "Parse KRL source code into an AST", | ||
@@ -35,4 +35,4 @@ "main": "dist/src/index.js", | ||
"ava": "^2.4.0", | ||
"ts-node": "^8.4.1", | ||
"typescript": "^3.7.2" | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.2" | ||
}, | ||
@@ -58,3 +58,3 @@ "dependencies": { | ||
}, | ||
"gitHead": "90020b0033b51d5bd3c3606466a92da3308fb6b7" | ||
"gitHead": "26aee8aeb73a2450f9224f2d8d81f3a3d49b33f2" | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
134853
2311
1