Fixing issue #676, chained accesses against the super() keyword.

This commit is contained in:
Jeremy Ashkenas 2010-09-12 16:33:38 -04:00
parent b727245834
commit a3c224e57a
4 changed files with 122 additions and 125 deletions

View File

@ -255,7 +255,7 @@
})
],
Call: [
o("Invocation"), o("Super"), o("NEW Invocation", function() {
o("Invocation"), o("NEW Invocation", function() {
return $2.newInstance();
}), o("NEW Value", function() {
return (new CallNode($2, [])).newInstance();
@ -271,6 +271,10 @@
return new CallNode($1, $3, $2);
}), o("Invocation OptFuncExist Arguments", function() {
return new CallNode($1, $3, $2);
}), o("SUPER", function() {
return new CallNode('super', [new SplatNode(new LiteralNode('arguments'))]);
}), o("SUPER Arguments", function() {
return new CallNode('super', $2);
})
],
OptFuncExist: [
@ -287,13 +291,6 @@
return $2;
})
],
Super: [
o("SUPER", function() {
return new CallNode('super', [new SplatNode(new LiteralNode('arguments'))]);
}), o("SUPER Arguments", function() {
return new CallNode('super', $2);
})
],
This: [
o("THIS", function() {
return new ValueNode(new LiteralNode('this'));
@ -615,7 +612,7 @@
})
]
};
operators = [["right", '?', 'NEW'], ["nonassoc", '++', '--'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'INSTANCEOF'], ["left", '==', '!='], ["left", 'LOGIC'], ["right", 'COMPOUND_ASSIGN'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
operators = [["right", '?', 'NEW'], ["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'INSTANCEOF'], ["left", '==', '!='], ["left", 'LOGIC'], ["right", 'COMPOUND_ASSIGN'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
tokens = [];
_a = grammar;
for (name in _a) {

File diff suppressed because one or more lines are too long

View File

@ -296,11 +296,9 @@ grammar =
o "{ ClassBody }", -> $2
]
# The three flavors of function call: normal, object instantiation with `new`,
# and calling `super()`
# The two flavors of function call: normal, and object instantiation with `new`.
Call: [
o "Invocation"
o "Super"
o "NEW Invocation", -> $2.newInstance()
o "NEW Value", -> (new CallNode($2, [])).newInstance()
]
@ -315,6 +313,8 @@ grammar =
Invocation: [
o "Value OptFuncExist Arguments", -> new CallNode $1, $3, $2
o "Invocation OptFuncExist Arguments", -> new CallNode $1, $3, $2
o "SUPER", -> new CallNode 'super', [new SplatNode(new LiteralNode('arguments'))]
o "SUPER Arguments", -> new CallNode 'super', $2
]
# An optional existence check on a function.
@ -329,12 +329,6 @@ grammar =
o "CALL_START ArgList OptComma CALL_END", -> $2
]
# Calling super.
Super: [
o "SUPER", -> new CallNode 'super', [new SplatNode(new LiteralNode('arguments'))]
o "SUPER Arguments", -> new CallNode 'super', $2
]
# A reference to the *this* current object.
This: [
o "THIS", -> new ValueNode new LiteralNode 'this'
@ -584,6 +578,7 @@ grammar =
# (2 + 3) * 4
operators = [
["right", '?', 'NEW']
["left", 'CALL_START', 'CALL_END']
["nonassoc", '++', '--']
["right", 'UNARY']
["left", 'MATH']

View File

@ -27,6 +27,13 @@ result = (new ThirdChild).func 'four'
ok result is 'zero/one/two/three/four'
ok Base.static('word') is 'static/word'
FirstChild::func = (string) ->
super('one/').length + string
result = (new ThirdChild).func 'four'
ok result is '9two/three/four'
class TopClass
constructor: (arg) ->