Skip to content

Commit

Permalink
json tree
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascrockford committed Oct 14, 2016
1 parent f405e18 commit 554bcbd
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions jslint.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// jslint.js
// 2016-10_09
// 2016-10-13
// Copyright (c) 2015 Douglas Crockford (www.JSLint.com)

// Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -1679,16 +1679,22 @@ var jslint = (function JSLint() {
// Parsing of JSON is simple:

function json_value() {
var negative;

function json_object() {
var brace = next_token;
var object = empty();
var properties = [];
brace.expression = properties;
advance("{");
if (next_token.id !== "}") {
(function next() {
var name;
var value;
if (next_token.quote !== "\"") {
warn("unexpected_a", next_token, next_token.quote);
}
name = next_token;
advance("(string)");
if (object[token.value] !== undefined) {
warn("duplicate_a", token);
Expand All @@ -1698,59 +1704,66 @@ var jslint = (function JSLint() {
object[token.value] = token;
}
advance(":");
json_value();
value = json_value();
value.label = name;
properties.push(value);
if (next_token.id === ",") {
advance(",");
return next();
}
}());
}
advance("}", brace);
return brace;
}

function json_array() {
var bracket = next_token;
var elements = [];
bracket.expression = elements;
advance("[");
if (next_token.id !== "]") {
(function next() {
json_value();
elements.push(json_value());
if (next_token.id === ",") {
advance(",");
return next();
}
}());
}
advance("]", bracket);
return bracket;
}

switch (next_token.id) {
case "{":
json_object();
break;
return json_object();
case "[":
json_array();
break;
return json_array();
case "true":
case "false":
case "null":
advance();
break;
return token;
case "(number)":
if (!rx_JSON_number.test(next_token.value)) {
warn("unexpected_a");
}
advance();
break;
return token;
case "(string)":
if (next_token.quote !== "\"") {
warn("unexpected_a", next_token, next_token.quote);
}
advance();
break;
return token;
case "-":
negative = next_token;
negative.arity = "unary";
advance("-");
advance("(number)");
break;
negative.expression = token;
return negative;
default:
stop("unexpected_a");
}
Expand Down Expand Up @@ -4867,7 +4880,7 @@ var jslint = (function JSLint() {
}
return {
directives: directives,
edition: "2016-10-09",
edition: "2016-10-13",
exports: exports,
froms: froms,
functions: functions,
Expand Down

0 comments on commit 554bcbd

Please sign in to comment.