ragel-bitmap 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aceb3e68e482270337fa3a13a01c176df168731cbb129f7dca0d42a7a999fcb8
4
+ data.tar.gz: 9891faf2710a410ba99a2a9f40ed8aa7fd06f239a77312b1a76199d03236d653
5
+ SHA512:
6
+ metadata.gz: 2f92c6dee162edfeb0a2e5c09745e08c03797ced2f704fefbd1b89d1aaa5fd1ee8f8252cc8dbc4cfb5c8a4f5d38dbfa00be7579f87e704a71c765637422065ba
7
+ data.tar.gz: 5e4f050c199ae16bd4008bfb4ff06fb0a515109a8ceb8832195b3117c6737cd9d90b7b14912fc2bc223630ae53503f5608162cb10262d472a7053adfd85a1f84
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ TargetRubyVersion: 2.6
5
+ Exclude:
6
+ - 'test/ragel/fixtures/*'
7
+ - 'vendor/**/*'
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm: 2.6.3
4
+ before_install:
5
+ - gem update --system
6
+ - gem install bundler
7
+ script:
8
+ - bundle exec rake
9
+ - bundle exec rubocop
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ragel-bitmap (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ jaro_winkler (1.5.2)
11
+ minitest (5.11.3)
12
+ parallel (1.17.0)
13
+ parser (2.6.3.0)
14
+ ast (~> 2.4.0)
15
+ rainbow (3.0.0)
16
+ rake (12.3.2)
17
+ rubocop (0.70.0)
18
+ jaro_winkler (~> 1.5.1)
19
+ parallel (~> 1.10)
20
+ parser (>= 2.6)
21
+ rainbow (>= 2.2.2, < 4.0)
22
+ ruby-progressbar (~> 1.7)
23
+ unicode-display_width (>= 1.4.0, < 1.7)
24
+ ruby-progressbar (1.10.1)
25
+ unicode-display_width (1.6.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 2.0)
32
+ minitest (~> 5.11)
33
+ ragel-bitmap!
34
+ rake (~> 12.3)
35
+ rubocop (~> 0.70)
36
+
37
+ BUNDLED WITH
38
+ 2.0.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Kevin Deisz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Ragel::Bitmap
2
+
3
+ [![Build Status](https://travis-ci.com/kddeisz/ragel-bitmap.svg?branch=master)](https://travis-ci.com/kddeisz/ragel-bitmap)
4
+
5
+ Use bitmaps for ragel-generated code instead of arrays.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ragel-bitmap'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ragel-bitmap
22
+
23
+ ## Usage
24
+
25
+ Use `Ragel::Bitmap.replace(filepath)` where `filepath` is a path to a ragel-generated file. Require `ragel/bitmap` in your code. Profit!
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kddeisz/ragel-bitmap.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ragel/bitmap'
6
+
7
+ require 'irb'
8
+ IRB.start(__FILE__)
data/bin/replace ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ragel/bitmap'
6
+
7
+ Ragel::Bitmap.replace(ARGV[0])
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ragel/bitmap/version'
4
+
5
+ module Ragel
6
+ # An integer bitmap that contains a width (the number of bytes that the
7
+ # largest integer requires) and a bitmap (an integer that is the combination
8
+ # of the element integers)
9
+ class Bitmap
10
+ attr_reader :width, :bitmap
11
+
12
+ def initialize(width, bitmap)
13
+ @width = width
14
+ @bitmap = bitmap
15
+ end
16
+
17
+ def [](index)
18
+ (bitmap >> (width * index)) & (2**width - 1)
19
+ end
20
+
21
+ def self.replace(filepath)
22
+ require 'ragel/bitmap/replace'
23
+
24
+ File.write(filepath, Replace.replace(File.read(filepath)))
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ripper'
4
+
5
+ module Ragel
6
+ class Bitmap
7
+ # A ruby parser that finds instances of table declarations in a
8
+ # ragel-outputted file.
9
+ class Replace < Ripper::SexpBuilderPP
10
+ # Represents a table declaration in the source
11
+ class Table
12
+ attr_reader :source, :start_line, :end_line
13
+
14
+ def initialize(left, right, lineno)
15
+ @source = source_from(left[3][1], right[1].map { |int| int[1].to_i })
16
+ @start_line = left[1][1][2][0] - 1
17
+ @end_line = lineno
18
+ end
19
+
20
+ def source_from(name, numbers)
21
+ width = Math.log2(numbers.max).ceil
22
+ bitmap =
23
+ numbers.each_with_index.inject(0) do |accum, (number, index)|
24
+ accum | (number << (width * index))
25
+ end
26
+
27
+ "self.#{name} = ::Ragel::Bitmap.new(#{width}, #{bitmap})"
28
+ end
29
+ end
30
+
31
+ # Represents the source as it changes
32
+ class Buffer
33
+ attr_reader :lines
34
+
35
+ def initialize(source)
36
+ @lines = source.split("\n")
37
+ end
38
+
39
+ def replace(table)
40
+ buffer = lines[table.start_line][/\A\s+/]
41
+ source = ["#{buffer}#{table.source}"]
42
+
43
+ @lines =
44
+ lines[0...table.start_line] + source + lines[table.end_line..-1]
45
+ end
46
+
47
+ def to_source
48
+ "#{lines.join("\n")}\n"
49
+ end
50
+ end
51
+
52
+ attr_reader :tables
53
+
54
+ def initialize(*)
55
+ super
56
+ @tables = []
57
+ end
58
+
59
+ class << self
60
+ def replace(source)
61
+ buffer = Buffer.new(source)
62
+ tables_from(source).reverse_each { |table| buffer.replace(table) }
63
+ buffer.to_source
64
+ end
65
+
66
+ private
67
+
68
+ def tables_from(source)
69
+ replace = new(source)
70
+ replace.parse
71
+
72
+ if replace.error?
73
+ warn 'Invalid ruby'
74
+ exit 1
75
+ end
76
+
77
+ replace.tables
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def on_assign(left, right)
84
+ super.tap do
85
+ next if left[0] != :field || right[0] != :array
86
+
87
+ tables << Table.new(left, right, lineno)
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ragel
4
+ class Bitmap
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'ragel/bitmap/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'ragel-bitmap'
9
+ spec.version = Ragel::Bitmap::VERSION
10
+ spec.authors = ['Kevin Deisz']
11
+ spec.email = ['kevin.deisz@gmail.com']
12
+
13
+ spec.summary = 'Use bitmaps for ragel-generated code instead of arrays'
14
+ spec.homepage = 'https://github.com/kddeisz/ragel-bitmap'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files =
18
+ Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ end
23
+
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_development_dependency 'bundler', '~> 2.0'
29
+ spec.add_development_dependency 'minitest', '~> 5.11'
30
+ spec.add_development_dependency 'rake', '~> 12.3'
31
+ spec.add_development_dependency 'rubocop', '~> 0.70'
32
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ragel-bitmap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Deisz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.70'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.70'
69
+ description:
70
+ email:
71
+ - kevin.deisz@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rubocop.yml"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/replace
86
+ - bin/setup
87
+ - lib/ragel/bitmap.rb
88
+ - lib/ragel/bitmap/replace.rb
89
+ - lib/ragel/bitmap/version.rb
90
+ - ragel-bitmap.gemspec
91
+ homepage: https://github.com/kddeisz/ragel-bitmap
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubygems_version: 3.0.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Use bitmaps for ragel-generated code instead of arrays
114
+ test_files: []