antelope 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rspec +3 -0
  4. data/.yardopts +4 -0
  5. data/Gemfile +7 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +29 -0
  8. data/Rakefile +2 -0
  9. data/antelope.gemspec +30 -0
  10. data/bin/antelope +24 -0
  11. data/examples/deterministic.ace +27 -0
  12. data/examples/deterministic.output +229 -0
  13. data/examples/example.ace +45 -0
  14. data/examples/example.output +610 -0
  15. data/examples/simple.ace +26 -0
  16. data/examples/simple.output +194 -0
  17. data/lib/antelope/ace/compiler.rb +290 -0
  18. data/lib/antelope/ace/errors.rb +27 -0
  19. data/lib/antelope/ace/grammar/generation.rb +47 -0
  20. data/lib/antelope/ace/grammar/loading.rb +51 -0
  21. data/lib/antelope/ace/grammar/presidence.rb +59 -0
  22. data/lib/antelope/ace/grammar/production.rb +47 -0
  23. data/lib/antelope/ace/grammar/productions.rb +119 -0
  24. data/lib/antelope/ace/grammar/terminals.rb +41 -0
  25. data/lib/antelope/ace/grammar.rb +59 -0
  26. data/lib/antelope/ace/presidence.rb +51 -0
  27. data/lib/antelope/ace/scanner/first.rb +61 -0
  28. data/lib/antelope/ace/scanner/second.rb +160 -0
  29. data/lib/antelope/ace/scanner/third.rb +25 -0
  30. data/lib/antelope/ace/scanner.rb +110 -0
  31. data/lib/antelope/ace/token/epsilon.rb +22 -0
  32. data/lib/antelope/ace/token/error.rb +24 -0
  33. data/lib/antelope/ace/token/nonterminal.rb +15 -0
  34. data/lib/antelope/ace/token/terminal.rb +15 -0
  35. data/lib/antelope/ace/token.rb +171 -0
  36. data/lib/antelope/ace.rb +50 -0
  37. data/lib/antelope/automaton.rb +36 -0
  38. data/lib/antelope/generation/conflictor/conflict.rb +7 -0
  39. data/lib/antelope/generation/conflictor.rb +45 -0
  40. data/lib/antelope/generation/constructor/first.rb +52 -0
  41. data/lib/antelope/generation/constructor/follow.rb +46 -0
  42. data/lib/antelope/generation/constructor/lookahead.rb +42 -0
  43. data/lib/antelope/generation/constructor/nullable.rb +40 -0
  44. data/lib/antelope/generation/constructor.rb +81 -0
  45. data/lib/antelope/generation/recognizer/rule.rb +93 -0
  46. data/lib/antelope/generation/recognizer/state.rb +56 -0
  47. data/lib/antelope/generation/recognizer.rb +152 -0
  48. data/lib/antelope/generation/tableizer.rb +80 -0
  49. data/lib/antelope/generation.rb +12 -0
  50. data/lib/antelope/generator/output.rb +30 -0
  51. data/lib/antelope/generator/ruby.rb +57 -0
  52. data/lib/antelope/generator/templates/output.erb +49 -0
  53. data/lib/antelope/generator/templates/ruby.erb +62 -0
  54. data/lib/antelope/generator.rb +84 -0
  55. data/lib/antelope/version.rb +4 -0
  56. data/lib/antelope.rb +9 -0
  57. data/spec/antelope/ace/compiler_spec.rb +50 -0
  58. data/spec/antelope/ace/scanner_spec.rb +27 -0
  59. data/spec/antelope/automaton_spec.rb +29 -0
  60. data/spec/spec_helper.rb +38 -0
  61. data/spec/support/benchmark_helper.rb +5 -0
  62. metadata +223 -0
