simplifying RangeNode grammar a bit.

This commit is contained in:
Jeremy Ashkenas 2010-09-04 06:48:20 -04:00
parent 493780efab
commit 3b60aad487
5 changed files with 129 additions and 133 deletions

View File

@ -299,31 +299,30 @@
return new ValueNode(new LiteralNode('this'));
})
],
RangeDots: [
o(". .", function() {
return 'inclusive';
}), o(". . .", function() {
return 'exclusive';
})
],
ThisProperty: [
o("@ Identifier", function() {
return new ValueNode(new LiteralNode('this'), [new AccessorNode($2)]);
})
],
Range: [
o("[ Expression . . Expression ]", function() {
return new RangeNode($2, $5);
}), o("[ Expression . . . Expression ]", function() {
return new RangeNode($2, $6, true);
o("[ Expression RangeDots Expression ]", function() {
return new RangeNode($2, $4, $3);
})
],
Slice: [
o("INDEX_START Expression . . Expression INDEX_END", function() {
return new RangeNode($2, $5);
}), o("INDEX_START Expression . . . Expression INDEX_END", function() {
return new RangeNode($2, $6, true);
}), o("INDEX_START Expression . . INDEX_END", function() {
return new RangeNode($2, null);
}), o("INDEX_START Expression . . . INDEX_END", function() {
return new RangeNode($2, null, true);
}), o("INDEX_START . . Expression INDEX_END", function() {
return new RangeNode(null, $4);
}), o("INDEX_START . . . Expression INDEX_END", function() {
return new RangeNode(null, $5, true);
o("INDEX_START Expression RangeDots Expression INDEX_END", function() {
return new RangeNode($2, $4, $3);
}), o("INDEX_START Expression RangeDots INDEX_END", function() {
return new RangeNode($2, null, $3);
}), o("INDEX_START RangeDots Expression INDEX_END", function() {
return new RangeNode(null, $3, $2);
})
],
Array: [

View File

@ -596,11 +596,11 @@
return IndexNode;
})();
exports.RangeNode = (function() {
RangeNode = function(_b, _c, exclusive) {
RangeNode = function(_b, _c, tag) {
this.to = _c;
this.from = _b;
RangeNode.__super__.constructor.call(this);
this.exclusive = !!exclusive;
this.exclusive = tag === 'exclusive';
this.equals = this.exclusive ? '' : '=';
return this;
};

File diff suppressed because one or more lines are too long

View File

@ -340,6 +340,11 @@ grammar =
o "@", -> new ValueNode new LiteralNode 'this'
]
RangeDots: [
o ". .", -> 'inclusive'
o ". . .", -> 'exclusive'
]
# A reference to a property on *this*.
ThisProperty: [
o "@ Identifier", -> new ValueNode new LiteralNode('this'), [new AccessorNode($2)]
@ -347,18 +352,14 @@ grammar =
# The CoffeeScript range literal.
Range: [
o "[ Expression . . Expression ]", -> new RangeNode $2, $5
o "[ Expression . . . Expression ]", -> new RangeNode $2, $6, true
o "[ Expression RangeDots Expression ]", -> new RangeNode $2, $4, $3
]
# The slice literal.
Slice: [
o "INDEX_START Expression . . Expression INDEX_END", -> new RangeNode $2, $5
o "INDEX_START Expression . . . Expression INDEX_END", -> new RangeNode $2, $6, true
o "INDEX_START Expression . . INDEX_END", -> new RangeNode $2, null
o "INDEX_START Expression . . . INDEX_END", -> new RangeNode $2, null, true
o "INDEX_START . . Expression INDEX_END", -> new RangeNode null, $4
o "INDEX_START . . . Expression INDEX_END", -> new RangeNode null, $5, true
o "INDEX_START Expression RangeDots Expression INDEX_END", -> new RangeNode $2, $4, $3
o "INDEX_START Expression RangeDots INDEX_END", -> new RangeNode $2, null, $3
o "INDEX_START RangeDots Expression INDEX_END", -> new RangeNode null, $3, $2
]
# The array literal.

View File

@ -550,9 +550,9 @@ exports.RangeNode = class RangeNode extends BaseNode
class: 'RangeNode'
children: ['from', 'to']
constructor: (@from, @to, exclusive) ->
constructor: (@from, @to, tag) ->
super()
@exclusive = !!exclusive
@exclusive = tag is 'exclusive'
@equals = if @exclusive then '' else '='
# Compiles the range's source variables -- where it starts and where it ends.