ragel-bitmap 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/Gemfile.lock +4 -4
- data/LICENSE +1 -1
- data/README.md +12 -2
- data/lib/ragel/bitmap/replace.rb +44 -24
- data/lib/ragel/bitmap/version.rb +2 -2
- data/lib/ragel/bitmap.rb +46 -11
- data/ragel-bitmap.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '092e46dd50337f51b96bc571bcabb3cb157c903a65469256f923df24006dcca4'
|
4
|
+
data.tar.gz: 965528c96ccd950bbd515dd57cf7213debeacb1a1f2531b22fc503e4c991401d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b27d046b012d2305cf884abc5c012724b40aaec5095c41aed8f19cd3ed2536cb23c5e878d79cdcd8c55f51d137adc5a481014e139cb76b2dcca3fb5535d6a49
|
7
|
+
data.tar.gz: e693f71d64e87a3c7cf25d30c554afc059ca288911feb7e3c3ad0835dc641f800c19d50df24eec78b8a4aa996a9d4e076981f7ec64adc589fd84a82ba07ed1e0
|
data/.rubocop.yml
CHANGED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
- Using welcoming and inclusive language
|
18
|
+
- Being respectful of differing viewpoints and experiences
|
19
|
+
- Gracefully accepting constructive criticism
|
20
|
+
- Focusing on what is best for the community
|
21
|
+
- Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
- The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
- Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
- Public or private harassment
|
29
|
+
- Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at kevin.deisz@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
|
+
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
74
|
+
|
75
|
+
For answers to common questions about this code of conduct, see
|
76
|
+
https://www.contributor-covenant.org/faq
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ragel-bitmap (0.
|
4
|
+
ragel-bitmap (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.0)
|
10
|
-
jaro_winkler (1.5.
|
10
|
+
jaro_winkler (1.5.3)
|
11
11
|
minitest (5.11.3)
|
12
12
|
parallel (1.17.0)
|
13
13
|
parser (2.6.3.0)
|
14
14
|
ast (~> 2.4.0)
|
15
15
|
rainbow (3.0.0)
|
16
16
|
rake (12.3.2)
|
17
|
-
rubocop (0.
|
17
|
+
rubocop (0.72.0)
|
18
18
|
jaro_winkler (~> 1.5.1)
|
19
19
|
parallel (~> 1.10)
|
20
20
|
parser (>= 2.6)
|
@@ -32,7 +32,7 @@ DEPENDENCIES
|
|
32
32
|
minitest (~> 5.11)
|
33
33
|
ragel-bitmap!
|
34
34
|
rake (~> 12.3)
|
35
|
-
rubocop (~> 0.
|
35
|
+
rubocop (~> 0.72)
|
36
36
|
|
37
37
|
BUNDLED WITH
|
38
38
|
2.0.1
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.com/kddeisz/ragel-bitmap.svg?branch=master)](https://travis-ci.com/kddeisz/ragel-bitmap)
|
4
4
|
|
5
|
-
|
5
|
+
[Ragel](https://www.colm.net/open-source/ragel/) generates ruby code with very large arrays of integers that allocate a lot of memory when required. To reduce memory consumption, this gem replaces those arrays with packed strings.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,17 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
After you've run `ragel` to generate your parser, you should then run this gem over the resulting source file and it will replace the integer arrays inline. For example, the following code adds a rake rule to generate the ragel parser from the grammar file and then run `Ragel::Bitmap` over it:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
rule %r|_parser\.rb\z| => '%X.rl' do |t|
|
29
|
+
sh "ragel -s -R -L -F1 -o #{t.name} #{t.source}"
|
30
|
+
require 'ragel/bitmap'
|
31
|
+
Ragel::Bitmap.replace(t.name)
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Then, in your application, add `require 'ragel/bitmap'` before you require your parser. Now you should be off and running!
|
26
36
|
|
27
37
|
## Development
|
28
38
|
|
data/lib/ragel/bitmap/replace.rb
CHANGED
@@ -3,10 +3,36 @@
|
|
3
3
|
require 'ripper'
|
4
4
|
|
5
5
|
module Ragel
|
6
|
-
|
6
|
+
module Bitmap
|
7
7
|
# A ruby parser that finds instances of table declarations in a
|
8
8
|
# ragel-outputted file.
|
9
9
|
class Replace < Ripper::SexpBuilderPP
|
10
|
+
class << self
|
11
|
+
# Get the required args for a bitmap from a set of numbers
|
12
|
+
def bitmap_args_from(numbers)
|
13
|
+
size = (Math.log2(numbers.max) / 8).ceil
|
14
|
+
strings =
|
15
|
+
size.downto(1).map do |index|
|
16
|
+
shift = (index - 1) * 8
|
17
|
+
numbers.map { |number| (number >> shift) & 0xff }.pack('C*')
|
18
|
+
end
|
19
|
+
|
20
|
+
[class_from(size), strings]
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def class_from(size)
|
26
|
+
case size
|
27
|
+
when 1 then :Array8
|
28
|
+
when 2 then :Array16
|
29
|
+
when 3 then :Array24
|
30
|
+
else
|
31
|
+
:ArrayGeneric
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
10
36
|
# Represents a table declaration in the source
|
11
37
|
class Table
|
12
38
|
attr_reader :source, :start_line, :end_line
|
@@ -17,14 +43,13 @@ module Ragel
|
|
17
43
|
@end_line = lineno
|
18
44
|
end
|
19
45
|
|
46
|
+
private
|
47
|
+
|
20
48
|
def source_from(name, numbers)
|
21
|
-
|
22
|
-
|
23
|
-
numbers.each_with_index.inject(0) do |accum, (number, index)|
|
24
|
-
accum | (number << (width * index))
|
25
|
-
end
|
49
|
+
clazz, strings = Replace.bitmap_args_from(numbers)
|
50
|
+
arguments = strings.map(&:inspect).join(', ')
|
26
51
|
|
27
|
-
"self.#{name} = ::Ragel::Bitmap.new(#{
|
52
|
+
"self.#{name} = ::Ragel::Bitmap::#{clazz}.new(#{arguments})"
|
28
53
|
end
|
29
54
|
end
|
30
55
|
|
@@ -56,26 +81,21 @@ module Ragel
|
|
56
81
|
@tables = []
|
57
82
|
end
|
58
83
|
|
59
|
-
|
60
|
-
|
61
|
-
buffer = Buffer.new(source)
|
62
|
-
tables_from(source).reverse_each { |table| buffer.replace(table) }
|
63
|
-
buffer.to_source
|
64
|
-
end
|
84
|
+
def each_table(&block)
|
85
|
+
parse
|
65
86
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
replace.parse
|
87
|
+
if error?
|
88
|
+
warn 'Invalid ruby'
|
89
|
+
exit 1
|
90
|
+
end
|
71
91
|
|
72
|
-
|
73
|
-
|
74
|
-
exit 1
|
75
|
-
end
|
92
|
+
tables.reverse_each(&block)
|
93
|
+
end
|
76
94
|
|
77
|
-
|
78
|
-
|
95
|
+
def self.replace(source)
|
96
|
+
buffer = Buffer.new(source)
|
97
|
+
new(source).each_table { |table| buffer.replace(table) }
|
98
|
+
buffer.to_source
|
79
99
|
end
|
80
100
|
|
81
101
|
private
|
data/lib/ragel/bitmap/version.rb
CHANGED
data/lib/ragel/bitmap.rb
CHANGED
@@ -3,19 +3,54 @@
|
|
3
3
|
require 'ragel/bitmap/version'
|
4
4
|
|
5
5
|
module Ragel
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
module Bitmap
|
7
|
+
class Array8
|
8
|
+
def initialize(string)
|
9
|
+
@string = string
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](idx)
|
13
|
+
@string.getbyte(idx)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Array16
|
18
|
+
def initialize(highstring, lowstring)
|
19
|
+
@highstring = highstring
|
20
|
+
@lowstring = lowstring
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](idx)
|
24
|
+
(@highstring.getbyte(idx) << 8) | @lowstring.getbyte(idx)
|
25
|
+
end
|
15
26
|
end
|
16
27
|
|
17
|
-
|
18
|
-
|
28
|
+
class Array24
|
29
|
+
def initialize(highstring, middlestring, lowstring)
|
30
|
+
@highstring = highstring
|
31
|
+
@middlestring = middlestring
|
32
|
+
@lowstring = lowstring
|
33
|
+
end
|
34
|
+
|
35
|
+
def [](idx)
|
36
|
+
(@highstring.getbyte(idx) << 16) |
|
37
|
+
(@middlestring.getbyte(idx) << 8) |
|
38
|
+
@lowstring.getbyte(idx)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class ArrayGeneric
|
43
|
+
def initialize(*strings)
|
44
|
+
@strings = strings
|
45
|
+
end
|
46
|
+
|
47
|
+
def [](idx)
|
48
|
+
shift = @strings.length * 8
|
49
|
+
@strings.inject(0) do |product, bitmap|
|
50
|
+
shift -= 8
|
51
|
+
product | (bitmap.getbyte(idx) << shift)
|
52
|
+
end
|
53
|
+
end
|
19
54
|
end
|
20
55
|
|
21
56
|
def self.replace(filepath)
|
data/ragel-bitmap.gemspec
CHANGED
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
29
29
|
spec.add_development_dependency 'minitest', '~> 5.11'
|
30
30
|
spec.add_development_dependency 'rake', '~> 12.3'
|
31
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.72'
|
32
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ragel-bitmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.72'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
68
|
+
version: '0.72'
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
- kevin.deisz@gmail.com
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- ".gitignore"
|
77
77
|
- ".rubocop.yml"
|
78
78
|
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
79
80
|
- Gemfile
|
80
81
|
- Gemfile.lock
|
81
82
|
- LICENSE
|