Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions JSONParser.class.nut
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ class JSONParser {

// current tokenizeing position
local start = 0;

local lastToken = null;

try {

local
Expand All @@ -262,7 +263,8 @@ class JSONParser {
tokenizer = _JSONTokenizer();

while (token = tokenizer.nextToken(str, start)) {

lastToken = token;

if ("ptfn" == token.type) {
// punctuation/true/false/null
action[token.value][state]();
Expand All @@ -284,13 +286,18 @@ class JSONParser {
}

// check is the final state is not ok
// or if there is somethign left in the str
// or if there is something left in the str
if (state != "ok" || regexp("[^\\s]").capture(str, start)) {
local min = @(a, b) a < b ? a : b;
local near = str.slice(start, min(str.len(), start + 10));
throw "JSON Syntax Error near `" + near + "`";
}

// if this is a standalone string or number, convert it
if (lastToken.type == "string" || lastToken.type == "number") {
return this._convert(lastToken.value, lastToken.type, converter)
}

return value;
}

Expand Down