mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
trying out new arrows for function literals -> is a function, => is a bound function
This commit is contained in:
@@ -39,7 +39,7 @@ prechigh
|
||||
left EXTENDS
|
||||
left '||=' '&&=' '?='
|
||||
right ASSIGN RETURN
|
||||
right '=>' '==>' UNLESS IF ELSE WHILE
|
||||
right '->' '=>' UNLESS IF ELSE WHILE
|
||||
preclow
|
||||
|
||||
rule
|
||||
@@ -207,8 +207,8 @@ rule
|
||||
|
||||
# The symbols to signify functions, and bound functions.
|
||||
FuncGlyph:
|
||||
'=>' { result = :func }
|
||||
| '==>' { result = :boundfunc }
|
||||
'->' { result = :func }
|
||||
| '=>' { result = :boundfunc }
|
||||
;
|
||||
|
||||
# The parameters to a function definition.
|
||||
|
||||
@@ -27,7 +27,7 @@ module CoffeeScript
|
||||
OPERATOR = /\A([+\*&|\/\-%=<>:!?]+)/
|
||||
WHITESPACE = /\A([ \t]+)/
|
||||
COMMENT = /\A(((\n?[ \t]*)?#.*$)+)/
|
||||
CODE = /\A(=?=>)/
|
||||
CODE = /\A((-|=)>)/
|
||||
REGEX = /\A(\/(.*?)([^\\]|\\\\)\/[imgy]{0,4})/
|
||||
MULTI_DENT = /\A((\n([ \t]*))+)(\.)?/
|
||||
LAST_DENT = /\n([ \t]*)/
|
||||
|
||||
@@ -12,14 +12,14 @@ Readline: require('readline')
|
||||
coffeePath: File.path(module.path).dirname().dirname().dirname().dirname().dirname().join('bin', 'coffee')
|
||||
|
||||
# Our general-purpose error handler.
|
||||
checkForErrors: (coffeeProcess) =>
|
||||
checkForErrors: (coffeeProcess) ->
|
||||
return true if coffeeProcess.wait() is 0
|
||||
system.stderr.print(coffeeProcess.stderr.read())
|
||||
throw new Error("CoffeeScript compile error")
|
||||
|
||||
# Run a simple REPL, round-tripping to the CoffeeScript compiler for every
|
||||
# command.
|
||||
exports.run: (args) =>
|
||||
exports.run: (args) ->
|
||||
if args.length
|
||||
for path, i in args
|
||||
exports.evalCS(File.read(path))
|
||||
@@ -35,24 +35,24 @@ exports.run: (args) =>
|
||||
print(e)
|
||||
|
||||
# Compile a given CoffeeScript file into JavaScript.
|
||||
exports.compileFile: (path) =>
|
||||
exports.compileFile: (path) ->
|
||||
coffee: OS.popen([coffeePath, "--print", "--no-wrap", path])
|
||||
checkForErrors(coffee)
|
||||
coffee.stdout.read()
|
||||
|
||||
# Compile a string of CoffeeScript into JavaScript.
|
||||
exports.compile: (source, flags) =>
|
||||
exports.compile: (source, flags) ->
|
||||
coffee: OS.popen([coffeePath, "--eval", "--no-wrap"].concat(flags or []))
|
||||
coffee.stdin.write(source).flush().close()
|
||||
checkForErrors(coffee)
|
||||
coffee.stdout.read()
|
||||
|
||||
# Evaluating a string of CoffeeScript first compiles it externally.
|
||||
exports.evalCS: (source, flags) =>
|
||||
exports.evalCS: (source, flags) ->
|
||||
eval(exports.compile(source, flags))
|
||||
|
||||
# Make a factory for the CoffeeScript environment.
|
||||
exports.makeNarwhalFactory: (path) =>
|
||||
exports.makeNarwhalFactory: (path) ->
|
||||
code: exports.compileFile(path)
|
||||
factoryText: "function(require,exports,module,system,print){" + code + "/**/\n}"
|
||||
if system.engine is "rhino"
|
||||
|
||||
@@ -6,12 +6,12 @@ factories: {}
|
||||
loader: {
|
||||
|
||||
# Reload the coffee-script environment from source.
|
||||
reload: (topId, path) =>
|
||||
reload: (topId, path) ->
|
||||
coffeescript ||= require('coffee-script')
|
||||
factories[topId]: => coffeescript.makeNarwhalFactory(path)
|
||||
factories[topId]: -> coffeescript.makeNarwhalFactory(path)
|
||||
|
||||
# Ensure that the coffee-script environment is loaded.
|
||||
load: (topId, path) =>
|
||||
load: (topId, path) ->
|
||||
factories[topId] ||= this.reload(topId, path)
|
||||
|
||||
}
|
||||
|
||||
@@ -1141,8 +1141,8 @@ racc_token_table = {
|
||||
"&&=" => 87,
|
||||
"?=" => 88,
|
||||
:ASSIGN => 89,
|
||||
"=>" => 90,
|
||||
"==>" => 91,
|
||||
"->" => 90,
|
||||
"=>" => 91,
|
||||
"\n" => 92,
|
||||
";" => 93,
|
||||
"," => 94,
|
||||
@@ -1264,8 +1264,8 @@ Racc_token_to_s_table = [
|
||||
"\"&&=\"",
|
||||
"\"?=\"",
|
||||
"ASSIGN",
|
||||
"\"->\"",
|
||||
"\"=>\"",
|
||||
"\"==>\"",
|
||||
"\"\\n\"",
|
||||
"\";\"",
|
||||
"\",\"",
|
||||
|
||||
@@ -22,7 +22,7 @@ module CoffeeScript
|
||||
IMPLICIT_END = [:IF, :UNLESS, :FOR, :WHILE, "\n", :PARAM_START, :OUTDENT]
|
||||
IMPLICIT_CALL = [:IDENTIFIER, :NUMBER, :STRING, :JS, :REGEX, :NEW, :PARAM_START,
|
||||
:TRY, :DELETE, :INSTANCEOF, :TYPEOF, :SWITCH, :ARGUMENTS,
|
||||
:TRUE, :FALSE, :YES, :NO, :ON, :OFF, '!', '!!', :NOT, '=>', '==>']
|
||||
:TRUE, :FALSE, :YES, :NO, :ON, :OFF, '!', '!!', :NOT, '->', '=>']
|
||||
|
||||
# The inverse mappings of token pairs we're trying to fix up.
|
||||
INVERSES = BALANCED_PAIRS.inject({}) do |memo, pair|
|
||||
@@ -33,7 +33,7 @@ module CoffeeScript
|
||||
|
||||
# Single-line flavors of block expressions that have unclosed endings.
|
||||
# The grammar can't disambiguate them, so we insert the implicit indentation.
|
||||
SINGLE_LINERS = [:ELSE, "=>", "==>", :TRY, :FINALLY, :THEN]
|
||||
SINGLE_LINERS = [:ELSE, "->", "=>", :TRY, :FINALLY, :THEN]
|
||||
SINGLE_CLOSERS = ["\n", :CATCH, :FINALLY, :ELSE, :OUTDENT, :LEADING_WHEN, :PARAM_START]
|
||||
|
||||
# Rewrite the token stream in multiple passes, one logical filter at
|
||||
@@ -193,7 +193,7 @@ module CoffeeScript
|
||||
end
|
||||
|
||||
# We'd like to support syntax like this:
|
||||
# el.click((event) =>
|
||||
# el.click((event) ->
|
||||
# el.hide())
|
||||
# In order to accomplish this, move outdents that follow closing parens
|
||||
# inwards, safely. The steps to accomplish this are:
|
||||
|
||||
Reference in New Issue
Block a user