expressive 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.
- data/.document +5 -0
- data/.gitignore +49 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +57 -0
- data/Guardfile +30 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +20 -0
- data/README.md +29 -0
- data/README.rdoc +19 -0
- data/Rakefile +12 -0
- data/expressive.gemspec +29 -0
- data/lib/expressive.rb +95 -0
- data/lib/expressive/version.rb +3 -0
- data/lib/expressive_grammar.treetop +59 -0
- data/lib/scope.rb +53 -0
- data/spec/expressive_spec.rb +84 -0
- data/spec/spec_helper.rb +14 -0
- metadata +214 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
coverage.data
|
4
|
+
|
5
|
+
# rdoc generated
|
6
|
+
rdoc
|
7
|
+
|
8
|
+
# yard generated
|
9
|
+
doc
|
10
|
+
.yardoc
|
11
|
+
|
12
|
+
# bundler
|
13
|
+
.bundle
|
14
|
+
|
15
|
+
# jeweler generated
|
16
|
+
pkg
|
17
|
+
|
18
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
19
|
+
#
|
20
|
+
# * Create a file at ~/.gitignore
|
21
|
+
# * Include files you want ignored
|
22
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
23
|
+
#
|
24
|
+
# After doing this, these files will be ignored in all your git projects,
|
25
|
+
# saving you from having to 'pollute' every project you touch with them
|
26
|
+
#
|
27
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
28
|
+
#
|
29
|
+
# For MacOS:
|
30
|
+
#
|
31
|
+
#.DS_Store
|
32
|
+
|
33
|
+
# For TextMate
|
34
|
+
#*.tmproj
|
35
|
+
#tmtags
|
36
|
+
|
37
|
+
# For emacs:
|
38
|
+
#*~
|
39
|
+
#\#*
|
40
|
+
#.\#*
|
41
|
+
|
42
|
+
# For vim:
|
43
|
+
#*.swp
|
44
|
+
|
45
|
+
# For redcar:
|
46
|
+
#.redcar
|
47
|
+
|
48
|
+
# For rubinius:
|
49
|
+
#*.rbc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
expressive (0.0.1)
|
5
|
+
awesome_print (~> 1.0.2)
|
6
|
+
polyglot (~> 0.3.3)
|
7
|
+
treetop (~> 1.4.10)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
awesome_print (1.0.2)
|
13
|
+
diff-lcs (1.1.3)
|
14
|
+
ffi (1.1.5)
|
15
|
+
guard (1.3.2)
|
16
|
+
listen (>= 0.4.2)
|
17
|
+
thor (>= 0.14.6)
|
18
|
+
guard-rspec (1.2.1)
|
19
|
+
guard (>= 1.1)
|
20
|
+
json (1.7.4)
|
21
|
+
listen (0.4.7)
|
22
|
+
rb-fchange (~> 0.0.5)
|
23
|
+
rb-fsevent (~> 0.9.1)
|
24
|
+
rb-inotify (~> 0.8.8)
|
25
|
+
polyglot (0.3.3)
|
26
|
+
rb-fchange (0.0.5)
|
27
|
+
ffi
|
28
|
+
rb-fsevent (0.9.1)
|
29
|
+
rb-inotify (0.8.8)
|
30
|
+
ffi (>= 0.5.0)
|
31
|
+
rdoc (3.12)
|
32
|
+
json (~> 1.4)
|
33
|
+
rspec (2.11.0)
|
34
|
+
rspec-core (~> 2.11.0)
|
35
|
+
rspec-expectations (~> 2.11.0)
|
36
|
+
rspec-mocks (~> 2.11.0)
|
37
|
+
rspec-core (2.11.1)
|
38
|
+
rspec-expectations (2.11.2)
|
39
|
+
diff-lcs (~> 1.1.3)
|
40
|
+
rspec-mocks (2.11.2)
|
41
|
+
ruby_gntp (0.3.4)
|
42
|
+
thor (0.16.0)
|
43
|
+
treetop (1.4.10)
|
44
|
+
polyglot
|
45
|
+
polyglot (>= 0.3.1)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
bundler (~> 1.1.4)
|
52
|
+
expressive!
|
53
|
+
guard (~> 1.3.2)
|
54
|
+
guard-rspec (~> 1.2.1)
|
55
|
+
rdoc (~> 3.12)
|
56
|
+
rspec (~> 2.11.0)
|
57
|
+
ruby_gntp (~> 0.3.4)
|
data/Guardfile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'bundler' do
|
5
|
+
watch('Gemfile')
|
6
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
7
|
+
# watch(/^.+\.gemspec/)
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'rspec', :cli => "--color --format nested --fail-fast", :version => 2 do
|
11
|
+
watch(%r{^spec/.+_spec\.rb$})
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch('spec/spec_helper.rb') { "spec" }
|
14
|
+
|
15
|
+
# Rails example
|
16
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
17
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
18
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
19
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
20
|
+
watch('config/routes.rb') { "spec/routing" }
|
21
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
22
|
+
|
23
|
+
# Capybara request specs
|
24
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
25
|
+
|
26
|
+
# Turnip features and steps
|
27
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
28
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
29
|
+
end
|
30
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 EmergeAdapt Ltd.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Ijonas Kisselbach
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Expressive
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'expressive'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install expressive
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= expressive
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to expressive
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Ijonas Kisselbach. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
Bundler::GemHelper.install_tasks
|
data/expressive.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/expressive/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ijonas Kisselbach"]
|
6
|
+
gem.email = ["ijonas@emergeadapt.com"]
|
7
|
+
gem.description = %q{Scheme-like language for manipulating CaseBlocks cases}
|
8
|
+
gem.summary = %q{Scheme-like language for manipulating CaseBlocks cases}
|
9
|
+
|
10
|
+
gem.homepage = "http://github.com/emergeadapt/expressive"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "expressive"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = Expressive::VERSION
|
18
|
+
|
19
|
+
gem.add_development_dependency "ruby_gntp", "~> 0.3.4"
|
20
|
+
gem.add_development_dependency "rspec", "~> 2.11.0"
|
21
|
+
gem.add_development_dependency "rdoc", "~> 3.12"
|
22
|
+
gem.add_development_dependency "bundler", "~> 1.1.4"
|
23
|
+
gem.add_development_dependency "guard", "~> 1.3.2"
|
24
|
+
gem.add_development_dependency "guard-rspec", "~> 1.2.1"
|
25
|
+
|
26
|
+
gem.add_dependency "polyglot", "~> 0.3.3"
|
27
|
+
gem.add_dependency "treetop", "~> 1.4.10"
|
28
|
+
gem.add_dependency "awesome_print", "~> 1.0.2"
|
29
|
+
end
|
data/lib/expressive.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'polyglot'
|
2
|
+
require 'treetop'
|
3
|
+
require 'awesome_print'
|
4
|
+
require File.join(File.dirname(__FILE__), 'scope')
|
5
|
+
|
6
|
+
Treetop.load File.join(File.dirname(__FILE__), 'expressive_grammar.treetop')
|
7
|
+
|
8
|
+
module Expressive
|
9
|
+
def self.run(source_code, scope = TopLevel.new )
|
10
|
+
program = parse(source_code)
|
11
|
+
program.eval(scope)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.parse(expressions)
|
15
|
+
@parser ||= ::ExpressiveParser.new
|
16
|
+
@parser.parse(expressions)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
module Boolean
|
22
|
+
def eval(scope)
|
23
|
+
'true' == text_value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module IntegerValue
|
28
|
+
def eval(scope)
|
29
|
+
text_value.to_i
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module FloatValue
|
34
|
+
def eval(scope)
|
35
|
+
text_value.to_f
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Program < Treetop::Runtime::SyntaxNode
|
40
|
+
def eval(scope)
|
41
|
+
elements.map {|e|
|
42
|
+
e.eval(scope)
|
43
|
+
}.last
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class List < Treetop::Runtime::SyntaxNode
|
48
|
+
def statements
|
49
|
+
elements[1].elements.map {|e| e.data }
|
50
|
+
end
|
51
|
+
|
52
|
+
def eval(scope)
|
53
|
+
function = statements.first.eval(scope)
|
54
|
+
function.call(scope, statements[1..-1])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Statement < Treetop::Runtime::SyntaxNode
|
59
|
+
def data
|
60
|
+
elements[1]
|
61
|
+
end
|
62
|
+
|
63
|
+
def eval(scope)
|
64
|
+
data.eval(scope)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# class SetNode < Treetop::Runtime::SyntaxNode
|
69
|
+
# def pieces
|
70
|
+
# [ :set, fieldname.text_value, value.text_value ]
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
|
74
|
+
class Identifier < Treetop::Runtime::SyntaxNode
|
75
|
+
def eval(scope)
|
76
|
+
scope[text_value]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Function
|
81
|
+
def initialize(&block)
|
82
|
+
@block = block
|
83
|
+
end
|
84
|
+
|
85
|
+
def call(scope, statements)
|
86
|
+
parameters = statements.map {|c| c.eval(scope)}
|
87
|
+
@block.call(*parameters)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class Syntax < Function
|
92
|
+
def call(scope, statements)
|
93
|
+
@block.call(scope, statements)
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
grammar Expressive
|
2
|
+
|
3
|
+
rule program
|
4
|
+
statement* <Program>
|
5
|
+
end
|
6
|
+
|
7
|
+
rule statement
|
8
|
+
whitespace* (list / atom) whitespace* <Statement>
|
9
|
+
end
|
10
|
+
|
11
|
+
rule atom
|
12
|
+
(value / identifier)
|
13
|
+
end
|
14
|
+
|
15
|
+
rule list
|
16
|
+
'(' statement+ ')' <List>
|
17
|
+
end
|
18
|
+
|
19
|
+
rule value
|
20
|
+
(boolean / number)
|
21
|
+
end
|
22
|
+
|
23
|
+
rule word
|
24
|
+
[a-zA-Z]+
|
25
|
+
end
|
26
|
+
|
27
|
+
rule number
|
28
|
+
( float / integer )
|
29
|
+
end
|
30
|
+
|
31
|
+
rule integer
|
32
|
+
[0-9]+ <IntegerValue>
|
33
|
+
end
|
34
|
+
|
35
|
+
rule float
|
36
|
+
[0-9]+ ('.' [0-9]+) <FloatValue>
|
37
|
+
end
|
38
|
+
|
39
|
+
rule whitespace
|
40
|
+
[\n\r\s\t]
|
41
|
+
end
|
42
|
+
|
43
|
+
rule parenthesis
|
44
|
+
[\(\)\[\]]
|
45
|
+
end
|
46
|
+
|
47
|
+
rule boolean
|
48
|
+
('true' / 'false') <Boolean>
|
49
|
+
end
|
50
|
+
|
51
|
+
rule delimeter
|
52
|
+
parenthesis / whitespace
|
53
|
+
end
|
54
|
+
|
55
|
+
rule identifier
|
56
|
+
(!delimeter .)+ <Identifier>
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/lib/scope.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
class Scope
|
2
|
+
def initialize(parent = {})
|
3
|
+
@parent = parent
|
4
|
+
@symbols = {}
|
5
|
+
end
|
6
|
+
|
7
|
+
def [](name)
|
8
|
+
@symbols[name] || @parent[name]
|
9
|
+
end
|
10
|
+
|
11
|
+
def []=(name, value)
|
12
|
+
@symbols[name] = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def merge(scope)
|
16
|
+
@symbols.merge!(scope)
|
17
|
+
end
|
18
|
+
|
19
|
+
def override_scope(scope)
|
20
|
+
scope.merge!(@symbols)
|
21
|
+
@symbols = scope
|
22
|
+
end
|
23
|
+
|
24
|
+
def retrieve_scope
|
25
|
+
@symbols
|
26
|
+
end
|
27
|
+
|
28
|
+
def define(name, &block)
|
29
|
+
self[name] = Function.new(&block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def syntax(name, &block)
|
33
|
+
self[name] = Syntax.new(&block)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
class TopLevel < Scope
|
39
|
+
def initialize
|
40
|
+
super
|
41
|
+
|
42
|
+
syntax('set') do |scope, cells|
|
43
|
+
scope[cells.first.text_value] = cells[1].eval(scope)
|
44
|
+
end
|
45
|
+
|
46
|
+
define('+') {|a,b| a + b }
|
47
|
+
define('-') {|a,b| a - b }
|
48
|
+
define('*') {|a,b| a * b }
|
49
|
+
define('/') {|a,b| a / b }
|
50
|
+
define('=') {|a,b| a == b }
|
51
|
+
define('sum') {|*args| args.flatten.reduce(:+) }
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Expressive" do
|
4
|
+
before(:each) do
|
5
|
+
@scope = TopLevel.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "understands booleans" do
|
9
|
+
it { Expressive.run("true").should eql true }
|
10
|
+
it { Expressive.run("false").should eql false }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "understands numbers" do
|
14
|
+
it { Expressive.run("5").should eql 5 }
|
15
|
+
it { Expressive.run("5.5").should eql 5.5 }
|
16
|
+
end
|
17
|
+
|
18
|
+
it "understands variables" do
|
19
|
+
@scope["hello"] = "World"
|
20
|
+
Expressive.run("hello", @scope).should eql "World"
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "understands arithmetic" do
|
24
|
+
it { Expressive.run("(+ 4 2)").should eql 6 }
|
25
|
+
it { Expressive.run("(- 4 2)").should eql 2 }
|
26
|
+
it { Expressive.run("(* 4 2)").should eql 8 }
|
27
|
+
it { Expressive.run("(/ 4 2)").should eql 2 }
|
28
|
+
it { Expressive.run("(sum 1 2 3)").should eql 6}
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "understands compound statements" do
|
32
|
+
it { Expressive.run("(= (+ 4 2) 6)").should eql true }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "looking up an id based on a value" do
|
36
|
+
it "should use the lookup method, find an id based on value" do
|
37
|
+
#Expressive.run("lookup_case_state 'not_started'", @scope)
|
38
|
+
#@payload[:_].should eql 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when setting simple properties" do
|
43
|
+
it "should set order_no to 1234" do
|
44
|
+
Expressive.run("(set order_no 1234)", @scope).should eql 1234
|
45
|
+
@scope["order_no"].should eql 1234
|
46
|
+
end
|
47
|
+
it "should reuse set properties" do
|
48
|
+
Expressive.run("(set order_no 1234)(+ order_no 11)", @scope).should eql 1245
|
49
|
+
end
|
50
|
+
it "should sum scoped arrays" do
|
51
|
+
@scope["sub_totals"] = [100, 200, 300]
|
52
|
+
Expressive.run("(sum sub_totals)", @scope).should eql 600
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when setting complex properties" do
|
57
|
+
context "e.g. current_state" do
|
58
|
+
before(:each) { Expressive.run("(set current_state (lookup_case_state, 'not started'))", @scope) }
|
59
|
+
it "should set current_state to 'started'"
|
60
|
+
it "should set current_state_id to 2"
|
61
|
+
end
|
62
|
+
context "e.g. owned_by" do
|
63
|
+
it "should set owned_by_id to 1"
|
64
|
+
it "should set owned_by_type to 'CaseBlocks::User'"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when setting multiple properties" do
|
69
|
+
# it {
|
70
|
+
|
71
|
+
# Expressive.apply_to @scope do |scope|
|
72
|
+
# apply "set order_no 1234"
|
73
|
+
# apply "set current_state (lookup case_state 'not started')"
|
74
|
+
# apply "set owned_by (lookup_user_by_email 'ijonas@ijonas.com')"
|
75
|
+
# end
|
76
|
+
# @scope["order_no"].should eql "1234"
|
77
|
+
# }
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
context "register external lookup functions" do
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rspec'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'expressive'
|
metadata
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: expressive
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ijonas Kisselbach
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ruby_gntp
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.4
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.4
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.11.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.11.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.1.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.1.4
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: guard
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.3.2
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.3.2
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: guard-rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.2.1
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.2.1
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: polyglot
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.3.3
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 0.3.3
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: treetop
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 1.4.10
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 1.4.10
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: awesome_print
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ~>
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 1.0.2
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ~>
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 1.0.2
|
158
|
+
description: Scheme-like language for manipulating CaseBlocks cases
|
159
|
+
email:
|
160
|
+
- ijonas@emergeadapt.com
|
161
|
+
executables: []
|
162
|
+
extensions: []
|
163
|
+
extra_rdoc_files: []
|
164
|
+
files:
|
165
|
+
- .document
|
166
|
+
- .gitignore
|
167
|
+
- Gemfile
|
168
|
+
- Gemfile.lock
|
169
|
+
- Guardfile
|
170
|
+
- LICENSE
|
171
|
+
- LICENSE.txt
|
172
|
+
- README.md
|
173
|
+
- README.rdoc
|
174
|
+
- Rakefile
|
175
|
+
- expressive.gemspec
|
176
|
+
- lib/expressive.rb
|
177
|
+
- lib/expressive/version.rb
|
178
|
+
- lib/expressive_grammar.treetop
|
179
|
+
- lib/scope.rb
|
180
|
+
- spec/expressive_spec.rb
|
181
|
+
- spec/spec_helper.rb
|
182
|
+
homepage: http://github.com/emergeadapt/expressive
|
183
|
+
licenses: []
|
184
|
+
post_install_message:
|
185
|
+
rdoc_options: []
|
186
|
+
require_paths:
|
187
|
+
- lib
|
188
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
189
|
+
none: false
|
190
|
+
requirements:
|
191
|
+
- - ! '>='
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
segments:
|
195
|
+
- 0
|
196
|
+
hash: -3389860880342306290
|
197
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
|
+
none: false
|
199
|
+
requirements:
|
200
|
+
- - ! '>='
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
segments:
|
204
|
+
- 0
|
205
|
+
hash: -3389860880342306290
|
206
|
+
requirements: []
|
207
|
+
rubyforge_project:
|
208
|
+
rubygems_version: 1.8.23
|
209
|
+
signing_key:
|
210
|
+
specification_version: 3
|
211
|
+
summary: Scheme-like language for manipulating CaseBlocks cases
|
212
|
+
test_files:
|
213
|
+
- spec/expressive_spec.rb
|
214
|
+
- spec/spec_helper.rb
|