@@ -0,0 +1,50 @@
1
+ describe Ace::Compiler do
2
+ let :file do
3
+ <<-DOC
4
+ %{
5
+ test
6
+ %}
7
+
8
+ %require "0.0.1"
9
+ %type "ruby"
10
+
11
+ %terminal NUMBER
12
+ %terminal SEMICOLON ";"
13
+ %terminal ADD "+"
14
+ %terminal LPAREN "("
15
+ %terminal RPAREN ")"
16
+
17
+ %%
18
+
19
+ s: e
20
+ e: t ADD e
21
+ t: NUMBER | LPAREN e RPAREN
22
+
23
+ %%
24
+
25
+ hello
26
+ DOC
27
+ end
28
+
29
+ let :tokens do
30
+ Ace::Scanner.scan(file)
31
+ end
32
+
33
+ let :compiler do
34
+ Ace::Compiler.new(tokens)
35
+ end
36
+
37
+ subject do
38
+ compiler.compile
39
+ compiler
40
+ end
41
+
42
+ its(:body) { should =~ /test/ }
43
+ its(:body) { should =~ /hello/ }
44
+ its(:options) { should have_key :type }
45
+
46
+ it "should have the proper terminals" do
47
+ expect(subject.options[:terminals].map(&:first)).to eq [:NUMBER,
48
+ :SEMICOLON, :ADD, :LPAREN, :RPAREN]
49
+ end
50
+ end
@@ -0,0 +1,27 @@
1
+ describe Ace::Scanner do
2
+
3
+ it "properly scans" do
4
+ expect(scan("%test \"a\" hi\n%%\nt: d { { } }\n%%\nhi\n")).to eq [
5
+ [:directive, "test", ["a", "hi"]],
6
+ [:second],
7
+ [:label, "t"],
8
+ [:part, "d"],
9
+ [:block, "{ { } }"],
10
+ [:third],
11
+ [:copy, "\nhi\n"]
12
+ ]
13
+ end
14
+
15
+ it "throws an error" do
16
+ expect {
17
+ scan("% %% %% ")
18
+ }.to raise_error(Ace::SyntaxError)
19
+ end
20
+
21
+ def scan(source)
22
+ Timeout.timeout(5) do
23
+ Ace::Scanner.scan(source)
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,29 @@
1
+ describe Automaton do
2
+ context "with a simple table" do
3
+ let(:states) { [ :s1, :s2 ] }
4
+ let(:alphabet) { [0, 1] }
5
+ let(:accept) { [ :s1 ] }
6
+ let(:transitions) { {
7
+ :s1 => { 0 => :s2, 1 => :s1 },
8
+ :s2 => { 0 => :s1, 1 => :s2 }
9
+ } }
10
+
11
+ subject do
12
+ Automaton.new(states, alphabet, :s1, accept, transitions)
13
+ end
14
+
15
+ it "basically runs" do
16
+ expect(subject.run([1, 1])).to be_truthy
17
+ end
18
+
19
+ it "yields for transitions" do
20
+ expect { |b| subject.run([1], &b) }.to yield_control
21
+ end
22
+
23
+ it "runs fast" do
24
+ expect(benchmark do
25
+ subject.run([1, 1])
26
+ end).to be < 5e-5
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,38 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ Bundler.setup
4
+
5
+ require "timeout"
6
+ require "benchmark"
7
+ require "simplecov"
8
+ require "coveralls"
9
+
10
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
11
+ SimpleCov.start do
12
+ add_filter 'spec'
13
+
14
+ end
15
+
16
+ require "rspec/its"
17
+ require "antelope"
18
+
19
+ include Antelope
20
+
21
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
22
+
23
+ # This file was generated by the `rspec --init` command. Conventionally, all
24
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
25
+ # Require this file using `require "spec_helper"` to ensure that it is only
26
+ # loaded once.
27
+ #
28
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
29
+ RSpec.configure do |config|
30
+ config.run_all_when_everything_filtered = true
31
+
32
+ # Run specs in random order to surface order dependencies. If you find an
33
+ # order dependency and want to debug it, you can fix the order by providing
34
+ # the seed, which is printed after each run.
35
+ # --seed 1234
36
+ config.order = 'random'
37
+ config.include BenchmarkHelper
38
+ end
@@ -0,0 +1,5 @@
1
+ module BenchmarkHelper
2
+ def benchmark
3
+ Benchmark.realtime(&Proc.new)
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: antelope
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Rodi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: liquid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sourcify
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.19'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.19'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
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: rspec
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: rspec-its
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
+ description: A compiler compiler, written in ruby.
126
+ email:
127
+ - redjazz96@gmail.com
128
+ executables:
129
+ - antelope
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".yardopts"
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - antelope.gemspec
141
+ - bin/antelope
142
+ - examples/deterministic.ace
143
+ - examples/deterministic.output
144
+ - examples/example.ace
145
+ - examples/example.output
146
+ - examples/simple.ace
147
+ - examples/simple.output
148
+ - lib/antelope.rb
149
+ - lib/antelope/ace.rb
150
+ - lib/antelope/ace/compiler.rb
151
+ - lib/antelope/ace/errors.rb
152
+ - lib/antelope/ace/grammar.rb
153
+ - lib/antelope/ace/grammar/generation.rb
154
+ - lib/antelope/ace/grammar/loading.rb
155
+ - lib/antelope/ace/grammar/presidence.rb
156
+ - lib/antelope/ace/grammar/production.rb
157
+ - lib/antelope/ace/grammar/productions.rb
158
+ - lib/antelope/ace/grammar/terminals.rb
159
+ - lib/antelope/ace/presidence.rb
160
+ - lib/antelope/ace/scanner.rb
161
+ - lib/antelope/ace/scanner/first.rb
162
+ - lib/antelope/ace/scanner/second.rb
163
+ - lib/antelope/ace/scanner/third.rb
164
+ - lib/antelope/ace/token.rb
165
+ - lib/antelope/ace/token/epsilon.rb
166
+ - lib/antelope/ace/token/error.rb
167
+ - lib/antelope/ace/token/nonterminal.rb
168
+ - lib/antelope/ace/token/terminal.rb
169
+ - lib/antelope/automaton.rb
170
+ - lib/antelope/generation.rb
171
+ - lib/antelope/generation/conflictor.rb
172
+ - lib/antelope/generation/conflictor/conflict.rb
173
+ - lib/antelope/generation/constructor.rb
174
+ - lib/antelope/generation/constructor/first.rb
175
+ - lib/antelope/generation/constructor/follow.rb
176
+ - lib/antelope/generation/constructor/lookahead.rb
177
+ - lib/antelope/generation/constructor/nullable.rb
178
+ - lib/antelope/generation/recognizer.rb
179
+ - lib/antelope/generation/recognizer/rule.rb
180
+ - lib/antelope/generation/recognizer/state.rb
181
+ - lib/antelope/generation/tableizer.rb
182
+ - lib/antelope/generator.rb
183
+ - lib/antelope/generator/output.rb
184
+ - lib/antelope/generator/ruby.rb
185
+ - lib/antelope/generator/templates/output.erb
186
+ - lib/antelope/generator/templates/ruby.erb
187
+ - lib/antelope/version.rb
188
+ - spec/antelope/ace/compiler_spec.rb
189
+ - spec/antelope/ace/scanner_spec.rb
190
+ - spec/antelope/automaton_spec.rb
191
+ - spec/spec_helper.rb
192
+ - spec/support/benchmark_helper.rb
193
+ homepage: https://github.com/medcat/antelope
194
+ licenses:
195
+ - MIT
196
+ metadata: {}
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 2.2.2
214
+ signing_key:
215
+ specification_version: 4
216
+ summary: A compiler compiler, written in ruby.
217
+ test_files:
218
+ - spec/antelope/ace/compiler_spec.rb
219
+ - spec/antelope/ace/scanner_spec.rb
220
+ - spec/antelope/automaton_spec.rb
221
+ - spec/spec_helper.rb
222
+ - spec/support/benchmark_helper.rb
223
+ has_rdoc: