Allowing @[property] syntax.

This commit is contained in:
Jeremy Ashkenas
2010-02-20 20:09:52 -05:00
parent 0f2a2ee11e
commit b027b5cf0d
5 changed files with 6 additions and 3 deletions

View File

@@ -343,6 +343,8 @@
return new ValueNode(new LiteralNode('this'));
}), o("@ Identifier", function() {
return new ValueNode(new LiteralNode('this'), [new AccessorNode($2)]);
}), o("@ Index", function() {
return new ValueNode(new LiteralNode('this'), [$2]);
})
],
// The range literal.

View File

@@ -49,7 +49,7 @@
// See: http://www.mozilla.org/js/language/js20-2002-04/rationale/syntax.html#regular-expressions
NOT_REGEX = ['IDENTIFIER', 'NUMBER', 'REGEX', 'STRING', ')', '++', '--', ']', '}', 'FALSE', 'NULL', 'TRUE'];
// Tokens which could legitimately be invoked or indexed.
CALLABLE = ['IDENTIFIER', 'SUPER', ')', ']', '}', 'STRING'];
CALLABLE = ['IDENTIFIER', 'SUPER', ')', ']', '}', 'STRING', '@'];
// Tokens that indicate an access -- keywords immediately following will be
// treated as identifiers.
ACCESSORS = ['PROPERTY_ACCESS', 'PROTOTYPE_ACCESS', 'SOAK_ACCESS', '@'];

View File

@@ -300,6 +300,7 @@ grammar: {
This: [
o "@", -> new ValueNode(new LiteralNode('this'))
o "@ Identifier", -> new ValueNode(new LiteralNode('this'), [new AccessorNode($2)])
o "@ Index", -> new ValueNode(new LiteralNode('this'), [$2])
]
# The range literal.

View File

@@ -78,7 +78,7 @@ NOT_REGEX: [
]
# Tokens which could legitimately be invoked or indexed.
CALLABLE: ['IDENTIFIER', 'SUPER', ')', ']', '}', 'STRING']
CALLABLE: ['IDENTIFIER', 'SUPER', ')', ']', '}', 'STRING', '@']
# Tokens that indicate an access -- keywords immediately following will be
# treated as identifiers.

View File

@@ -45,7 +45,7 @@ bob: {
greet: (salutation) ->
salutation + " " + @name
hello: ->
@greet "Hello"
@['greet'] "Hello"
10: 'number'
}