@@ -179,10 +179,8 @@ function generateJS(ast, options) {
179179 paramsLengthCode = 'bc[ip + ' + ( baseLength - 1 ) + ']' ;
180180
181181 return [
182- 'params = bc.slice(ip + ' + baseLength + ', ip + ' + baseLength + ' + ' + paramsLengthCode + ');' ,
183- 'for (i = 0; i < ' + paramsLengthCode + '; i++) {' ,
184- ' params[i] = stack[stack.length - 1 - params[i]];' ,
185- '}' ,
182+ 'params = bc.slice(ip + ' + baseLength + ', ip + ' + baseLength + ' + ' + paramsLengthCode + ')' ,
183+ ' .map(function(p) { return stack[stack.length - 1 - p]; });' ,
186184 '' ,
187185 'stack.splice(' ,
188186 ' stack.length - bc[ip + 2],' ,
@@ -197,13 +195,7 @@ function generateJS(ast, options) {
197195
198196 parts . push ( [
199197 'function peg$decode(s) {' ,
200- ' var bc = new Array(s.length), i;' ,
201- '' ,
202- ' for (i = 0; i < s.length; i++) {' ,
203- ' bc[i] = s.charCodeAt(i) - 32;' ,
204- ' }' ,
205- '' ,
206- ' return bc;' ,
198+ ' return s.split("").map(function(ch) { return ch.charCodeAt(0) - 32; });' ,
207199 '}' ,
208200 '' ,
209201 'function peg$parseRule(index) {'
@@ -218,7 +210,7 @@ function generateJS(ast, options) {
218210 ' ends = [],' ,
219211 ' stack = [],' ,
220212 ' startPos = peg$currPos,' ,
221- ' params, i ;'
213+ ' params;'
222214 ] . join ( '\n' ) ) ;
223215 } else {
224216 parts . push ( [
@@ -228,7 +220,7 @@ function generateJS(ast, options) {
228220 ' end = bc.length,' ,
229221 ' ends = [],' ,
230222 ' stack = [],' ,
231- ' params, i ;'
223+ ' params;'
232224 ] . join ( '\n' ) ) ;
233225 }
234226
@@ -786,14 +778,11 @@ function generateJS(ast, options) {
786778 ' },' ,
787779 '' ,
788780 ' "class": function(expectation) {' ,
789- ' var escapedParts = "",' ,
790- ' i;' ,
791- '' ,
792- ' for (i = 0; i < expectation.parts.length; i++) {' ,
793- ' escapedParts += Array.isArray(expectation.parts[i])' ,
794- ' ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1])' ,
795- ' : classEscape(expectation.parts[i]);' ,
796- ' }' ,
781+ ' var escapedParts = expectation.parts.map(function(part) {' ,
782+ ' return Array.isArray(part)' ,
783+ ' ? classEscape(part[0]) + "-" + classEscape(part[1])' ,
784+ ' : classEscape(part);' ,
785+ ' });' ,
797786 '' ,
798787 ' return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";' ,
799788 ' },' ,
@@ -846,13 +835,9 @@ function generateJS(ast, options) {
846835 ' }' ,
847836 '' ,
848837 ' function describeExpected(expected) {' ,
849- ' var descriptions = new Array( expected.length ),' ,
838+ ' var descriptions = expected.map(describeExpectation ),' ,
850839 ' i, j;' ,
851840 '' ,
852- ' for (i = 0; i < expected.length; i++) {' ,
853- ' descriptions[i] = describeExpectation(expected[i]);' ,
854- ' }' ,
855- '' ,
856841 ' descriptions.sort();' ,
857842 '' ,
858843 ' if (descriptions.length > 0) {' ,
0 commit comments