creamerscript 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjE4ZjUwYzQ5ZTI0YjA5MzVmOWMwNjJjMjRjZjRiMGQ1MGZmNGVmMQ==
5
+ data.tar.gz: !binary |-
6
+ NGUxZjA5Nzk1Yjk5MTY4NDRjNmNkYTIxYzU3MTYyNWM5ZjUwN2QzZQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NmJmYTg3YWU3YzEwMjc5NGI2Njk5ZjY0MTg1MTQ5OTg2YTA5Y2Y3OWZhMGYz
10
+ MTZhOGFiZmVkMTIxYzQzMGEwY2FmMGY3M2Y1OTlmNWE3ZjAzYjU2YTRhNGI2
11
+ MmM4ZjkxMTFkZGMwYTZiOWFlNmEzNGIzN2QzMGRkNzkwMGMwY2E=
12
+ data.tar.gz: !binary |-
13
+ YzFmOTZlYmFkMjg3N2JlYzllNjZjNjNhYWMyYzFhZDNiMDE1ODQ0N2UwMTQ5
14
+ MzFiYTFkNTAwNTY2NTEzMmI2MzFkZTEyNTg0ZTcxMjBmMDE3YWIyNjkwMzcw
15
+ NzJhOTQ4NzFiZjFlNGEyMjU4NzBmNzcxY2ZjMzdkOGRmYzY3OTg=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format progress
3
+ --fail-fast
4
+ --debug
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Matte Noble
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # CreamerScript
2
+
3
+ CreamerScript is a language framework on top of Coffeescript.
4
+
5
+ ## Overview
6
+
7
+ CreamerScript itself is really only a Compiler. That Compiler is really
8
+ just a standard way of transforming code.
9
+ [Sweeteners](https://github.com/mnoble/creamerscript-sweeteners) are what actually
10
+ do the heavy lifting.
11
+
12
+ ## Process
13
+
14
+ The compilation process is done in two stages. In the first stage, it
15
+ runs through all registered Sweeteners and tells them to substitute any
16
+ code they will later want to transform with special tokens.
17
+
18
+ Once all chunks of code are replaced with tokens, the Compiler will
19
+ iterate through those tokens, find the Sweetener responsible for it and
20
+ ask it to transform it to Coffeescript. It does this recursively until
21
+ all tokens are replaced with the transformed code.
22
+
23
+ ## Rationale
24
+
25
+ This is very much a poor man's parser approach. There is no AST and
26
+ is therefor not a super robust system. You need to be able to match a
27
+ chunk of code with a regexp in order to use it with CreamerScript.
28
+
29
+ The substitution phase is done depth first, meaning the inner-most
30
+ entities (of nested entities) are substituted first. Strings, Arrays and
31
+ Objects are all substituted first. This gets rid of a lot of the
32
+ headache of dealing with nested entities.
33
+
34
+ ## Example
35
+
36
+ ```coffeescript
37
+ class Gear
38
+ def constructor:chainring cog:cog
39
+ @chainring = chainring
40
+ @cog = cog
41
+
42
+ def gear_inches:diameter
43
+ (this ratio:) / diameter
44
+
45
+ def ratio
46
+ @chainring / (@cog to_f)
47
+
48
+
49
+ class Wheel
50
+ def constructor:rim tire:tire chainring:chainring cog:cog
51
+ @rim = rim
52
+ @tire = tire
53
+ @gear = (Gear new:chainring cog:cog)
54
+
55
+ def diameter
56
+ @rim + (@tire size)
57
+
58
+ def gear_inches
59
+ diameter = (this diameter:)
60
+ (@gear gear_inches:diameter)
61
+ ```
62
+
63
+ ## Usage
64
+
65
+ From the command line:
66
+
67
+ ```
68
+ $ creamer path/to/file.creamer
69
+ ```
70
+
71
+ From Ruby:
72
+
73
+ ```ruby
74
+ require "creamerscript"
75
+ compiler = Creamerscript::Compiler.new("(person say:word)")
76
+ compiler.compile
77
+ # => "person.say(word)"
78
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/creamer ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "creamerscript"
3
+ puts Creamerscript::Compiler.new(File.read(ARGV[0])).compile
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'creamerscript/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "creamerscript"
8
+ spec.version = Creamerscript::VERSION
9
+ spec.authors = ["Matte Noble"]
10
+ spec.email = ["me@mattenoble.com"]
11
+ spec.description = %q{Syntactic sugar framework on top of Coffeescript.}
12
+ spec.summary = %q{Syntactic sugar framework on top of Coffeescript.}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "creamerscript-sweeteners"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "debugger"
26
+ end
27
+
data/example.creamer ADDED
@@ -0,0 +1,24 @@
1
+ class Gear
2
+ def constructor:chainring cog:cog
3
+ @chainring = chainring
4
+ @cog = cog
5
+
6
+ def gear_inches:diameter
7
+ (this ratio:) / diameter
8
+
9
+ def ratio
10
+ @chainring / (@cog to_f)
11
+
12
+
13
+ class Wheel
14
+ def constructor:rim tire:tire chainring:chainring cog:cog
15
+ @rim = rim
16
+ @tire = tire
17
+ @gear = (Gear new:chainring cog:cog)
18
+
19
+ def diameter
20
+ @rim + (@tire size)
21
+
22
+ def gear_inches
23
+ diameter = (this diameter:)
24
+ (@gear gear_inches:diameter)
@@ -0,0 +1,52 @@
1
+ module Creamerscript
2
+ # Compiles CreamerScript code to Coffeescript.
3
+ #
4
+ # The Compiler itself doesn't really do much. It's just a
5
+ # structured way of parsing code and then transforming it
6
+ # into Coffeescript.
7
+ #
8
+ # Sweeteners are the real workers of CreamerScript. Take a
9
+ # look at the the creamerscript-sweeteners project for more
10
+ # info.
11
+ #
12
+ # @example
13
+ #
14
+ # compiler = Creamerscript::Compiler.new "(person say:'Hello')"
15
+ # compiler.compile
16
+ # # => "person.say("hello")
17
+ #
18
+ class Compiler
19
+ attr_accessor :source
20
+
21
+ def initialize(source)
22
+ @source = source.dup
23
+ end
24
+
25
+ def compile
26
+ substitute
27
+ source.tap { transform(source) }
28
+ end
29
+
30
+ def substitute
31
+ Sweeteners.each do |sweetener|
32
+ sweetener.substitute(source) while source =~ sweetener.pattern
33
+ end
34
+ end
35
+
36
+ def transform(source)
37
+ source.gsub!(pattern) do |sub|
38
+ sweetener = Sweeteners.for($1.downcase.to_sym)
39
+ sweetener.call($2.to_i)
40
+
41
+ result = sweetener.to_coffee
42
+ result = transform(result) if result =~ pattern
43
+ result
44
+ end
45
+ end
46
+
47
+ def pattern
48
+ /_____CREAMER_([A-Z_]+)_(\d+)_____/
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,3 @@
1
+ module Creamerscript
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "creamerscript/compiler"
2
+ require "creamerscript/sweeteners/default"
3
+
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe Creamerscript::Compiler do
4
+ it "transforms all substitutions" do
5
+ source = %{
6
+ def foo:bar baz:zap
7
+ (this bar:baz beep:{a:1})
8
+ (this alert:"MOG")
9
+ return (_ all:[true], (this all_iter), this)
10
+
11
+ def zap
12
+ a = (1 + 1)
13
+ (console log:a)
14
+ (connection send_async_request:(Request new:)
15
+ queue:"main_queue"
16
+ completion_handler:(this complete))
17
+ }
18
+
19
+ Creamerscript::Compiler.new(source).compile.should == %{
20
+ foo_baz: (bar, zap) =>
21
+ this.bar_beep(baz, {a:1})
22
+ this.alert("MOG")
23
+ return _.all([true], this.all_iter, this)
24
+
25
+ zap: =>
26
+ a = (1 + 1)
27
+ console.log(a)
28
+ connection.send_async_request_queue_completion_handler(new Request(), "main_queue", this.complete)
29
+ }
30
+ end
31
+ end
32
+
@@ -0,0 +1,9 @@
1
+ require "debugger"
2
+ require "creamerscript"
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+ config.order = 'random'
9
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: creamerscript
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matte Noble
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: creamerscript-sweeteners
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: debugger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Syntactic sugar framework on top of Coffeescript.
84
+ email:
85
+ - me@mattenoble.com
86
+ executables:
87
+ - creamer
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/creamer
98
+ - creamerscript.gemspec
99
+ - example.creamer
100
+ - lib/creamerscript.rb
101
+ - lib/creamerscript/compiler.rb
102
+ - lib/creamerscript/version.rb
103
+ - spec/creamerscript/compiler_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage:
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.0.0
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Syntactic sugar framework on top of Coffeescript.
129
+ test_files:
130
+ - spec/creamerscript/compiler_spec.rb
131
+ - spec/spec_helper.rb