Browse Source

Replace suitable for loops with Array methods (in /src)

See #441.
redux
David Majda 5 years ago
parent
commit
3e8bcbea73
  1. 22
      lib/parser.js
  2. 22
      src/parser.pegjs

22
lib/parser.js

@ -337,7 +337,7 @@ function peg$parse(input, options) {
peg$c98 = function(inverted, parts, ignoreCase) {
return {
type: "class",
parts: filterEmptyStrings(parts),
parts: parts.filter(function(part) { return part !== ""; }),
inverted: inverted !== null,
ignoreCase: ignoreCase !== null,
location: location()
@ -4984,30 +4984,12 @@ function peg$parse(input, options) {
"!": "semantic_not"
};
function filterEmptyStrings(array) {
var result = [], i;
for (i = 0; i < array.length; i++) {
if (array[i] !== "") {
result.push(array[i]);
}
}
return result;
}
function extractOptional(optional, index) {
return optional ? optional[index] : null;
}
function extractList(list, index) {
var result = new Array(list.length), i;
for (i = 0; i < list.length; i++) {
result[i] = list[i][index];
}
return result;
return list.map(function(element) { return element[index]; });
}
function buildList(head, tail, index) {

22
src/parser.pegjs

@ -41,30 +41,12 @@
"!": "semantic_not"
};
function filterEmptyStrings(array) {
var result = [], i;
for (i = 0; i < array.length; i++) {
if (array[i] !== "") {
result.push(array[i]);
}
}
return result;
}
function extractOptional(optional, index) {
return optional ? optional[index] : null;
}
function extractList(list, index) {
var result = new Array(list.length), i;
for (i = 0; i < list.length; i++) {
result[i] = list[i][index];
}
return result;
return list.map(function(element) { return element[index]; });
}
function buildList(head, tail, index) {
@ -382,7 +364,7 @@ CharacterClassMatcher "character class"
{
return {
type: "class",
parts: filterEmptyStrings(parts),
parts: parts.filter(function(part) { return part !== ""; }),
inverted: inverted !== null,
ignoreCase: ignoreCase !== null,
location: location()

Loading…
Cancel
Save