Browse Source

tools: refactor json.js

* Simplify regular expressions (see below)
* Remove unneeded `parseYAML()` wrapper
* Remove unused callback argument

Regular expression simplifications include:

* Changing trailing `*?$/` to `*$/` because non-greedy matching to the
  end of a line will not change behavior
* Change regexp beginnings like `/^(?:property:?\s*)?[^.\[]+` to the
  equivalent `/[^.\]]+`
* For regular expressions changed per the above, remove
  case-insensitivity if it no longer affects the regexp

PR-URL: https://github.com/nodejs/node/pull/10442
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
v7.x
Rich Trott 8 years ago
committed by Evan Lucas
parent
commit
797d9a8e79
  1. 22
      tools/doc/json.js

22
tools/doc/json.js

@ -102,7 +102,7 @@ function doJSON(input, filename, cb) {
current.list.push(tok); current.list.push(tok);
current.list.level = 1; current.list.level = 1;
} else if (type === 'html' && common.isYAMLBlock(tok.text)) { } else if (type === 'html' && common.isYAMLBlock(tok.text)) {
current.meta = parseYAML(tok.text); current.meta = common.extractAndParseYAML(tok.text);
} else { } else {
current.desc = current.desc || []; current.desc = current.desc || [];
if (!Array.isArray(current.desc)) { if (!Array.isArray(current.desc)) {
@ -302,10 +302,6 @@ function processList(section) {
delete section.list; delete section.list;
} }
function parseYAML(text) {
return common.extractAndParseYAML(text);
}
// textRaw = "someobject.someMethod(a[, b=100][, c])" // textRaw = "someobject.someMethod(a[, b=100][, c])"
function parseSignature(text, sig) { function parseSignature(text, sig) {
var params = text.match(paramExpr); var params = text.match(paramExpr);
@ -314,7 +310,7 @@ function parseSignature(text, sig) {
params = params.split(/,/); params = params.split(/,/);
var optionalLevel = 0; var optionalLevel = 0;
var optionalCharDict = {'[': 1, ' ': 0, ']': -1}; var optionalCharDict = {'[': 1, ' ': 0, ']': -1};
params.forEach(function(p, i, _) { params.forEach(function(p, i) {
p = p.trim(); p = p.trim();
if (!p) return; if (!p) return;
var param = sig.params[i]; var param = sig.params[i];
@ -544,14 +540,12 @@ function deepCopy_(src) {
// these parse out the contents of an H# tag // these parse out the contents of an H# tag
var eventExpr = /^Event(?::|\s)+['"]?([^"']+).*$/i; var eventExpr = /^Event(?::|\s)+['"]?([^"']+).*$/i;
var classExpr = /^Class:\s*([^ ]+).*?$/i; var classExpr = /^Class:\s*([^ ]+).*$/i;
var propExpr = /^(?:property:?\s*)?[^.]+\.([^ .()]+)\s*?$/i; var propExpr = /^[^.]+\.([^ .()]+)\s*$/;
var braceExpr = /^(?:property:?\s*)?[^.\[]+(\[[^\]]+\])\s*?$/i; var braceExpr = /^[^.[]+(\[[^\]]+\])\s*$/;
var classMethExpr = var classMethExpr = /^class\s*method\s*:?[^.]+\.([^ .()]+)\([^)]*\)\s*$/i;
/^class\s*method\s*:?[^.]+\.([^ .()]+)\([^)]*\)\s*?$/i; var methExpr = /^(?:[^.]+\.)?([^ .()]+)\([^)]*\)\s*$/;
var methExpr = var newExpr = /^new ([A-Z][a-zA-Z]+)\([^)]*\)\s*$/;
/^(?:method:?\s*)?(?:[^.]+\.)?([^ .()]+)\([^)]*\)\s*?$/i;
var newExpr = /^new ([A-Z][a-zA-Z]+)\([^)]*\)\s*?$/;
var paramExpr = /\((.*)\);?$/; var paramExpr = /\((.*)\);?$/;
function newSection(tok) { function newSection(tok) {

Loading…
Cancel
Save