Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split source code into one file per class.
- Loading branch information
Showing
10 changed files
with
162 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Stake.extend({ | ||
AnyCharParser: new JS.Class(Stake.Parser, { | ||
consume: function(input, offset) { | ||
if (input === '') return null; | ||
return this._syntaxNode(input.substring(0,1), offset); | ||
} | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Stake.extend({ | ||
CharClassParser: new JS.Class(Stake.Parser, { | ||
initialize: function(charClass) { | ||
this._charClass = charClass; | ||
this._pattern = new RegExp('^' + charClass); | ||
}, | ||
|
||
consume: function(input, offset) { | ||
var match = input.match(this._pattern); | ||
return match ? this._syntaxNode(String(match), offset) : null; | ||
} | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Stake.extend({ | ||
ChoiceParser: new JS.Class(Stake.Parser, { | ||
extend: { | ||
create: function() { | ||
return new this(Array.prototype.slice.call(arguments)); | ||
} | ||
}, | ||
|
||
initialize: function(choices) { | ||
this._choices = choices; | ||
}, | ||
|
||
consume: function(input, offset) { | ||
var choices = this._choices, | ||
n = choices.length, i, node; | ||
|
||
for (i = 0; i < n; i++) { | ||
if (node = choices[i].consume(input, offset)) | ||
return node; | ||
} | ||
return null; | ||
} | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Stake.extend({ | ||
MaybeParser: new JS.Class(Stake.Parser, { | ||
initialize: function(parser) { | ||
this._parser = parser; | ||
}, | ||
|
||
consume: function(input, offset) { | ||
var node = this._parser.consume(input, offset); | ||
return node || this._syntaxNode('', offset); | ||
} | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Stake.extend({ | ||
NotParser: new JS.Class(Stake.Parser, { | ||
initialize: function(parser) { | ||
this._parser = parser; | ||
}, | ||
|
||
consume: function(input, offset) { | ||
var node = this._parser.consume(input, offset); | ||
return node ? null : this._syntaxNode('', offset); | ||
} | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Stake.extend({ | ||
RepeatParser: new JS.Class(Stake.Parser, { | ||
extend: { | ||
create: function(minimum, parser) { | ||
return new this(parser, minimum); | ||
} | ||
}, | ||
|
||
initialize: function(parser, minimum) { | ||
this._parser = parser; | ||
this._minimum = minimum || 0; | ||
}, | ||
|
||
consume: function(input, offset) { | ||
var elements = [], | ||
textValue = '', | ||
counter = offset, | ||
remaining = this._minimum, | ||
node = true; | ||
|
||
while (node = this._parser.consume(input, counter)) { | ||
elements.push(node); | ||
input = input.substring(node.textValue.length); | ||
textValue += node.textValue; | ||
counter += node.textValue.length; | ||
remaining -= 1; | ||
} | ||
if (remaining > 0) return null; | ||
return this._syntaxNode(textValue, offset, elements); | ||
} | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Stake.extend({ | ||
SequenceParser: new JS.Class(Stake.Parser, { | ||
extend: { | ||
create: function() { | ||
return new this(Array.prototype.slice.call(arguments)); | ||
} | ||
}, | ||
|
||
initialize: function(parsers) { | ||
this._parsers = parsers; | ||
}, | ||
|
||
consume: function(input, offset) { | ||
var elements = [], | ||
parsers = this._parsers, | ||
textValue = '', | ||
counter = offset, | ||
n = parsers.length, i, node; | ||
|
||
for (i = 0; i < n; i++) { | ||
node = parsers[i].consume(input, counter); | ||
if (!node) return null; | ||
|
||
elements.push(node); | ||
input = input.substring(node.textValue.length); | ||
|
||
textValue += node.textValue; | ||
counter += node.textValue.length; | ||
} | ||
return this._syntaxNode(textValue, offset, elements); | ||
} | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Stake.extend({ | ||
StringParser: new JS.Class(Stake.Parser, { | ||
initialize: function(string) { | ||
this._string = string; | ||
}, | ||
|
||
consume: function(input, offset) { | ||
if (!this._begins(input, this._string)) return null; | ||
return this._syntaxNode(this._string, offset); | ||
} | ||
}) | ||
}); | ||
|