gary 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +144 -0
- data/Guardfile +16 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +13 -0
- data/Rakefile +26 -0
- data/VERSION +1 -0
- data/bin/gary +7 -0
- data/example/fizzbuzz.gary +25 -0
- data/example/polish_calculator.gary +13 -0
- data/example/polish_calculator/leaf.gary +13 -0
- data/example/polish_calculator/node.gary +38 -0
- data/example/what_to_do.gary +13 -0
- data/gary.gemspec +94 -0
- data/lib/gary.rb +2 -0
- data/lib/gary/backus_naur_form.rb +16 -0
- data/lib/gary/parser.rb +37 -0
- data/lib/gary/rules.rb +13 -0
- data/lib/gary/runner.rb +29 -0
- data/spec/lib/gary/parser_spec.rb +81 -0
- data/spec/spec_helper.rb +10 -0
- metadata +223 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75f0e5c3bfe60ba4abfe60c05bac196d7dc6ad67
|
4
|
+
data.tar.gz: bc3011b69815fc014e2c98bfe862c904f208aa66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e372dac3958608ab6a44f7e15eccd19eba50b26a221c5c6f87bad46ed943a69b4e0ce629ce720ed5addef2c707b956404897f8db79503f761dbf404d43d0f791
|
7
|
+
data.tar.gz: 2fa831bce04a02fda96ba78a8ae72257a915ead868e56292cf045a20bf8e5ac17a795ffebbe4e337bf50785a072c8832ce8df70434e24cd3fb09f2d4b59a9eef
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "thor"
|
4
|
+
gem "rake"
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem "pry"
|
8
|
+
gem "rspec"
|
9
|
+
gem "guard-rspec"
|
10
|
+
gem "terminal-notifier"
|
11
|
+
gem "terminal-notifier-guard"
|
12
|
+
gem "shoulda", ">= 0"
|
13
|
+
gem "bundler", "~> 1.0"
|
14
|
+
gem "jeweler", "~> 2.0.1"
|
15
|
+
gem "simplecov", ">= 0"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (4.2.1)
|
5
|
+
i18n (~> 0.7)
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
9
|
+
tzinfo (~> 1.1)
|
10
|
+
addressable (2.3.7)
|
11
|
+
builder (3.2.2)
|
12
|
+
celluloid (0.16.0)
|
13
|
+
timers (~> 4.0.0)
|
14
|
+
coderay (1.1.0)
|
15
|
+
descendants_tracker (0.0.4)
|
16
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
17
|
+
diff-lcs (1.2.5)
|
18
|
+
docile (1.1.5)
|
19
|
+
faraday (0.9.1)
|
20
|
+
multipart-post (>= 1.2, < 3)
|
21
|
+
ffi (1.9.8)
|
22
|
+
formatador (0.2.5)
|
23
|
+
git (1.2.9.1)
|
24
|
+
github_api (0.12.3)
|
25
|
+
addressable (~> 2.3)
|
26
|
+
descendants_tracker (~> 0.0.4)
|
27
|
+
faraday (~> 0.8, < 0.10)
|
28
|
+
hashie (>= 3.3)
|
29
|
+
multi_json (>= 1.7.5, < 2.0)
|
30
|
+
nokogiri (~> 1.6.3)
|
31
|
+
oauth2
|
32
|
+
guard (2.12.5)
|
33
|
+
formatador (>= 0.2.4)
|
34
|
+
listen (~> 2.7)
|
35
|
+
lumberjack (~> 1.0)
|
36
|
+
nenv (~> 0.1)
|
37
|
+
notiffany (~> 0.0)
|
38
|
+
pry (>= 0.9.12)
|
39
|
+
shellany (~> 0.0)
|
40
|
+
thor (>= 0.18.1)
|
41
|
+
guard-compat (1.2.1)
|
42
|
+
guard-rspec (4.5.0)
|
43
|
+
guard (~> 2.1)
|
44
|
+
guard-compat (~> 1.1)
|
45
|
+
rspec (>= 2.99.0, < 4.0)
|
46
|
+
hashie (3.4.0)
|
47
|
+
highline (1.7.1)
|
48
|
+
hitimes (1.2.2)
|
49
|
+
i18n (0.7.0)
|
50
|
+
jeweler (2.0.1)
|
51
|
+
builder
|
52
|
+
bundler (>= 1.0)
|
53
|
+
git (>= 1.2.5)
|
54
|
+
github_api
|
55
|
+
highline (>= 1.6.15)
|
56
|
+
nokogiri (>= 1.5.10)
|
57
|
+
rake
|
58
|
+
rdoc
|
59
|
+
json (1.8.2)
|
60
|
+
jwt (1.4.1)
|
61
|
+
listen (2.9.0)
|
62
|
+
celluloid (>= 0.15.2)
|
63
|
+
rb-fsevent (>= 0.9.3)
|
64
|
+
rb-inotify (>= 0.9)
|
65
|
+
lumberjack (1.0.9)
|
66
|
+
method_source (0.8.2)
|
67
|
+
mini_portile (0.6.2)
|
68
|
+
minitest (5.5.1)
|
69
|
+
multi_json (1.11.0)
|
70
|
+
multi_xml (0.5.5)
|
71
|
+
multipart-post (2.0.0)
|
72
|
+
nenv (0.2.0)
|
73
|
+
nokogiri (1.6.6.2)
|
74
|
+
mini_portile (~> 0.6.0)
|
75
|
+
notiffany (0.0.6)
|
76
|
+
nenv (~> 0.1)
|
77
|
+
shellany (~> 0.0)
|
78
|
+
oauth2 (1.0.0)
|
79
|
+
faraday (>= 0.8, < 0.10)
|
80
|
+
jwt (~> 1.0)
|
81
|
+
multi_json (~> 1.3)
|
82
|
+
multi_xml (~> 0.5)
|
83
|
+
rack (~> 1.2)
|
84
|
+
pry (0.10.1)
|
85
|
+
coderay (~> 1.1.0)
|
86
|
+
method_source (~> 0.8.1)
|
87
|
+
slop (~> 3.4)
|
88
|
+
rack (1.6.0)
|
89
|
+
rake (10.4.2)
|
90
|
+
rb-fsevent (0.9.4)
|
91
|
+
rb-inotify (0.9.5)
|
92
|
+
ffi (>= 0.5.0)
|
93
|
+
rdoc (3.12.2)
|
94
|
+
json (~> 1.4)
|
95
|
+
rspec (3.2.0)
|
96
|
+
rspec-core (~> 3.2.0)
|
97
|
+
rspec-expectations (~> 3.2.0)
|
98
|
+
rspec-mocks (~> 3.2.0)
|
99
|
+
rspec-core (3.2.2)
|
100
|
+
rspec-support (~> 3.2.0)
|
101
|
+
rspec-expectations (3.2.0)
|
102
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
103
|
+
rspec-support (~> 3.2.0)
|
104
|
+
rspec-mocks (3.2.1)
|
105
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
106
|
+
rspec-support (~> 3.2.0)
|
107
|
+
rspec-support (3.2.2)
|
108
|
+
shellany (0.0.1)
|
109
|
+
shoulda (3.5.0)
|
110
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
111
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
112
|
+
shoulda-context (1.2.1)
|
113
|
+
shoulda-matchers (2.8.0)
|
114
|
+
activesupport (>= 3.0.0)
|
115
|
+
simplecov (0.9.2)
|
116
|
+
docile (~> 1.1.0)
|
117
|
+
multi_json (~> 1.0)
|
118
|
+
simplecov-html (~> 0.9.0)
|
119
|
+
simplecov-html (0.9.0)
|
120
|
+
slop (3.6.0)
|
121
|
+
terminal-notifier (1.6.2)
|
122
|
+
terminal-notifier-guard (1.6.4)
|
123
|
+
thor (0.19.1)
|
124
|
+
thread_safe (0.3.5)
|
125
|
+
timers (4.0.1)
|
126
|
+
hitimes
|
127
|
+
tzinfo (1.2.2)
|
128
|
+
thread_safe (~> 0.1)
|
129
|
+
|
130
|
+
PLATFORMS
|
131
|
+
ruby
|
132
|
+
|
133
|
+
DEPENDENCIES
|
134
|
+
bundler (~> 1.0)
|
135
|
+
guard-rspec
|
136
|
+
jeweler (~> 2.0.1)
|
137
|
+
pry
|
138
|
+
rake
|
139
|
+
rspec
|
140
|
+
shoulda
|
141
|
+
simplecov
|
142
|
+
terminal-notifier
|
143
|
+
terminal-notifier-guard
|
144
|
+
thor
|
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
2
|
+
require "guard/rspec/dsl"
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
# Feel free to open issues for suggestions and improvements
|
6
|
+
|
7
|
+
# RSpec files
|
8
|
+
rspec = dsl.rspec
|
9
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
10
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
11
|
+
watch(rspec.spec_files)
|
12
|
+
|
13
|
+
# Ruby files
|
14
|
+
ruby = dsl.ruby
|
15
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Brett Cassette
|
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.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
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
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
gem.name = "gary"
|
17
|
+
gem.homepage = "http://github.com/brettshollenberger/garylang"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %Q{Garylang interpreter}
|
20
|
+
gem.description = %Q{The Garylang interpreter executes Garylang programs. What to do?}
|
21
|
+
gem.email = "brettcassette@gmail.com"
|
22
|
+
gem.authors = ["Brett Cassette"]
|
23
|
+
gem.executables = %w(gary)
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/gary
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
class Fizzbuzz
|
2
|
+
yeahmung fizz?(n)
|
3
|
+
n % 3 == 0
|
4
|
+
fineto
|
5
|
+
|
6
|
+
yeahmung buzz?(n)
|
7
|
+
n % 5 == 0
|
8
|
+
fineto
|
9
|
+
|
10
|
+
yeahmung go!
|
11
|
+
(1..100).to_a.each what2do |n|
|
12
|
+
ifinfact fizz?(n) && buzz?(n)
|
13
|
+
ooooh "fizzbuzz"
|
14
|
+
elsif fizz?(n)
|
15
|
+
ooooh "fizz"
|
16
|
+
elsif buzz?(n)
|
17
|
+
ooooh "buzz"
|
18
|
+
else
|
19
|
+
ooooh n
|
20
|
+
fineto
|
21
|
+
fineto
|
22
|
+
fineto
|
23
|
+
fineto
|
24
|
+
|
25
|
+
Fizzbuzz.new.go!
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class PolishCalculator
|
2
|
+
class Node
|
3
|
+
attr_accessor :root, :left, :right
|
4
|
+
|
5
|
+
yeahmung initialize(args)
|
6
|
+
@root = args.pop
|
7
|
+
|
8
|
+
%w(left right).each what2do |leaf|
|
9
|
+
ifinfact is_operator?(args[-1])
|
10
|
+
instance_variable_set("@#{leaf}", Node.new(args))
|
11
|
+
else
|
12
|
+
instance_variable_set("@#{leaf}", Leaf.new(args.pop.to_i))
|
13
|
+
fineto
|
14
|
+
fineto
|
15
|
+
fineto
|
16
|
+
|
17
|
+
yeahmung reduce
|
18
|
+
l = left.reducible? ? left.reduce : left.root
|
19
|
+
r = right.reducible? ? right.reduce : right.root
|
20
|
+
op = root
|
21
|
+
|
22
|
+
l.send(op, r)
|
23
|
+
fineto
|
24
|
+
|
25
|
+
yeahmung reducible?
|
26
|
+
true
|
27
|
+
fineto
|
28
|
+
|
29
|
+
private
|
30
|
+
yeahmung supported_operators
|
31
|
+
%w(* + - /)
|
32
|
+
fineto
|
33
|
+
|
34
|
+
yeahmung is_operator?(arg)
|
35
|
+
supported_operators.include?(arg)
|
36
|
+
fineto
|
37
|
+
fineto
|
38
|
+
fineto
|
data/gary.gemspec
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: gary 0.1.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "gary"
|
9
|
+
s.version = "0.1.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Brett Cassette"]
|
14
|
+
s.date = "2015-03-26"
|
15
|
+
s.description = "The Garylang interpreter executes Garylang programs. What to do?"
|
16
|
+
s.email = "brettcassette@gmail.com"
|
17
|
+
s.executables = ["gary"]
|
18
|
+
s.extra_rdoc_files = [
|
19
|
+
"LICENSE.txt",
|
20
|
+
"README.rdoc"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".document",
|
24
|
+
".rspec",
|
25
|
+
"Gemfile",
|
26
|
+
"Gemfile.lock",
|
27
|
+
"Guardfile",
|
28
|
+
"LICENSE.txt",
|
29
|
+
"README.rdoc",
|
30
|
+
"Rakefile",
|
31
|
+
"VERSION",
|
32
|
+
"bin/gary",
|
33
|
+
"example/fizzbuzz.gary",
|
34
|
+
"example/polish_calculator.gary",
|
35
|
+
"example/polish_calculator/leaf.gary",
|
36
|
+
"example/polish_calculator/node.gary",
|
37
|
+
"example/what_to_do.gary",
|
38
|
+
"gary.gemspec",
|
39
|
+
"lib/gary.rb",
|
40
|
+
"lib/gary/backus_naur_form.rb",
|
41
|
+
"lib/gary/parser.rb",
|
42
|
+
"lib/gary/rules.rb",
|
43
|
+
"lib/gary/runner.rb",
|
44
|
+
"spec/lib/gary/parser_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
s.homepage = "http://github.com/brettshollenberger/garylang"
|
48
|
+
s.licenses = ["MIT"]
|
49
|
+
s.rubygems_version = "2.4.5"
|
50
|
+
s.summary = "Garylang interpreter"
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
s.specification_version = 4
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<thor>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<pry>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<guard-rspec>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<terminal-notifier>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<terminal-notifier-guard>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
65
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
66
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
70
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
71
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
72
|
+
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
73
|
+
s.add_dependency(%q<terminal-notifier>, [">= 0"])
|
74
|
+
s.add_dependency(%q<terminal-notifier-guard>, [">= 0"])
|
75
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
76
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
77
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
78
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
79
|
+
end
|
80
|
+
else
|
81
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
82
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
83
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
84
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
85
|
+
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
86
|
+
s.add_dependency(%q<terminal-notifier>, [">= 0"])
|
87
|
+
s.add_dependency(%q<terminal-notifier-guard>, [">= 0"])
|
88
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
89
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
90
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
91
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
data/lib/gary.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Gary
|
2
|
+
module BackusNaurForm
|
3
|
+
def self.included(klass)
|
4
|
+
klass.send(:extend, ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
attr_accessor :rules
|
9
|
+
|
10
|
+
def rule(matcher, replacement)
|
11
|
+
@rules ||= []
|
12
|
+
@rules.push({matcher: matcher, replacement: replacement})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/gary/parser.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Gary
|
2
|
+
class Parser
|
3
|
+
class << self
|
4
|
+
def parse(string)
|
5
|
+
new(string).parse
|
6
|
+
end
|
7
|
+
|
8
|
+
def tokenize(string)
|
9
|
+
new(string).tokenize
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :string, :tokens
|
14
|
+
|
15
|
+
def initialize(string)
|
16
|
+
@string = string
|
17
|
+
end
|
18
|
+
|
19
|
+
def tokenize
|
20
|
+
@tokens ||= @string.split("\n").flat_map do |line|
|
21
|
+
line.scan(/[\w|'|"|\.|\<|\>|\=|\!|\?|\)|\(|\&|\%]+/) << "\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse
|
26
|
+
tokenize.map do |token|
|
27
|
+
Gary::Rules.rules.inject(token) do |token, rule|
|
28
|
+
if token.match(rule[:matcher])
|
29
|
+
rule[:replacement]
|
30
|
+
else
|
31
|
+
token
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/gary/rules.rb
ADDED
data/lib/gary/runner.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "rake"
|
3
|
+
|
4
|
+
module Gary
|
5
|
+
class Runner
|
6
|
+
include Thor::Base
|
7
|
+
include Thor::Actions
|
8
|
+
include Rake::DSL
|
9
|
+
|
10
|
+
source_root Dir.pwd
|
11
|
+
|
12
|
+
def run(file)
|
13
|
+
src = File.read(file)
|
14
|
+
file = file.gsub(/gary/) { "rb" }
|
15
|
+
|
16
|
+
create_file file
|
17
|
+
append_to_file file, Parser.parse(src).join(" ")
|
18
|
+
|
19
|
+
verbose(false) do
|
20
|
+
begin
|
21
|
+
sh "ruby #{file}"
|
22
|
+
rescue
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
remove_file file
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Gary::Parser do
|
4
|
+
it "tokenizes" do
|
5
|
+
example = <<-EX
|
6
|
+
hello world what's up
|
7
|
+
"i am a string"
|
8
|
+
EX
|
9
|
+
|
10
|
+
expect(Gary::Parser.tokenize(example)).to eq [
|
11
|
+
"hello",
|
12
|
+
"world",
|
13
|
+
"what's",
|
14
|
+
"up",
|
15
|
+
"\n",
|
16
|
+
"\"i",
|
17
|
+
"am",
|
18
|
+
"a",
|
19
|
+
"string\"",
|
20
|
+
"\n"
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "transforms tokens into ruby program" do
|
25
|
+
example = <<-GARY
|
26
|
+
boomz "ostruct"
|
27
|
+
|
28
|
+
yeahmung parse_number(n)
|
29
|
+
ifinfact n < 10
|
30
|
+
ooooh n
|
31
|
+
else
|
32
|
+
cantdomuch "What to do?"
|
33
|
+
fineto
|
34
|
+
fineto
|
35
|
+
|
36
|
+
20.times what2do |n|
|
37
|
+
parse_number(n)
|
38
|
+
fineto
|
39
|
+
GARY
|
40
|
+
|
41
|
+
expect(Gary::Parser.parse(example)).to eq [
|
42
|
+
"require",
|
43
|
+
"\"ostruct\"",
|
44
|
+
"\n",
|
45
|
+
"\n",
|
46
|
+
"def",
|
47
|
+
"parse_number",
|
48
|
+
"n",
|
49
|
+
"\n",
|
50
|
+
"if",
|
51
|
+
"n",
|
52
|
+
"<",
|
53
|
+
"10",
|
54
|
+
"\n",
|
55
|
+
"puts",
|
56
|
+
"n",
|
57
|
+
"\n",
|
58
|
+
"else",
|
59
|
+
"\n",
|
60
|
+
"raise",
|
61
|
+
"\"What",
|
62
|
+
"to",
|
63
|
+
"do?\"",
|
64
|
+
"\n",
|
65
|
+
"end",
|
66
|
+
"\n",
|
67
|
+
"end",
|
68
|
+
"\n",
|
69
|
+
"\n",
|
70
|
+
"20.times",
|
71
|
+
"do",
|
72
|
+
"|n|",
|
73
|
+
"\n",
|
74
|
+
"parse_number",
|
75
|
+
"n",
|
76
|
+
"\n",
|
77
|
+
"end",
|
78
|
+
"\n"
|
79
|
+
]
|
80
|
+
end
|
81
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "bundler"
|
2
|
+
|
3
|
+
Bundler.require(:development)
|
4
|
+
|
5
|
+
Dir[File.expand_path(File.join(__FILE__, "../../lib/**/*.rb"))].each { |f| require f }
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.filter_run focus: true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brett Cassette
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
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: guard-rspec
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: terminal-notifier
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: terminal-notifier-guard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: shoulda
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: bundler
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: jeweler
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 2.0.1
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 2.0.1
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: The Garylang interpreter executes Garylang programs. What to do?
|
168
|
+
email: brettcassette@gmail.com
|
169
|
+
executables:
|
170
|
+
- gary
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files:
|
173
|
+
- LICENSE.txt
|
174
|
+
- README.rdoc
|
175
|
+
files:
|
176
|
+
- .document
|
177
|
+
- .rspec
|
178
|
+
- Gemfile
|
179
|
+
- Gemfile.lock
|
180
|
+
- Guardfile
|
181
|
+
- LICENSE.txt
|
182
|
+
- README.rdoc
|
183
|
+
- Rakefile
|
184
|
+
- VERSION
|
185
|
+
- bin/gary
|
186
|
+
- example/fizzbuzz.gary
|
187
|
+
- example/polish_calculator.gary
|
188
|
+
- example/polish_calculator/leaf.gary
|
189
|
+
- example/polish_calculator/node.gary
|
190
|
+
- example/what_to_do.gary
|
191
|
+
- gary.gemspec
|
192
|
+
- lib/gary.rb
|
193
|
+
- lib/gary/backus_naur_form.rb
|
194
|
+
- lib/gary/parser.rb
|
195
|
+
- lib/gary/rules.rb
|
196
|
+
- lib/gary/runner.rb
|
197
|
+
- spec/lib/gary/parser_spec.rb
|
198
|
+
- spec/spec_helper.rb
|
199
|
+
homepage: http://github.com/brettshollenberger/garylang
|
200
|
+
licenses:
|
201
|
+
- MIT
|
202
|
+
metadata: {}
|
203
|
+
post_install_message:
|
204
|
+
rdoc_options: []
|
205
|
+
require_paths:
|
206
|
+
- lib
|
207
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - '>='
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - '>='
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
217
|
+
requirements: []
|
218
|
+
rubyforge_project:
|
219
|
+
rubygems_version: 2.4.5
|
220
|
+
signing_key:
|
221
|
+
specification_version: 4
|
222
|
+
summary: Garylang interpreter
|
223
|
+
test_files: []
|