Comparing version 1.0.9 to 1.0.10
@@ -0,1 +1,10 @@ | ||
<a name="1.0.10"></a> | ||
### 1.0.10 (2018-05-28) | ||
#### Features | ||
* more validation on queries for clearer error reporting & non-silly results ([af934a18](git+https://github.com/codeo-za/segmenta.git/commit/af934a18)) | ||
<a name="1.0.9"></a> | ||
@@ -2,0 +11,0 @@ ### 1.0.9 (2018-05-28) |
@@ -13,6 +13,10 @@ export declare enum TokenTypes { | ||
} | ||
export interface IToken { | ||
export interface ISimpleToken { | ||
type: TokenTypes; | ||
value?: string; | ||
} | ||
export interface IToken extends ISimpleToken { | ||
line: number; | ||
char: number; | ||
} | ||
export declare function tokenize(code: string): IToken[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const validation_1 = require("./validation"); | ||
var TokenTypes; | ||
@@ -53,4 +54,8 @@ (function (TokenTypes) { | ||
} | ||
function generateSyntaxErrorFor(allCode, current) { | ||
const absolutePos = allCode.length - current.length, lines = allCode.substr(0, absolutePos).split(new RegExp("\\r\\n|\\n|\\r")), linePos = lines.length, charPos = lines[linePos - 1].length + 1, partial = current.length > 10 ? current.substr(0, 10) + "..." : current; | ||
function codePos(allCode, current) { | ||
const absolutePos = allCode.length - current.length, lines = allCode.substr(0, absolutePos).split(new RegExp("\\r\\n|\\n|\\r")), linePos = lines.length, charPos = lines[linePos - 1].length + 1; | ||
return [linePos, charPos]; | ||
} | ||
function generateSyntaxErrorFor(current, linePos, charPos) { | ||
const partial = current.length > 10 ? current.substr(0, 10) + "..." : current; | ||
return `Syntax error (line ${linePos}, char ${charPos}): '${partial}'`; | ||
@@ -62,2 +67,3 @@ } | ||
while (currentCode) { | ||
const [line, char] = codePos(code, currentCode); | ||
const thisToken = tokenTypes.reduce((acc, cur) => { | ||
@@ -69,3 +75,3 @@ if (acc) { | ||
return match && match.index === 0 | ||
? { type: cur.type, match } | ||
? { type: cur.type, match, line, char } | ||
: acc; | ||
@@ -76,3 +82,3 @@ }, undefined); | ||
thisToken.match.index === undefined) { | ||
throw new Error(generateSyntaxErrorFor(code, currentCode)); | ||
throw new Error(generateSyntaxErrorFor(currentCode, line, char)); | ||
} | ||
@@ -84,3 +90,5 @@ else { | ||
? sanitizeIdentifier(thisToken.match[0]) | ||
: undefined | ||
: undefined, | ||
line, | ||
char | ||
}); | ||
@@ -90,4 +98,5 @@ currentCode = currentCode.substr(thisToken.match[0].length).trim(); | ||
} | ||
validation_1.validate(result); | ||
return result; | ||
} | ||
exports.tokenize = tokenize; |
{ | ||
"name": "segmenta", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "A blazingly fast API for managing and querying arbitrary data segments stored in Redis", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
61494
33
1333