mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-13 16:57:54 -05:00
little fixes more examples
This commit is contained in:
7
Rakefile
7
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'
|
||||
|
||||
@@ -102,4 +102,52 @@ Creature : {
|
||||
puts( "[Your enemy hit with " + enemy_hit + "points of damage!]" )
|
||||
this.hit( enemy_hit )..
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
# # 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.
|
||||
@@ -61,7 +61,7 @@
|
||||
<key>comment</key>
|
||||
<string>match stuff like: a => … </string>
|
||||
<key>match</key>
|
||||
<string>([a-zA-Z_?.$]*)\s*(=>)</string>
|
||||
<string>([a-zA-Z_?., $]*)\s*(=>)</string>
|
||||
<key>name</key>
|
||||
<string>meta.inline.function.cs</string>
|
||||
</dict>
|
||||
|
||||
@@ -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]+)/
|
||||
|
||||
@@ -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}}"
|
||||
|
||||
Reference in New Issue
Block a user