mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
finished moving over string and regex interpolation to use '#' instead of '$', Issue #544
This commit is contained in:
parent
d624310be1
commit
89cd25ab15
9 changed files with 45 additions and 50 deletions
30
Cakefile
30
Cakefile
|
@ -16,25 +16,25 @@ run = (args) ->
|
|||
|
||||
# Log a message with a color.
|
||||
log = (message, color, explanation) ->
|
||||
puts "$color$message$reset ${explanation or ''}"
|
||||
puts "#color#message#reset #{explanation or ''}"
|
||||
|
||||
option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
|
||||
|
||||
task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) ->
|
||||
base = options.prefix or '/usr/local'
|
||||
lib = "$base/lib/coffee-script"
|
||||
bin = "$base/bin"
|
||||
lib = "#base/lib/coffee-script"
|
||||
bin = "#base/bin"
|
||||
node = "~/.node_libraries/coffee-script"
|
||||
puts "Installing CoffeeScript to $lib"
|
||||
puts "Linking to $node"
|
||||
puts "Linking 'coffee' to $bin/coffee"
|
||||
puts "Installing CoffeeScript to #lib"
|
||||
puts "Linking to #node"
|
||||
puts "Linking 'coffee' to #bin/coffee"
|
||||
exec([
|
||||
"mkdir -p $lib $bin"
|
||||
"cp -rf bin lib LICENSE README package.json src $lib"
|
||||
"ln -sf $lib/bin/coffee $bin/coffee"
|
||||
"ln -sf $lib/bin/cake $bin/cake"
|
||||
"mkdir -p #lib #bin"
|
||||
"cp -rf bin lib LICENSE README package.json src #lib"
|
||||
"ln -sf #lib/bin/coffee #bin/coffee"
|
||||
"ln -sf #lib/bin/cake #bin/cake"
|
||||
"mkdir -p ~/.node_libraries"
|
||||
"ln -sf $lib/lib $node"
|
||||
"ln -sf #lib/lib #node"
|
||||
].join(' && '), (err, stdout, stderr) ->
|
||||
if err then print stderr else log 'done', green
|
||||
)
|
||||
|
@ -88,7 +88,7 @@ task 'doc:underscore', 'rebuild the Underscore.coffee documentation page', ->
|
|||
|
||||
task 'loc', 'count the lines of source code in the CoffeeScript compiler', ->
|
||||
sources = ['src/coffee-script.coffee', 'src/grammar.coffee', 'src/helpers.coffee', 'src/lexer.coffee', 'src/nodes.coffee', 'src/rewriter.coffee', 'src/scope.coffee']
|
||||
exec "cat ${ sources.join(' ') } | grep -v '^\\( *#\\|\\s*$\\)' | wc -l | tr -s ' '", (err, stdout) ->
|
||||
exec "cat #{ sources.join(' ') } | grep -v '^\\( *#\\|\\s*$\\)' | wc -l | tr -s ' '", (err, stdout) ->
|
||||
print stdout
|
||||
|
||||
|
||||
|
@ -103,9 +103,9 @@ task 'test', 'run the CoffeeScript language test suite', ->
|
|||
}
|
||||
process.on 'exit', ->
|
||||
time = ((new Date - startTime) / 1000).toFixed(2)
|
||||
message = "passed $passedTests tests in $time seconds$reset"
|
||||
message = "passed #passedTests tests in #time seconds#reset"
|
||||
if failedTests
|
||||
log "failed $failedTests and $message", red
|
||||
log "failed #failedTests and #message", red
|
||||
else
|
||||
log message, green
|
||||
fs.readdir 'test', (err, files) ->
|
||||
|
@ -117,4 +117,4 @@ task 'test', 'run the CoffeeScript language test suite', ->
|
|||
CoffeeScript.run code.toString(), {source: source}
|
||||
catch err
|
||||
failedTests += 1
|
||||
log "failed $source", red, '\n' + err.stack.toString()
|
||||
log "failed #source", red, '\n' + err.stack.toString()
|
||||
|
|
10
lib/lexer.js
10
lib/lexer.js
|
@ -129,7 +129,7 @@
|
|||
if (!(starts(this.chunk, '"') || starts(this.chunk, "'"))) {
|
||||
return false;
|
||||
}
|
||||
if (!(string = this.balancedToken(['"', '"'], ['${', '}'], ['#{', '}']) || this.balancedToken(["'", "'"]))) {
|
||||
if (!(string = this.balancedToken(['"', '"'], ['#{', '}']) || this.balancedToken(["'", "'"]))) {
|
||||
return false;
|
||||
}
|
||||
this.interpolateString(string.replace(STRING_NEWLINES, " \\\n"));
|
||||
|
@ -471,7 +471,7 @@
|
|||
tokens.push(['IDENTIFIER', interp]);
|
||||
i += group.length - 1;
|
||||
pi = i + 1;
|
||||
} else if ((expr = this.balancedString(str.substring(i), [['${', '}'], ['#{', '}']]))) {
|
||||
} else if ((expr = this.balancedString(str.substring(i), [['#{', '}']]))) {
|
||||
if (pi < i) {
|
||||
tokens.push(['STRING', ("" + quote + (str.substring(pi, i)) + quote)]);
|
||||
}
|
||||
|
@ -580,16 +580,16 @@
|
|||
IDENTIFIER = /^([a-zA-Z\$_](\w|\$)*)/;
|
||||
NUMBER = /^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-]?[0-9]+)?)))\b/i;
|
||||
HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/;
|
||||
INTERPOLATION = /^[$#]([a-zA-Z_@]\w*(\.\w+)*)/;
|
||||
INTERPOLATION = /^#([a-zA-Z_@]\w*(\.\w+)*)/;
|
||||
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>:!?]+)([ \t]*)/;
|
||||
WHITESPACE = /^([ \t]+)/;
|
||||
COMMENT = /^(\s*#{3}(?!#)[ \t]*\n+([\s\S]*?)[ \t]*\n+[ \t]*#{3}|(\s*#(?!##[^#])[^\n]*)+)/;
|
||||
COMMENT = /^(\s*\#{3}(?!#)[ \t]*\n+([\s\S]*?)[ \t]*\n+[ \t]*\#{3}|(\s*#(?!##[^#])[^\n]*)+)/;
|
||||
CODE = /^((-|=)>)/;
|
||||
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/;
|
||||
LAST_DENTS = /\n([ \t]*)/g;
|
||||
LAST_DENT = /\n([ \t]*)/;
|
||||
REGEX_START = /^\/[^\/ ]/;
|
||||
REGEX_INTERPOLATION = /([^\\]\$[a-zA-Z_@]|[^\\]\$\{.*[^\\]\})/;
|
||||
REGEX_INTERPOLATION = /([^\\]#[a-zA-Z_@]|[^\\]#\{.*[^\\]\})/;
|
||||
REGEX_END = /^(([imgy]{1,4})\b|\W|$)/;
|
||||
REGEX_ESCAPE = /\\[^\$]/g;
|
||||
JS_CLEANER = /(^`|`$)/g;
|
||||
|
|
|
@ -118,7 +118,7 @@ exports.Lexer = class Lexer
|
|||
stringToken: ->
|
||||
return false unless starts(@chunk, '"') or starts(@chunk, "'")
|
||||
return false unless string =
|
||||
@balancedToken(['"', '"'], ['${', '}'], ['#{', '}']) or
|
||||
@balancedToken(['"', '"'], ['#{', '}']) or
|
||||
@balancedToken ["'", "'"]
|
||||
@interpolateString string.replace STRING_NEWLINES, " \\\n"
|
||||
@line += count string, "\n"
|
||||
|
@ -400,7 +400,7 @@ exports.Lexer = class Lexer
|
|||
tokens.push ['IDENTIFIER', interp]
|
||||
i += group.length - 1
|
||||
pi = i + 1
|
||||
else if (expr = @balancedString str.substring(i), [['${', '}'], ['#{', '}']])
|
||||
else if (expr = @balancedString str.substring(i), [['#{', '}']])
|
||||
tokens.push ['STRING', "#quote#{ str.substring(pi, i) }#quote"] if pi < i
|
||||
inner = expr.substring(2, expr.length - 1)
|
||||
if inner.length
|
||||
|
@ -509,10 +509,10 @@ JS_FORBIDDEN = JS_KEYWORDS.concat RESERVED
|
|||
IDENTIFIER = /^([a-zA-Z\$_](\w|\$)*)/
|
||||
NUMBER = /^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-]?[0-9]+)?)))\b/i
|
||||
HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/
|
||||
INTERPOLATION = /^[$#]([a-zA-Z_@]\w*(\.\w+)*)/
|
||||
INTERPOLATION = /^#([a-zA-Z_@]\w*(\.\w+)*)/
|
||||
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>:!?]+)([ \t]*)/
|
||||
WHITESPACE = /^([ \t]+)/
|
||||
COMMENT = /^(\s*#{3}(?!#)[ \t]*\n+([\s\S]*?)[ \t]*\n+[ \t]*#{3}|(\s*#(?!##[^#])[^\n]*)+)/
|
||||
COMMENT = /^(\s*\#{3}(?!#)[ \t]*\n+([\s\S]*?)[ \t]*\n+[ \t]*\#{3}|(\s*#(?!##[^#])[^\n]*)+)/
|
||||
CODE = /^((-|=)>)/
|
||||
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/
|
||||
LAST_DENTS = /\n([ \t]*)/g
|
||||
|
@ -520,7 +520,7 @@ LAST_DENT = /\n([ \t]*)/
|
|||
|
||||
# Regex-matching-regexes.
|
||||
REGEX_START = /^\/[^\/ ]/
|
||||
REGEX_INTERPOLATION= /([^\\]\$[a-zA-Z_@]|[^\\]\$\{.*[^\\]\})/
|
||||
REGEX_INTERPOLATION= /([^\\]#[a-zA-Z_@]|[^\\]#\{.*[^\\]\})/
|
||||
REGEX_END = /^(([imgy]{1,4})\b|\W|$)/
|
||||
REGEX_ESCAPE = /\\[^\$]/g
|
||||
|
||||
|
|
|
@ -566,7 +566,7 @@ exports.RangeNode = class RangeNode extends BaseNode
|
|||
step = del o, 'step'
|
||||
step and= "#idx += #{step.compile(o)}"
|
||||
if from <= to
|
||||
"#idx = #from; #idx <#@equals #to; #{step or "$idx++"}"
|
||||
"#idx = #from; #idx <#@equals #to; #{step or "#idx++"}"
|
||||
else
|
||||
"#idx = #from; #idx >#@equals #to; #{step or "#idx--"}"
|
||||
|
||||
|
@ -1536,6 +1536,6 @@ literal = (name) ->
|
|||
|
||||
# Helper for ensuring that utility functions are assigned at the top level.
|
||||
utility = (name) ->
|
||||
ref = "__$name"
|
||||
ref = "__#name"
|
||||
Scope.root.assign ref, UTILITIES[name]
|
||||
ref
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# Test classes with a four-level inheritance chain.
|
||||
class Base
|
||||
func: (string) ->
|
||||
"zero/$string"
|
||||
"zero/#string"
|
||||
|
||||
@static: (string) ->
|
||||
"static/$string"
|
||||
"static/#string"
|
||||
|
||||
class FirstChild extends Base
|
||||
func: (string) ->
|
||||
|
@ -56,7 +56,7 @@ Base = ->
|
|||
Base::func = (string) ->
|
||||
'zero/' + string
|
||||
Base::['func-func'] = (string) ->
|
||||
"dynamic-$string"
|
||||
"dynamic-#string"
|
||||
|
||||
FirstChild = ->
|
||||
FirstChild extends Base
|
||||
|
@ -137,7 +137,7 @@ class Dog
|
|||
@name = name
|
||||
|
||||
bark: =>
|
||||
"$@name woofs!"
|
||||
"#@name woofs!"
|
||||
|
||||
spark = new Dog('Spark')
|
||||
fido = new Dog('Fido')
|
||||
|
@ -164,7 +164,7 @@ class Connection
|
|||
[@one, @two, @three] = [one, two, three]
|
||||
|
||||
out: ->
|
||||
"$@one-$@two-$@three"
|
||||
"#@one-#@two-#@three"
|
||||
|
||||
list = [3, 2, 1]
|
||||
conn = new Connection list...
|
||||
|
|
|
@ -85,11 +85,6 @@ fn = (arg) -> arg
|
|||
|
||||
ok fn(fn {prop: 101}).prop is 101
|
||||
|
||||
# Function calls sans-spacing.
|
||||
ok((fn (x) ->
|
||||
3
|
||||
)() is 3)
|
||||
|
||||
|
||||
# Multi-blocks with optional parens.
|
||||
result = fn( ->
|
||||
|
|
|
@ -55,17 +55,17 @@ ok a is 'more"than"one"quote'
|
|||
val = 10
|
||||
|
||||
a = """
|
||||
basic heredoc $val
|
||||
basic heredoc #val
|
||||
on two lines
|
||||
"""
|
||||
|
||||
b = '''
|
||||
basic heredoc $val
|
||||
basic heredoc #val
|
||||
on two lines
|
||||
'''
|
||||
|
||||
ok a is "basic heredoc 10\non two lines"
|
||||
ok b is "basic heredoc \$val\non two lines"
|
||||
ok b is "basic heredoc \#val\non two lines"
|
||||
|
||||
|
||||
a = '''here's an apostrophe'''
|
||||
|
|
|
@ -119,7 +119,7 @@ persons = {
|
|||
Christopher: { name: "Stan" }
|
||||
}
|
||||
|
||||
join1 = "$key: $name" for key, { name } of persons
|
||||
join1 = "#key: #name" for key, { name } of persons
|
||||
|
||||
deepEqual join1, ["George: Bob", "Bob: Alice", "Christopher: Stan"]
|
||||
|
||||
|
@ -129,11 +129,11 @@ persons = [
|
|||
{ name: "Stan", parent: { name: "Christopher" } }
|
||||
]
|
||||
|
||||
join2 = "$parent: $name" for { name, parent: { name: parent } } in persons
|
||||
join2 = "#parent: #name" for { name, parent: { name: parent } } in persons
|
||||
|
||||
deepEqual join1, join2
|
||||
|
||||
persons = [['Bob', ['George']], ['Alice', ['Bob']], ['Stan', ['Christopher']]]
|
||||
join3 = "$parent: $name" for [name, [parent]] in persons
|
||||
join3 = "#parent: #name" for [name, [parent]] in persons
|
||||
|
||||
deepEqual join2, join3
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
# Interpolate regular expressions.
|
||||
name = 'Moe'
|
||||
|
||||
ok not not '"Moe"'.match(/^"${name}"$/i)
|
||||
ok '"Moe!"'.match(/^"${name}"$/i) is null
|
||||
ok not not '"Moe"'.match(/^"#{name}"$/i)
|
||||
ok '"Moe!"'.match(/^"#{name}"$/i) is null
|
||||
|
||||
ok not not 'Moe'.match(/^$name$/)
|
||||
ok 'Moe!'.match(/^$name/)
|
||||
ok not not 'Moe'.match(/^#name$/)
|
||||
ok 'Moe!'.match(/^#name/)
|
||||
|
||||
ok 'Moe!'.match(/${"${"${"$name"}"}"}/imgy)
|
||||
ok 'Moe!'.match(/#{"#{"#{"#name"}"}"}/imgy)
|
||||
|
||||
ok '$a$b$c'.match(/\$A\$B\$C/i)
|
||||
|
||||
a = 1
|
||||
b = 2
|
||||
c = 3
|
||||
ok '123'.match(/$a$b$c/i)
|
||||
ok '123'.match(/#a#b#c/i)
|
||||
|
||||
[a, b, c] = [1, 2, /\d+/]
|
||||
ok (/$a$b$c$/i).toString() is '/12/\\d+/$/i'
|
||||
ok (/#a#b#c$/i).toString() is '/12/\\d+/$/i'
|
||||
|
|
Loading…
Reference in a new issue