Implemented rescoping with the do keyword.
This commit is contained in:
parent
f52ef98cee
commit
d096f69c78
|
@ -38,7 +38,7 @@
|
|||
return new Literal($1);
|
||||
})
|
||||
],
|
||||
Expression: [o("Value"), o("Invocation"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Existence"), o("Comment")],
|
||||
Expression: [o("Value"), o("Invocation"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Existence"), o("Comment"), o("Do")],
|
||||
Block: [
|
||||
o("INDENT Body OUTDENT", function() {
|
||||
return $2;
|
||||
|
@ -106,6 +106,11 @@
|
|||
return new Existence($1);
|
||||
})
|
||||
],
|
||||
Do: [
|
||||
o("DO Code", function() {
|
||||
return new Call($2, $2.params);
|
||||
})
|
||||
],
|
||||
Code: [
|
||||
o("PARAM_START ParamList PARAM_END FuncGlyph Block", function() {
|
||||
return new Code($2, $5, $4);
|
||||
|
|
|
@ -585,7 +585,7 @@
|
|||
};
|
||||
return Lexer;
|
||||
})();
|
||||
JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
|
||||
JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'try', 'catch', 'finally', 'class', 'extends', 'super', 'do'];
|
||||
COFFEE_KEYWORDS = ['then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
|
||||
for (op in COFFEE_ALIASES = {
|
||||
and: '&&',
|
||||
|
@ -600,7 +600,7 @@
|
|||
}) {
|
||||
COFFEE_KEYWORDS.push(op);
|
||||
}
|
||||
RESERVED = ['case', 'default', 'do', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice'];
|
||||
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice'];
|
||||
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
|
||||
IDENTIFIER = /^([$A-Za-z_][$\w]*)([^\n\S]*:(?!:))?/;
|
||||
NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i;
|
||||
|
|
|
@ -1728,7 +1728,7 @@
|
|||
}).call(this);
|
||||
Push = {
|
||||
wrap: function(name, expressions) {
|
||||
if (expressions.empty() || (last(expressions.expressions)).containsPureStatement()) {
|
||||
if (expressions.empty() || last(expressions.expressions).containsPureStatement()) {
|
||||
return expressions;
|
||||
}
|
||||
return expressions.push(new Call(new Value(new Literal(name), [new Accessor(new Literal('push'))]), [expressions.pop()]));
|
||||
|
|
358
lib/parser.js
358
lib/parser.js
File diff suppressed because one or more lines are too long
|
@ -103,6 +103,7 @@ grammar =
|
|||
o "Class"
|
||||
o "Existence"
|
||||
o "Comment"
|
||||
o "Do"
|
||||
]
|
||||
|
||||
# An indented block of expressions. Note that the [Rewriter](rewriter.html)
|
||||
|
@ -169,6 +170,10 @@ grammar =
|
|||
Existence: [
|
||||
o "Expression ?", -> new Existence $1
|
||||
]
|
||||
|
||||
Do: [
|
||||
o "DO Code", -> new Call $2, $2.params
|
||||
]
|
||||
|
||||
# The **Code** node is the function literal. It's defined by an indented block
|
||||
# of **Expressions** preceded by a function arrow, with an optional parameter
|
||||
|
|
|
@ -515,7 +515,7 @@ JS_KEYWORDS = [
|
|||
'new', 'delete', 'typeof', 'in', 'instanceof'
|
||||
'return', 'throw', 'break', 'continue', 'debugger'
|
||||
'if', 'else', 'switch', 'for', 'while', 'try', 'catch', 'finally'
|
||||
'class', 'extends', 'super'
|
||||
'class', 'extends', 'super', 'do'
|
||||
]
|
||||
|
||||
# CoffeeScript-only keywords.
|
||||
|
@ -535,7 +535,7 @@ COFFEE_KEYWORDS.push op for all op of COFFEE_ALIASES =
|
|||
# used by CoffeeScript internally. We throw an error when these are encountered,
|
||||
# to avoid having a JavaScript error at runtime.
|
||||
RESERVED = [
|
||||
'case', 'default', 'do', 'function', 'var', 'void', 'with'
|
||||
'case', 'default', 'function', 'var', 'void', 'with'
|
||||
'const', 'let', 'enum', 'export', 'import', 'native'
|
||||
'__hasProp', '__extends', '__slice'
|
||||
]
|
||||
|
|
|
@ -345,3 +345,13 @@ eq ok, new ->
|
|||
ok
|
||||
### Should `return` implicitly ###
|
||||
### even with trailing comments. ###
|
||||
|
||||
|
||||
# Rescoping with the `do` keyword.
|
||||
v1 = 1
|
||||
v2 = 2
|
||||
do (v1) ->
|
||||
v1 = 3
|
||||
v2 = 4
|
||||
ok v1 is 1
|
||||
ok v2 is 4
|
||||
|
|
Loading…
Reference in New Issue