crapshoot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "shoulda", ">= 0"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.5.2"
9
+ gem "rcov", ">= 0"
10
+ gem 'guard-test', '~> 0.1.4'
11
+ gem 'treetop', '~> 1.4.9'
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ crapshoot (0.0.0)
5
+ activesupport (~> 3.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activesupport (3.0.3)
11
+ configuration (1.2.0)
12
+ git (1.2.5)
13
+ guard (0.2.2)
14
+ open_gem (~> 1.4.2)
15
+ thor (~> 0.14.3)
16
+ guard-test (0.1.4)
17
+ guard (>= 0.2.2)
18
+ test-unit (~> 2.1)
19
+ jeweler (1.5.2)
20
+ bundler (~> 1.0.0)
21
+ git (>= 1.2.5)
22
+ rake
23
+ launchy (0.3.7)
24
+ configuration (>= 0.0.5)
25
+ rake (>= 0.8.1)
26
+ open_gem (1.4.2)
27
+ launchy (~> 0.3.5)
28
+ polyglot (0.3.1)
29
+ rake (0.8.7)
30
+ rcov (0.9.9)
31
+ shoulda (2.11.3)
32
+ test-unit (2.1.2)
33
+ thor (0.14.6)
34
+ treetop (1.4.9)
35
+ polyglot (>= 0.3.1)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ activesupport (~> 3.0)
42
+ bundler (~> 1.0.0)
43
+ crapshoot!
44
+ guard-test (~> 0.1.4)
45
+ jeweler (~> 1.5.2)
46
+ rcov
47
+ shoulda
48
+ treetop (~> 1.4.9)
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard 'test', :runner => 'fastfail' do
2
+ watch('^lib/(.*)\.rb') { |m| "test/test_#{m[1]}.rb" }
3
+ watch('^lib/crapshoot/(.*)\.rb') { |m| 'test/test_#{m[1]}.rb'}
4
+ watch('^test/(.*)_test.rb') { 'rake test' }
5
+ watch('^test/test_helper.rb') { 'rake test' }
6
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Bryce Kerley
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
@@ -0,0 +1,19 @@
1
+ = crapshoot
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to crapshoot
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) 2010 Bryce Kerley. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,77 @@
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 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "crapshoot"
16
+ gem.homepage = "http://github.com/bkerley/crapshoot"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{The alpha and omega of rolling dice}
19
+ gem.description = %Q{Crapshoot is a dice-rolling gem that parses complicated notation for most of your pen-and-paper gaming needs.}
20
+ gem.email = "bkerley@brycekerley.net"
21
+ gem.authors = ["Bryce Kerley"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'activesupport', '~> 3.0'
25
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
26
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ task :test => :scanner
38
+
39
+ desc 'Generate the Ragel scanner'
40
+ task :scanner => 'lib/crapshoot/parser/scan.rb'
41
+
42
+ file 'lib/crapshoot/parser/scan.rb' => ['lib/crapshoot/parser/scan.rl'] do |t|
43
+ sh "ragel -R -F1 -o #{t.name} #{t.prerequisites.first}"
44
+ end
45
+
46
+ namespace :scanner do
47
+ desc 'Generate a PDF graph of the Ragel scanner'
48
+ task :pdf => 'doc/scan.pdf'
49
+ file 'doc/scan.pdf' => ['doc/scan.dot', 'doc'] do |t|
50
+ sh "dot -Tpdf -o #{t.name} #{t.prerequisites.first}"
51
+ end
52
+
53
+ file 'doc/scan.dot' => ['lib/crapshoot/parser/scan.rl', 'doc'] do |t|
54
+ sh "ragel -Vp -o #{t.name} #{t.prerequisites.first}"
55
+ end
56
+ end
57
+
58
+ directory 'doc'
59
+
60
+ require 'rcov/rcovtask'
61
+ Rcov::RcovTask.new do |test|
62
+ test.libs << 'test'
63
+ test.pattern = 'test/**/test_*.rb'
64
+ test.verbose = true
65
+ end
66
+
67
+ task :default => :test
68
+
69
+ require 'rake/rdoctask'
70
+ Rake::RDocTask.new do |rdoc|
71
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
72
+
73
+ rdoc.rdoc_dir = 'rdoc'
74
+ rdoc.title = "crapshoot #{version}"
75
+ rdoc.rdoc_files.include('README*')
76
+ rdoc.rdoc_files.include('lib/**/*.rb')
77
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/crapshoot.gemspec ADDED
@@ -0,0 +1,113 @@
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
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{crapshoot}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Bryce Kerley"]
12
+ s.date = %q{2010-12-28}
13
+ s.description = %q{Crapshoot is a dice-rolling gem that parses complicated notation for most of your pen-and-paper gaming needs.}
14
+ s.email = %q{bkerley@brycekerley.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "Guardfile",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "crapshoot.gemspec",
29
+ "lib/crapshoot.rb",
30
+ "lib/crapshoot/evaluator.rb",
31
+ "lib/crapshoot/parser/scan.rb",
32
+ "lib/crapshoot/parser/scan.rl",
33
+ "lib/crapshoot/postfixer.rb",
34
+ "lib/crapshoot/scanner.rb",
35
+ "lib/crapshoot/tokens/arithmetic.rb",
36
+ "lib/crapshoot/tokens/base.rb",
37
+ "lib/crapshoot/tokens/constant.rb",
38
+ "lib/crapshoot/tokens/series.rb",
39
+ "test/helper.rb",
40
+ "test/test_crapshoot.rb",
41
+ "test/test_evaluator.rb",
42
+ "test/test_postfixer.rb",
43
+ "test/test_scanner.rb"
44
+ ]
45
+ s.homepage = %q{http://github.com/bkerley/crapshoot}
46
+ s.licenses = ["MIT"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = %q{1.3.7}
49
+ s.summary = %q{The alpha and omega of rolling dice}
50
+ s.test_files = [
51
+ "test/helper.rb",
52
+ "test/test_crapshoot.rb",
53
+ "test/test_evaluator.rb",
54
+ "test/test_postfixer.rb",
55
+ "test/test_scanner.rb"
56
+ ]
57
+
58
+ if s.respond_to? :specification_version then
59
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
60
+ s.specification_version = 3
61
+
62
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
+ s.add_runtime_dependency(%q<crapshoot>, [">= 0"])
64
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
65
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
66
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
68
+ s.add_development_dependency(%q<rcov>, [">= 0"])
69
+ s.add_development_dependency(%q<guard-test>, ["~> 0.1.4"])
70
+ s.add_development_dependency(%q<treetop>, ["~> 1.4.9"])
71
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
72
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
73
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
74
+ s.add_development_dependency(%q<rcov>, [">= 0"])
75
+ s.add_development_dependency(%q<guard-test>, ["~> 0.1.4"])
76
+ s.add_development_dependency(%q<treetop>, ["~> 1.4.9"])
77
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
78
+ else
79
+ s.add_dependency(%q<crapshoot>, [">= 0"])
80
+ s.add_dependency(%q<activesupport>, ["~> 3.0"])
81
+ s.add_dependency(%q<shoulda>, [">= 0"])
82
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
83
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
84
+ s.add_dependency(%q<rcov>, [">= 0"])
85
+ s.add_dependency(%q<guard-test>, ["~> 0.1.4"])
86
+ s.add_dependency(%q<treetop>, ["~> 1.4.9"])
87
+ s.add_dependency(%q<shoulda>, [">= 0"])
88
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
89
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
90
+ s.add_dependency(%q<rcov>, [">= 0"])
91
+ s.add_dependency(%q<guard-test>, ["~> 0.1.4"])
92
+ s.add_dependency(%q<treetop>, ["~> 1.4.9"])
93
+ s.add_dependency(%q<activesupport>, ["~> 3.0"])
94
+ end
95
+ else
96
+ s.add_dependency(%q<crapshoot>, [">= 0"])
97
+ s.add_dependency(%q<activesupport>, ["~> 3.0"])
98
+ s.add_dependency(%q<shoulda>, [">= 0"])
99
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
100
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
101
+ s.add_dependency(%q<rcov>, [">= 0"])
102
+ s.add_dependency(%q<guard-test>, ["~> 0.1.4"])
103
+ s.add_dependency(%q<treetop>, ["~> 1.4.9"])
104
+ s.add_dependency(%q<shoulda>, [">= 0"])
105
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
106
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
107
+ s.add_dependency(%q<rcov>, [">= 0"])
108
+ s.add_dependency(%q<guard-test>, ["~> 0.1.4"])
109
+ s.add_dependency(%q<treetop>, ["~> 1.4.9"])
110
+ s.add_dependency(%q<activesupport>, ["~> 3.0"])
111
+ end
112
+ end
113
+
data/lib/crapshoot.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'treetop'
2
+ require 'active_support'
3
+ %w{ scanner postfixer evaluator }.each do |f|
4
+ require File.join(File.dirname(__FILE__), 'crapshoot', f)
5
+ end
6
+
7
+ module Crapshoot
8
+ def self.roll(expression)
9
+ scanner = Scanner.new
10
+ postfixer = Postfixer.new
11
+ evaluator = Evaluator.new
12
+
13
+ tokens = scanner.parse expression
14
+ postfix_tokens = postfixer.postfixify tokens
15
+ result = evaluator.evaluate postfix_tokens
16
+
17
+ return result
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Crapshoot
2
+ class Evaluator
3
+ def evaluate(tokens)
4
+ @stack = []
5
+ @tokens = tokens.dup
6
+ until @tokens.empty?
7
+ step
8
+ end
9
+
10
+ raise "Stack has too many entries: #{@stack.inspect}" unless @stack.length == 1
11
+
12
+ return @stack[0]
13
+ end
14
+
15
+ def step
16
+ candidate = @tokens.shift
17
+ result = candidate.eval @stack
18
+ @stack.push result
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,374 @@
1
+
2
+ # line 1 "lib/crapshoot/parser/scan.rl"
3
+
4
+ # line 33 "lib/crapshoot/parser/scan.rl"
5
+
6
+
7
+ module Crapshoot
8
+ module Parser
9
+ class Scan
10
+ def initialize
11
+ @tokens = []
12
+ @num_stack = []
13
+ end
14
+
15
+ def parse(line)
16
+ data = line.codepoints.to_a
17
+ stack = []
18
+ p = 0
19
+ ts = 0
20
+ te = 0
21
+ act = 0
22
+ eof = data.length
23
+
24
+ # line 25 "lib/crapshoot/parser/scan.rb"
25
+ class << self
26
+ attr_accessor :_scanner_trans_keys
27
+ private :_scanner_trans_keys, :_scanner_trans_keys=
28
+ end
29
+ self._scanner_trans_keys = [
30
+ 0, 0, 48, 57, 9, 45,
31
+ 9, 57, 9, 57, 48,
32
+ 57, 9, 100, 9, 118,
33
+ 9, 45, 9, 45, 0
34
+ ]
35
+
36
+ class << self
37
+ attr_accessor :_scanner_key_spans
38
+ private :_scanner_key_spans, :_scanner_key_spans=
39
+ end
40
+ self._scanner_key_spans = [
41
+ 0, 10, 37, 49, 49, 10, 92, 110,
42
+ 37, 37
43
+ ]
44
+
45
+ class << self
46
+ attr_accessor :_scanner_index_offsets
47
+ private :_scanner_index_offsets, :_scanner_index_offsets=
48
+ end
49
+ self._scanner_index_offsets = [
50
+ 0, 0, 11, 49, 99, 149, 160, 253,
51
+ 364, 402
52
+ ]
53
+
54
+ class << self
55
+ attr_accessor :_scanner_indicies
56
+ private :_scanner_indicies, :_scanner_indicies=
57
+ end
58
+ self._scanner_indicies = [
59
+ 0, 0, 0, 0, 0, 0, 0, 0,
60
+ 0, 0, 1, 2, 2, 2, 2, 2,
61
+ 1, 1, 1, 1, 1, 1, 1, 1,
62
+ 1, 1, 1, 1, 1, 1, 1, 1,
63
+ 1, 1, 2, 1, 1, 1, 1, 1,
64
+ 1, 1, 1, 1, 1, 3, 1, 3,
65
+ 1, 4, 4, 4, 4, 4, 1, 1,
66
+ 1, 1, 1, 1, 1, 1, 1, 1,
67
+ 1, 1, 1, 1, 1, 1, 1, 1,
68
+ 4, 1, 1, 1, 1, 1, 1, 1,
69
+ 1, 1, 1, 1, 1, 1, 1, 1,
70
+ 5, 5, 5, 5, 5, 5, 5, 5,
71
+ 5, 5, 1, 6, 6, 6, 6, 6,
72
+ 1, 1, 1, 1, 1, 1, 1, 1,
73
+ 1, 1, 1, 1, 1, 1, 1, 1,
74
+ 1, 1, 6, 1, 1, 1, 1, 1,
75
+ 1, 1, 1, 1, 1, 1, 1, 1,
76
+ 1, 1, 0, 0, 0, 0, 0, 0,
77
+ 0, 0, 0, 0, 1, 7, 7, 7,
78
+ 7, 7, 7, 7, 7, 7, 7, 1,
79
+ 8, 8, 8, 8, 8, 1, 1, 1,
80
+ 1, 1, 1, 1, 1, 1, 1, 1,
81
+ 1, 1, 1, 1, 1, 1, 1, 8,
82
+ 1, 1, 1, 1, 1, 1, 1, 1,
83
+ 1, 1, 9, 1, 9, 1, 1, 10,
84
+ 10, 10, 10, 10, 10, 10, 10, 10,
85
+ 10, 1, 1, 1, 1, 1, 1, 1,
86
+ 1, 1, 1, 1, 1, 1, 1, 1,
87
+ 1, 1, 1, 1, 1, 1, 1, 1,
88
+ 1, 1, 1, 1, 1, 1, 1, 1,
89
+ 1, 1, 1, 1, 1, 1, 1, 1,
90
+ 1, 1, 1, 11, 1, 12, 12, 12,
91
+ 12, 12, 1, 1, 1, 1, 1, 1,
92
+ 1, 1, 1, 1, 1, 1, 1, 1,
93
+ 1, 1, 1, 1, 12, 1, 1, 1,
94
+ 1, 1, 1, 1, 1, 1, 1, 13,
95
+ 1, 13, 1, 1, 14, 14, 14, 14,
96
+ 14, 14, 14, 14, 14, 14, 1, 1,
97
+ 1, 1, 1, 1, 1, 1, 1, 1,
98
+ 1, 1, 1, 1, 1, 1, 1, 1,
99
+ 1, 1, 1, 1, 1, 1, 1, 1,
100
+ 1, 1, 1, 1, 1, 1, 1, 1,
101
+ 1, 1, 15, 1, 1, 1, 1, 1,
102
+ 1, 1, 1, 1, 1, 1, 1, 1,
103
+ 1, 1, 1, 1, 1, 1, 1, 1,
104
+ 1, 1, 16, 1, 17, 17, 17, 17,
105
+ 17, 1, 1, 1, 1, 1, 1, 1,
106
+ 1, 1, 1, 1, 1, 1, 1, 1,
107
+ 1, 1, 1, 17, 1, 1, 1, 1,
108
+ 1, 1, 1, 1, 1, 1, 18, 1,
109
+ 18, 1, 19, 19, 19, 19, 19, 1,
110
+ 1, 1, 1, 1, 1, 1, 1, 1,
111
+ 1, 1, 1, 1, 1, 1, 1, 1,
112
+ 1, 19, 1, 1, 1, 1, 1, 1,
113
+ 1, 1, 1, 1, 20, 1, 20, 1,
114
+ 0
115
+ ]
116
+
117
+ class << self
118
+ attr_accessor :_scanner_trans_targs
119
+ private :_scanner_trans_targs, :_scanner_trans_targs=
120
+ end
121
+ self._scanner_trans_targs = [
122
+ 6, 0, 2, 3, 4, 6, 4, 7,
123
+ 2, 3, 6, 5, 2, 3, 7, 8,
124
+ 9, 2, 3, 2, 3
125
+ ]
126
+
127
+ class << self
128
+ attr_accessor :_scanner_trans_actions
129
+ private :_scanner_trans_actions, :_scanner_trans_actions=
130
+ end
131
+ self._scanner_trans_actions = [
132
+ 1, 0, 0, 0, 2, 3, 0, 1,
133
+ 4, 4, 0, 5, 6, 6, 0, 5,
134
+ 5, 7, 7, 8, 8
135
+ ]
136
+
137
+ class << self
138
+ attr_accessor :_scanner_eof_actions
139
+ private :_scanner_eof_actions, :_scanner_eof_actions=
140
+ end
141
+ self._scanner_eof_actions = [
142
+ 0, 0, 0, 0, 0, 0, 4, 6,
143
+ 7, 8
144
+ ]
145
+
146
+ class << self
147
+ attr_accessor :scanner_start
148
+ end
149
+ self.scanner_start = 1;
150
+ class << self
151
+ attr_accessor :scanner_first_final
152
+ end
153
+ self.scanner_first_final = 6;
154
+ class << self
155
+ attr_accessor :scanner_error
156
+ end
157
+ self.scanner_error = 0;
158
+
159
+ class << self
160
+ attr_accessor :scanner_en_main
161
+ end
162
+ self.scanner_en_main = 1;
163
+
164
+
165
+ # line 52 "lib/crapshoot/parser/scan.rl"
166
+
167
+ # line 168 "lib/crapshoot/parser/scan.rb"
168
+ begin
169
+ p ||= 0
170
+ pe ||= data.length
171
+ cs = scanner_start
172
+ end
173
+
174
+ # line 53 "lib/crapshoot/parser/scan.rl"
175
+
176
+ # line 177 "lib/crapshoot/parser/scan.rb"
177
+ begin
178
+ testEof = false
179
+ _slen, _trans, _keys, _inds, _acts, _nacts = nil
180
+ _goto_level = 0
181
+ _resume = 10
182
+ _eof_trans = 15
183
+ _again = 20
184
+ _test_eof = 30
185
+ _out = 40
186
+ while true
187
+ if _goto_level <= 0
188
+ if p == pe
189
+ _goto_level = _test_eof
190
+ next
191
+ end
192
+ if cs == 0
193
+ _goto_level = _out
194
+ next
195
+ end
196
+ end
197
+ if _goto_level <= _resume
198
+ _keys = cs << 1
199
+ _inds = _scanner_index_offsets[cs]
200
+ _slen = _scanner_key_spans[cs]
201
+ _trans = if ( _slen > 0 &&
202
+ _scanner_trans_keys[_keys] <= data[p] &&
203
+ data[p] <= _scanner_trans_keys[_keys + 1]
204
+ ) then
205
+ _scanner_indicies[ _inds + data[p] - _scanner_trans_keys[_keys] ]
206
+ else
207
+ _scanner_indicies[ _inds + _slen ]
208
+ end
209
+ cs = _scanner_trans_targs[_trans]
210
+ if _scanner_trans_actions[_trans] != 0
211
+ case _scanner_trans_actions[_trans]
212
+ when 1 then
213
+ # line 4 "lib/crapshoot/parser/scan.rl"
214
+ begin
215
+ @mark_num = p end
216
+ # line 4 "lib/crapshoot/parser/scan.rl"
217
+ when 5 then
218
+ # line 5 "lib/crapshoot/parser/scan.rl"
219
+ begin
220
+ @num_stack.push atos(data[@mark_num..p-1]) end
221
+ # line 5 "lib/crapshoot/parser/scan.rl"
222
+ when 7 then
223
+ # line 8 "lib/crapshoot/parser/scan.rl"
224
+ begin
225
+
226
+ drop = @drop_current
227
+ @drop_current = nil
228
+ sides = @num_stack.pop
229
+ count = @num_stack.pop
230
+ @tokens << Tokens::Series.new(count, sides, drop)
231
+ end
232
+ # line 8 "lib/crapshoot/parser/scan.rl"
233
+ when 2 then
234
+ # line 15 "lib/crapshoot/parser/scan.rl"
235
+ begin
236
+ @tokens << Tokens::Arithmetic.new(data[p-1].chr) end
237
+ # line 15 "lib/crapshoot/parser/scan.rl"
238
+ when 4 then
239
+ # line 5 "lib/crapshoot/parser/scan.rl"
240
+ begin
241
+ @num_stack.push atos(data[@mark_num..p-1]) end
242
+ # line 5 "lib/crapshoot/parser/scan.rl"
243
+ # line 7 "lib/crapshoot/parser/scan.rl"
244
+ begin
245
+ @tokens << Tokens::Constant.new(@num_stack.pop) end
246
+ # line 7 "lib/crapshoot/parser/scan.rl"
247
+ when 6 then
248
+ # line 5 "lib/crapshoot/parser/scan.rl"
249
+ begin
250
+ @num_stack.push atos(data[@mark_num..p-1]) end
251
+ # line 5 "lib/crapshoot/parser/scan.rl"
252
+ # line 8 "lib/crapshoot/parser/scan.rl"
253
+ begin
254
+
255
+ drop = @drop_current
256
+ @drop_current = nil
257
+ sides = @num_stack.pop
258
+ count = @num_stack.pop
259
+ @tokens << Tokens::Series.new(count, sides, drop)
260
+ end
261
+ # line 8 "lib/crapshoot/parser/scan.rl"
262
+ when 3 then
263
+ # line 15 "lib/crapshoot/parser/scan.rl"
264
+ begin
265
+ @tokens << Tokens::Arithmetic.new(data[p-1].chr) end
266
+ # line 15 "lib/crapshoot/parser/scan.rl"
267
+ # line 4 "lib/crapshoot/parser/scan.rl"
268
+ begin
269
+ @mark_num = p end
270
+ # line 4 "lib/crapshoot/parser/scan.rl"
271
+ when 8 then
272
+ # line 17 "lib/crapshoot/parser/scan.rl"
273
+ begin
274
+ @drop_current = data[p-1].chr end
275
+ # line 17 "lib/crapshoot/parser/scan.rl"
276
+ # line 8 "lib/crapshoot/parser/scan.rl"
277
+ begin
278
+
279
+ drop = @drop_current
280
+ @drop_current = nil
281
+ sides = @num_stack.pop
282
+ count = @num_stack.pop
283
+ @tokens << Tokens::Series.new(count, sides, drop)
284
+ end
285
+ # line 8 "lib/crapshoot/parser/scan.rl"
286
+ # line 287 "lib/crapshoot/parser/scan.rb"
287
+ end
288
+ end
289
+ end
290
+ if _goto_level <= _again
291
+ if cs == 0
292
+ _goto_level = _out
293
+ next
294
+ end
295
+ p += 1
296
+ if p != pe
297
+ _goto_level = _resume
298
+ next
299
+ end
300
+ end
301
+ if _goto_level <= _test_eof
302
+ if p == eof
303
+ case _scanner_eof_actions[cs]
304
+ when 7 then
305
+ # line 8 "lib/crapshoot/parser/scan.rl"
306
+ begin
307
+
308
+ drop = @drop_current
309
+ @drop_current = nil
310
+ sides = @num_stack.pop
311
+ count = @num_stack.pop
312
+ @tokens << Tokens::Series.new(count, sides, drop)
313
+ end
314
+ # line 8 "lib/crapshoot/parser/scan.rl"
315
+ when 4 then
316
+ # line 5 "lib/crapshoot/parser/scan.rl"
317
+ begin
318
+ @num_stack.push atos(data[@mark_num..p-1]) end
319
+ # line 5 "lib/crapshoot/parser/scan.rl"
320
+ # line 7 "lib/crapshoot/parser/scan.rl"
321
+ begin
322
+ @tokens << Tokens::Constant.new(@num_stack.pop) end
323
+ # line 7 "lib/crapshoot/parser/scan.rl"
324
+ when 6 then
325
+ # line 5 "lib/crapshoot/parser/scan.rl"
326
+ begin
327
+ @num_stack.push atos(data[@mark_num..p-1]) end
328
+ # line 5 "lib/crapshoot/parser/scan.rl"
329
+ # line 8 "lib/crapshoot/parser/scan.rl"
330
+ begin
331
+
332
+ drop = @drop_current
333
+ @drop_current = nil
334
+ sides = @num_stack.pop
335
+ count = @num_stack.pop
336
+ @tokens << Tokens::Series.new(count, sides, drop)
337
+ end
338
+ # line 8 "lib/crapshoot/parser/scan.rl"
339
+ when 8 then
340
+ # line 17 "lib/crapshoot/parser/scan.rl"
341
+ begin
342
+ @drop_current = data[p-1].chr end
343
+ # line 17 "lib/crapshoot/parser/scan.rl"
344
+ # line 8 "lib/crapshoot/parser/scan.rl"
345
+ begin
346
+
347
+ drop = @drop_current
348
+ @drop_current = nil
349
+ sides = @num_stack.pop
350
+ count = @num_stack.pop
351
+ @tokens << Tokens::Series.new(count, sides, drop)
352
+ end
353
+ # line 8 "lib/crapshoot/parser/scan.rl"
354
+ # line 355 "lib/crapshoot/parser/scan.rb"
355
+ end
356
+ end
357
+
358
+ end
359
+ if _goto_level <= _out
360
+ break
361
+ end
362
+ end
363
+ end
364
+
365
+ # line 54 "lib/crapshoot/parser/scan.rl"
366
+ return @tokens
367
+ end
368
+
369
+ def atos(a)
370
+ a.map(&:chr).join
371
+ end
372
+ end
373
+ end
374
+ end