Addressing some assignment issues.
This commit is contained in:
parent
7de5253318
commit
7b9a8998cf
|
@ -117,7 +117,7 @@
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
// Assignment of a variable, property, or index to a value.
|
// Assignment of a variable, property, or index to a value.
|
||||||
Assign: [o("Value ASSIGN Expression", function() {
|
Assign: [o("Assignable ASSIGN Expression", function() {
|
||||||
return new AssignNode($1, $3);
|
return new AssignNode($1, $3);
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
@ -187,24 +187,29 @@
|
||||||
return new SplatNode($1);
|
return new SplatNode($1);
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
// The types of things that can be treated as values -- assigned to, invoked
|
// Everything that can be assigned to.
|
||||||
// as functions, indexed into, named as a class, etc.
|
Assignable: [o("Identifier", function() {
|
||||||
Value: [o("Identifier", function() {
|
|
||||||
return new ValueNode($1);
|
|
||||||
}), o("Literal", function() {
|
|
||||||
return new ValueNode($1);
|
return new ValueNode($1);
|
||||||
}), o("Array", function() {
|
}), o("Array", function() {
|
||||||
return new ValueNode($1);
|
return new ValueNode($1);
|
||||||
}), o("Object", function() {
|
}), o("Object", function() {
|
||||||
return new ValueNode($1);
|
return new ValueNode($1);
|
||||||
|
}), o("Value Accessor", function() {
|
||||||
|
return $1.push($2);
|
||||||
|
}), o("Invocation Accessor", function() {
|
||||||
|
return new ValueNode($1, [$2]);
|
||||||
|
}), o("ThisProperty")
|
||||||
|
],
|
||||||
|
// The types of things that can be treated as values -- assigned to, invoked
|
||||||
|
// as functions, indexed into, named as a class, etc.
|
||||||
|
Value: [o("Assignable"), o("Literal", function() {
|
||||||
|
return new ValueNode($1);
|
||||||
}), o("Parenthetical", function() {
|
}), o("Parenthetical", function() {
|
||||||
return new ValueNode($1);
|
return new ValueNode($1);
|
||||||
}), o("Range", function() {
|
}), o("Range", function() {
|
||||||
return new ValueNode($1);
|
return new ValueNode($1);
|
||||||
}), o("This"), o("Value Accessor", function() {
|
}), o("This"), o("NULL", function() {
|
||||||
return $1.push($2);
|
return new ValueNode(new LiteralNode('null'));
|
||||||
}), o("Invocation Accessor", function() {
|
|
||||||
return new ValueNode($1, [$2]);
|
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
// The general group of accessors into an object, by property, by prototype
|
// The general group of accessors into an object, by property, by prototype
|
||||||
|
@ -241,13 +246,13 @@
|
||||||
],
|
],
|
||||||
// Class definitions have optional bodies of prototype property assignments,
|
// Class definitions have optional bodies of prototype property assignments,
|
||||||
// and optional references to the superclass.
|
// and optional references to the superclass.
|
||||||
Class: [o("CLASS Value", function() {
|
Class: [o("CLASS Identifier", function() {
|
||||||
return new ClassNode($2);
|
return new ClassNode($2);
|
||||||
}), o("CLASS Value EXTENDS Value", function() {
|
}), o("CLASS Identifier EXTENDS Value", function() {
|
||||||
return new ClassNode($2, $4);
|
return new ClassNode($2, $4);
|
||||||
}), o("CLASS Value IndentedAssignList", function() {
|
}), o("CLASS Identifier IndentedAssignList", function() {
|
||||||
return new ClassNode($2, null, $3);
|
return new ClassNode($2, null, $3);
|
||||||
}), o("CLASS Value EXTENDS Value IndentedAssignList", function() {
|
}), o("CLASS Identifier EXTENDS Value IndentedAssignList", function() {
|
||||||
return new ClassNode($2, $4, $5);
|
return new ClassNode($2, $4, $5);
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
@ -309,10 +314,15 @@
|
||||||
return new CallNode('super', $3);
|
return new CallNode('super', $3);
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
// A reference to the *this* current object, either naked or to a property.
|
// A reference to the *this* current object.
|
||||||
This: [o("@", function() {
|
This: [o("THIS", function() {
|
||||||
return new ValueNode(new LiteralNode('this'));
|
return new ValueNode(new LiteralNode('this'));
|
||||||
}), o("@ Identifier", function() {
|
}), o("@", function() {
|
||||||
|
return new ValueNode(new LiteralNode('this'));
|
||||||
|
})
|
||||||
|
],
|
||||||
|
// A reference to a property on *this*.
|
||||||
|
ThisProperty: [o("@ Identifier", function() {
|
||||||
return new ValueNode(new LiteralNode('this'), [new AccessorNode($2)]);
|
return new ValueNode(new LiteralNode('this'), [new AccessorNode($2)]);
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
|
@ -596,7 +596,7 @@
|
||||||
// Constants
|
// Constants
|
||||||
// ---------
|
// ---------
|
||||||
// Keywords that CoffeeScript shares in common with JavaScript.
|
// Keywords that CoffeeScript shares in common with JavaScript.
|
||||||
JS_KEYWORDS = ["if", "else", "true", "false", "new", "return", "try", "catch", "finally", "throw", "break", "continue", "for", "in", "while", "delete", "instanceof", "typeof", "switch", "super", "extends", "class"];
|
JS_KEYWORDS = ["if", "else", "true", "false", "new", "return", "try", "catch", "finally", "throw", "break", "continue", "for", "in", "while", "delete", "instanceof", "typeof", "switch", "super", "extends", "class", "this", "null"];
|
||||||
// CoffeeScript-only keywords, which we're more relaxed about allowing. They can't
|
// CoffeeScript-only keywords, which we're more relaxed about allowing. They can't
|
||||||
// be used standalone, but you can reference them as an attached property.
|
// be used standalone, but you can reference them as an attached property.
|
||||||
COFFEE_ALIASES = ["and", "or", "is", "isnt", "not"];
|
COFFEE_ALIASES = ["and", "or", "is", "isnt", "not"];
|
||||||
|
|
282
lib/parser.js
282
lib/parser.js
File diff suppressed because one or more lines are too long
|
@ -384,7 +384,7 @@
|
||||||
// Tokens that, if followed by an `IMPLICIT_CALL`, indicate a function invocation.
|
// Tokens that, if followed by an `IMPLICIT_CALL`, indicate a function invocation.
|
||||||
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '<-'];
|
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '<-'];
|
||||||
// If preceded by an `IMPLICIT_FUNC`, indicates a function invocation.
|
// If preceded by an `IMPLICIT_FUNC`, indicates a function invocation.
|
||||||
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'EXTENSION', 'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'NOT', '@', '->', '=>', '[', '(', '{'];
|
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'EXTENSION', 'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'NOT', 'THIS', 'NULL', '@', '->', '=>', '[', '(', '{'];
|
||||||
// Tokens indicating that the implicit call must enclose a block of expressions.
|
// Tokens indicating that the implicit call must enclose a block of expressions.
|
||||||
IMPLICIT_BLOCK = ['->', '=>', '{', '[', ','];
|
IMPLICIT_BLOCK = ['->', '=>', '{', '[', ','];
|
||||||
// Tokens that always mark the end of an implicit call for single-liners.
|
// Tokens that always mark the end of an implicit call for single-liners.
|
||||||
|
|
|
@ -132,7 +132,7 @@ grammar: {
|
||||||
|
|
||||||
# Assignment of a variable, property, or index to a value.
|
# Assignment of a variable, property, or index to a value.
|
||||||
Assign: [
|
Assign: [
|
||||||
o "Value ASSIGN Expression", -> new AssignNode $1, $3
|
o "Assignable ASSIGN Expression", -> new AssignNode $1, $3
|
||||||
]
|
]
|
||||||
|
|
||||||
# Assignment when it happens within an object literal. The difference from
|
# Assignment when it happens within an object literal. The difference from
|
||||||
|
@ -195,18 +195,25 @@ grammar: {
|
||||||
o "Expression . . .", -> new SplatNode $1
|
o "Expression . . .", -> new SplatNode $1
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Everything that can be assigned to.
|
||||||
|
Assignable: [
|
||||||
|
o "Identifier", -> new ValueNode $1
|
||||||
|
o "Array", -> new ValueNode $1
|
||||||
|
o "Object", -> new ValueNode $1
|
||||||
|
o "Value Accessor", -> $1.push $2
|
||||||
|
o "Invocation Accessor", -> new ValueNode $1, [$2]
|
||||||
|
o "ThisProperty"
|
||||||
|
]
|
||||||
|
|
||||||
# The types of things that can be treated as values -- assigned to, invoked
|
# The types of things that can be treated as values -- assigned to, invoked
|
||||||
# as functions, indexed into, named as a class, etc.
|
# as functions, indexed into, named as a class, etc.
|
||||||
Value: [
|
Value: [
|
||||||
o "Identifier", -> new ValueNode $1
|
o "Assignable"
|
||||||
o "Literal", -> new ValueNode $1
|
o "Literal", -> new ValueNode $1
|
||||||
o "Array", -> new ValueNode $1
|
|
||||||
o "Object", -> new ValueNode $1
|
|
||||||
o "Parenthetical", -> new ValueNode $1
|
o "Parenthetical", -> new ValueNode $1
|
||||||
o "Range", -> new ValueNode $1
|
o "Range", -> new ValueNode $1
|
||||||
o "This"
|
o "This"
|
||||||
o "Value Accessor", -> $1.push $2
|
o "NULL", -> new ValueNode new LiteralNode 'null'
|
||||||
o "Invocation Accessor", -> new ValueNode $1, [$2]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# The general group of accessors into an object, by property, by prototype
|
# The general group of accessors into an object, by property, by prototype
|
||||||
|
@ -237,10 +244,10 @@ grammar: {
|
||||||
# Class definitions have optional bodies of prototype property assignments,
|
# Class definitions have optional bodies of prototype property assignments,
|
||||||
# and optional references to the superclass.
|
# and optional references to the superclass.
|
||||||
Class: [
|
Class: [
|
||||||
o "CLASS Value", -> new ClassNode $2
|
o "CLASS Identifier", -> new ClassNode $2
|
||||||
o "CLASS Value EXTENDS Value", -> new ClassNode $2, $4
|
o "CLASS Identifier EXTENDS Value", -> new ClassNode $2, $4
|
||||||
o "CLASS Value IndentedAssignList", -> new ClassNode $2, null, $3
|
o "CLASS Identifier IndentedAssignList", -> new ClassNode $2, null, $3
|
||||||
o "CLASS Value EXTENDS Value IndentedAssignList", -> new ClassNode $2, $4, $5
|
o "CLASS Identifier EXTENDS Value IndentedAssignList", -> new ClassNode $2, $4, $5
|
||||||
]
|
]
|
||||||
|
|
||||||
# Assignment of properties within an object literal can be separated by
|
# Assignment of properties within an object literal can be separated by
|
||||||
|
@ -295,9 +302,14 @@ grammar: {
|
||||||
o "SUPER CALL_START ArgList , CALL_END", -> new CallNode 'super', $3
|
o "SUPER CALL_START ArgList , CALL_END", -> new CallNode 'super', $3
|
||||||
]
|
]
|
||||||
|
|
||||||
# A reference to the *this* current object, either naked or to a property.
|
# A reference to the *this* current object.
|
||||||
This: [
|
This: [
|
||||||
|
o "THIS", -> new ValueNode new LiteralNode 'this'
|
||||||
o "@", -> new ValueNode new LiteralNode 'this'
|
o "@", -> new ValueNode new LiteralNode 'this'
|
||||||
|
]
|
||||||
|
|
||||||
|
# A reference to a property on *this*.
|
||||||
|
ThisProperty: [
|
||||||
o "@ Identifier", -> new ValueNode new LiteralNode('this'), [new AccessorNode($2)]
|
o "@ Identifier", -> new ValueNode new LiteralNode('this'), [new AccessorNode($2)]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -438,7 +438,8 @@ JS_KEYWORDS: [
|
||||||
"break", "continue",
|
"break", "continue",
|
||||||
"for", "in", "while",
|
"for", "in", "while",
|
||||||
"delete", "instanceof", "typeof",
|
"delete", "instanceof", "typeof",
|
||||||
"switch", "super", "extends", "class"
|
"switch", "super", "extends", "class",
|
||||||
|
"this", "null"
|
||||||
]
|
]
|
||||||
|
|
||||||
# CoffeeScript-only keywords, which we're more relaxed about allowing. They can't
|
# CoffeeScript-only keywords, which we're more relaxed about allowing. They can't
|
||||||
|
|
|
@ -263,6 +263,7 @@ IMPLICIT_FUNC: ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '<-']
|
||||||
IMPLICIT_CALL: ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START',
|
IMPLICIT_CALL: ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START',
|
||||||
'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'EXTENSION',
|
'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'EXTENSION',
|
||||||
'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'NOT',
|
'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'NOT',
|
||||||
|
'THIS', 'NULL',
|
||||||
'@', '->', '=>', '[', '(', '{']
|
'@', '->', '=>', '[', '(', '{']
|
||||||
|
|
||||||
# Tokens indicating that the implicit call must enclose a block of expressions.
|
# Tokens indicating that the implicit call must enclose a block of expressions.
|
||||||
|
|
Loading…
Reference in New Issue