mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
going back to familiar operators +: is just too strange
This commit is contained in:
@@ -6,4 +6,4 @@ if happy and knows_it
|
||||
|
||||
date: if friday then sue else jill.
|
||||
|
||||
expensive ||: do_the_math()
|
||||
expensive ||= do_the_math()
|
||||
@@ -273,9 +273,9 @@ coffee-script --print app/scripts/*.cs > concatenation.js</pre>
|
||||
</p>
|
||||
<%= code_for('conditionals') %>
|
||||
<p>
|
||||
The conditional assignment operators are available: <tt>||:</tt>,
|
||||
The conditional assignment operators are available: <tt>||=</tt>,
|
||||
which only assigns a value to a variable if the variable's current value
|
||||
is falsy, and <tt>&&:</tt>, which only replaces the value of
|
||||
is falsy, and <tt>&&=</tt>, which only replaces the value of
|
||||
truthy variables.
|
||||
</p>
|
||||
|
||||
|
||||
@@ -62,8 +62,8 @@ race: =>
|
||||
race().
|
||||
|
||||
# Conditional assignment:
|
||||
good ||: evil
|
||||
wine &&: cheese
|
||||
good ||= evil
|
||||
wine &&= cheese
|
||||
|
||||
# Nested property access and calls.
|
||||
((moon.turn(360))).shapes[3].move({x: 45, y: 30}).position['top'].offset('x')
|
||||
|
||||
@@ -81,9 +81,9 @@ Creature : {
|
||||
hit: damage =>
|
||||
p_up: Math.rand( this.charisma )
|
||||
if p_up % 9 is 7
|
||||
this.life +: p_up / 4
|
||||
this.life += p_up / 4
|
||||
puts( "[" + this.name + " magick powers up " + p_up + "!]" ).
|
||||
this.life -: damage
|
||||
this.life -= damage
|
||||
if this.life <= 0 then puts( "[" + this.name + " has died.]" )..
|
||||
|
||||
# This method takes one turn in a fight.
|
||||
|
||||
@@ -406,7 +406,7 @@ var new_num = change_numbers();
|
||||
|
||||
date<span class="Keyword">:</span> <span class="Keyword">if</span> friday <span class="Keyword">then</span> sue <span class="Keyword">else</span> jill.
|
||||
|
||||
expensive <span class="Keyword">||</span><span class="Keyword">:</span> do_the_math()
|
||||
expensive <span class="Keyword">||</span><span class="Keyword">=</span> do_the_math()
|
||||
</pre><pre class="idle"><span class="Storage">var</span> mood;
|
||||
<span class="Keyword">if</span> (singing) {
|
||||
mood <span class="Keyword">=</span> greatly_improved;
|
||||
@@ -419,9 +419,9 @@ expensive <span class="Keyword">||</span><span class="Keyword">:</span> do_the_m
|
||||
expensive <span class="Keyword">=</span> expensive <span class="Keyword">||</span> do_the_math();
|
||||
</pre><br class='clear' /></div>
|
||||
<p>
|
||||
The conditional assignment operators are available: <tt>||:</tt>,
|
||||
The conditional assignment operators are available: <tt>||=</tt>,
|
||||
which only assigns a value to a variable if the variable's current value
|
||||
is falsy, and <tt>&&:</tt>, which only replaces the value of
|
||||
is falsy, and <tt>&&=</tt>, which only replaces the value of
|
||||
truthy variables.
|
||||
</p>
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@
|
||||
</dict>
|
||||
<dict>
|
||||
<key>match</key>
|
||||
<string>!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\?|\|\||\:|\*:|(?<!\()/=|%:|\+:|\-:|&=|\^=|\b(in|instanceof|new|delete|typeof|and|or|is|isnt|not)\b</string>
|
||||
<string>!|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\?|\|\||\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(in|instanceof|new|delete|typeof|and|or|is|isnt|not)\b</string>
|
||||
<key>name</key>
|
||||
<string>keyword.operator.cs</string>
|
||||
</dict>
|
||||
|
||||
@@ -26,12 +26,12 @@ prechigh
|
||||
left '<=' '<' '>' '>='
|
||||
right '==' '!=' IS ISNT
|
||||
left '&&' '||' AND OR
|
||||
right '-:' '+:' '/:' '*:' '%:'
|
||||
right '-=' '+=' '/=' '*=' '%='
|
||||
right DELETE INSTANCEOF TYPEOF
|
||||
left "."
|
||||
right THROW FOR IN WHILE NEW SUPER
|
||||
left UNLESS IF ELSE EXTENDS
|
||||
left ":" '||:' '&&:'
|
||||
left ":" '||=' '&&='
|
||||
right RETURN
|
||||
preclow
|
||||
|
||||
@@ -179,13 +179,13 @@ rule
|
||||
| Expression AND Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression OR Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
|
||||
| Expression '-:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '+:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '/:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '*:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '%:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '||:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '&&:' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '-=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '+=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '/=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '*=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '%=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '||=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
| Expression '&&=' Expression { result = OpNode.new(val[1], val[0], val[2]) }
|
||||
|
||||
| DELETE Expression { result = OpNode.new(val[0], val[1]) }
|
||||
| TYPEOF Expression { result = OpNode.new(val[0], val[1]) }
|
||||
|
||||
@@ -7,12 +7,12 @@ loader: {
|
||||
|
||||
# Reload the coffee-script environment from source.
|
||||
reload: topId, path =>
|
||||
coffeescript ||: require('coffee-script')
|
||||
coffeescript ||= require('coffee-script')
|
||||
factories[topId]: coffeescript.makeNarwhalFactory(path).
|
||||
|
||||
# Ensure that the coffee-script environment is loaded.
|
||||
load: topId, path =>
|
||||
factories[topId] ||: this.reload(topId, path).
|
||||
factories[topId] ||= this.reload(topId, path).
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -358,14 +358,9 @@ module CoffeeScript
|
||||
'or' => '||',
|
||||
'is' => '===',
|
||||
"isnt" => "!==",
|
||||
'not' => '!',
|
||||
'+:' => '+=',
|
||||
'-:' => '-=',
|
||||
'*:' => '*=',
|
||||
'/:' => '/=',
|
||||
'%:' => '%='
|
||||
'not' => '!'
|
||||
}
|
||||
CONDITIONALS = ['||:', '&&:']
|
||||
CONDITIONALS = ['||=', '&&=']
|
||||
PREFIX_OPERATORS = ['typeof', 'delete']
|
||||
|
||||
attr_reader :operator, :first, :second
|
||||
|
||||
Reference in New Issue
Block a user