diff --git a/Rakefile b/Rakefile index 422ba989..432a9d16 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,4 @@ +require 'erb' require 'fileutils' require 'rake/testtask' @@ -14,6 +15,12 @@ task :build, :extra_args do |t, args| sh "racc #{args[:extra_args]} -o lib/coffee_script/parser.rb lib/coffee_script/grammar.y" end +desc "Build the documentation page" +task :doc do + rendered = ERB.new(File.read('documentation/index.html.erb')).result(binding) + File.open('index.html', 'w+') {|f| f.write(rendered) } +end + namespace :gem do desc 'Build and install the coffee-script gem' diff --git a/examples/poignant.cs b/examples/poignant.cs index d9e705b0..7c9b05f5 100644 --- a/examples/poignant.cs +++ b/examples/poignant.cs @@ -102,4 +102,52 @@ Creature : { puts( "[Your enemy hit with " + enemy_hit + "points of damage!]" ) this.hit( enemy_hit ).. -} \ No newline at end of file +} + + + +# # Get evil idea and swap in code words +# print "Enter your new idea: " +# idea = gets +# code_words.each do |real, code| +# idea.gsub!( real, code ) +# end +# +# # Save the jibberish to a new file +# print "File encoded. Please enter a name for this idea: " +# idea_name = gets.strip +# File::open( "idea-" + idea_name + ".txt", "w" ) do |f| +# f << idea +# end + +# Get evil idea and swap in code words +print("Enter your new idea: ") +idea: gets() +code_words.each( real, code => idea.replace(real, code). ) + +# Save the jibberish to a new file +print("File encoded. Please enter a name for this idea: ") +idea_name: gets().strip() +File.open("idea-" + idea_name + '.txt', 'w', file => file.write(idea). ) + + + +# def wipe_mutterings_from( sentence ) +# unless sentence.respond_to? :include? +# raise ArgumentError, +# "cannot wipe mutterings from a #{ sentence.class }" +# end +# while sentence.include? '(' +# open = sentence.index( '(' ) +# close = sentence.index( ')', open ) +# sentence[open..close] = '' if close +# end +# end + +wipe_mutterings_from: sentence => + throw new Error("cannot wipe mutterings") unless sentence.indexOf + while sentence.indexOf('(') >= 0 + open: sentence.indexOf('(') - 1 + close: sentence.indexOf(')') + 1 + sentence: sentence[0, open] + sentence[close, sentence.length]. + sentence. \ No newline at end of file diff --git a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage index 82c83b73..b788c281 100644 --- a/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +++ b/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage @@ -61,7 +61,7 @@ comment match stuff like: a => … match - ([a-zA-Z_?.$]*)\s*(=>) + ([a-zA-Z_?., $]*)\s*(=>) name meta.inline.function.cs diff --git a/lib/coffee_script/lexer.rb b/lib/coffee_script/lexer.rb index 7c351fbe..78208a1c 100644 --- a/lib/coffee_script/lexer.rb +++ b/lib/coffee_script/lexer.rb @@ -20,7 +20,7 @@ module CoffeeScript # Token matching regexes. IDENTIFIER = /\A([a-zA-Z$_]\w*)/ NUMBER = /\A\b((0(x|X)[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?(e[+\-]?[0-9]+)?))\b/i - STRING = /\A("(.*?)[^\\]"|'(.*?)[^\\]')/m + STRING = /\A(""|''|"(.*?)[^\\]"|'(.*?)[^\\]')/m JS = /\A(`(.*?)`)/ OPERATOR = /\A([+\*&|\/\-%=<>]+)/ WHITESPACE = /\A([ \t\r]+)/ diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index a09a5bb9..071324d8 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -300,7 +300,7 @@ module CoffeeScript def compile(indent, scope, opts={}) scope = Scope.new(scope) - @params.each {|id| scope.find(id) } + @params.each {|id| scope.find(id.to_s) } opts = opts.merge(:return => true) code = @body.compile(indent + TAB, scope, opts) "function(#{@params.join(', ')}) {\n#{code}\n#{indent}}"