From beae912a91c957729f2f80cd1c383f7f4ba14a54 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Thu, 24 Dec 2009 22:25:29 -0800 Subject: [PATCH] making all assignment-y operators use a colon -- now it's +: -: *: /:, and friends --- examples/poignant.cs | 4 ++-- .../Syntaxes/CoffeeScript.tmLanguage | 2 +- lib/coffee_script/grammar.y | 11 ++++++----- lib/coffee_script/nodes.rb | 5 +++++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/poignant.cs b/examples/poignant.cs index 7c9b05f5..1a6c77ee 100644 --- a/examples/poignant.cs +++ b/examples/poignant.cs @@ -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. diff --git a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage index 6a35fb27..58640113 100644 --- a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +++ b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage @@ -241,7 +241,7 @@ match - !|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\?|\|\||\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^=|\b(in|instanceof|new|delete|typeof|and|or|is|isnt|not)\b + !|\$|%|&|\*|\-\-|\-|\+\+|\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\?|\|\||\:|\*:|(?<!\()/=|%:|\+:|\-:|&=|\^=|\b(in|instanceof|new|delete|typeof|and|or|is|isnt|not)\b name keyword.operator.cs diff --git a/lib/coffee_script/grammar.y b/lib/coffee_script/grammar.y index 81c0ef19..e1ff0196 100644 --- a/lib/coffee_script/grammar.y +++ b/lib/coffee_script/grammar.y @@ -26,7 +26,7 @@ prechigh left '<=' '<' '>' '>=' right '==' '!=' IS ISNT left '&&' '||' AND OR - right '-=' '+=' '/=' '*=' + right '-:' '+:' '/:' '*:' '%:' right DELETE INSTANCEOF TYPEOF left "." right THROW FOR IN WHILE NEW SUPER @@ -179,10 +179,11 @@ 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]) } diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index 93369c47..16b20b75 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -359,6 +359,11 @@ module CoffeeScript 'is' => '===', "isnt" => "!==", 'not' => '!', + '+:' => '+=', + '-:' => '-=', + '*:' => '*=', + '/:' => '/=', + '%:' => '%=' } CONDITIONALS = ['||:', '&&:'] PREFIX_OPERATORS = ['typeof', 'delete']