Skip to content

Commit

Permalink
removed JSON.parse hack
Browse files Browse the repository at this point in the history
  • Loading branch information
d4tocchini authored and paulyoung committed Jan 3, 2015
1 parent f5de9df commit db7bd91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
18 changes: 16 additions & 2 deletions lib/grammar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
var Grammar;
var Grammar, cloneCommand;

cloneCommand = function(command) {
var clone, part, _i, _len;
clone = [];
for (_i = 0, _len = command.length; _i < _len; _i++) {
part = command[_i];
if (typeof part !== 'object') {
clone.push(part);
} else if (part instanceof Array) {
clone.push(cloneCommand(part));
}
}
return clone;
};

Grammar = (function() {
/* Private*/
Expand Down Expand Up @@ -61,7 +75,7 @@ Grammar = (function() {
_ref = outie.slice(1, outie.length);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
outieCommand = _ref[_i];
innieClone = JSON.parse(JSON.stringify(innie));
innieClone = cloneCommand(innie);
results.push(this.reverseFilterNest([innieClone, outieCommand]));
}
commands[i] = results;
Expand Down
12 changes: 11 additions & 1 deletion src/grammar.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# A CoffeeScript representation of the PEG grammar.
#

cloneCommand = (command) ->
clone = []
for part in command
if typeof part isnt 'object'
clone.push part
else if part instanceof Array
clone.push cloneCommand part
clone

class Grammar

### Private ###
Expand Down Expand Up @@ -100,7 +110,7 @@ class Grammar
if outie[0] is ','
results = [',']
for outieCommand in outie[1...outie.length]
innieClone = JSON.parse JSON.stringify innie
innieClone = cloneCommand innie
results.push @reverseFilterNest [innieClone, outieCommand]
commands[i] = results

Expand Down

0 comments on commit db7bd91

Please sign in to comment.