parse_queue 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +17 -7
- data/lib/parse_queue/exceptions.rb +0 -2
- data/lib/parse_queue/version.rb +1 -3
- data/lib/parse_queue.rb +39 -31
- data/parse_queue.gemspec +2 -0
- data/rakefile.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 383a2388d540d992e658a3b6e3eff0a04ffcaab4
|
4
|
+
data.tar.gz: 63aac7b0b20544d1e596a58d8e1e88d8f6c012b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f7a07e5d590f807e8d9097ac5ea0b9fd567f9366fef702a5d5e0cf2be17d07b22b8127107db635ea828964ca2044fcc9267a22c8554b57500265d0d35baa72e
|
7
|
+
data.tar.gz: 37fa8202815532981dfd6d5327117e6e83fc5618d9be63f2317ebcb2bdde2a9c059140823d5c1ce7eb48c072ba175adf576cbc08c768f2b1539c52fee6ff01e2
|
data/README.md
CHANGED
@@ -34,11 +34,21 @@ When creating a parse queue, an optional block parameter is passed in. This is
|
|
34
34
|
called whenever more queue items are required. For example:
|
35
35
|
|
36
36
|
```ruby
|
37
|
-
|
37
|
+
def open_file_tokenized(name)
|
38
|
+
txt = IO.readlines(name, nil)[0]
|
39
|
+
lex = LexicalAnalayzer.new(text: txt, rules: LEXICAL_RULES)
|
40
|
+
ParseQueue.new { lex.get }
|
41
|
+
end
|
38
42
|
```
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
This example above is a method that reads in the named file, creates an
|
44
|
+
analyzer on it (see the
|
45
|
+
[lexical_analyzer](https://rubygems.org/gems/lexical_analyzer)
|
46
|
+
gem for more details) and then uses that as the source for the parse queue.
|
47
|
+
The queue is returned for use by the compiler's parser.
|
48
|
+
|
49
|
+
Note: If the fetch block is omitted, then items will have to added to the parse
|
50
|
+
queue using the add method. The add method accepts single items, multiple items
|
51
|
+
or an array of items.
|
42
52
|
|
43
53
|
#### Getting a queued item:
|
44
54
|
|
@@ -120,7 +130,7 @@ a **ParseQueueNoRev** exception is raised.
|
|
120
130
|
|
121
131
|
#### Plan A
|
122
132
|
|
123
|
-
1. Fork it ( https://github.com/PeterCamilleri/
|
133
|
+
1. Fork it ( https://github.com/PeterCamilleri/parse_queue/fork )
|
124
134
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
125
135
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
126
136
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -134,10 +144,10 @@ aspect that could use some TLC or a suggestion or an idea.
|
|
134
144
|
## License
|
135
145
|
|
136
146
|
The gem is available as open source under the terms of the
|
137
|
-
[MIT License](
|
147
|
+
[MIT License](./LICENSE.txt).
|
138
148
|
|
139
149
|
## Code of Conduct
|
140
150
|
|
141
151
|
Everyone interacting in the ParseQueue project’s codebases, issue trackers,
|
142
152
|
chat rooms and mailing lists is expected to follow the
|
143
|
-
[code of conduct](
|
153
|
+
[code of conduct](./CODE_OF_CONDUCT.md).
|
data/lib/parse_queue/version.rb
CHANGED
data/lib/parse_queue.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
# The Ruby Compiler Toolkit Project - Parse Queue
|
4
2
|
# A queue for compiler objects between parser layers.
|
5
3
|
|
@@ -11,44 +9,54 @@ class ParseQueue
|
|
11
9
|
# The current read point of the queue.
|
12
10
|
attr_reader :position
|
13
11
|
|
14
|
-
#
|
15
|
-
|
12
|
+
#The default fetch block
|
13
|
+
DFB = Proc.new { false }
|
16
14
|
|
17
15
|
# Set up the parser queue.
|
18
16
|
def initialize(&fetch)
|
19
|
-
@fetch
|
17
|
+
@fetch = fetch || DFB
|
20
18
|
@buffer = []
|
21
19
|
@offset = @position = 0
|
22
20
|
end
|
23
21
|
|
24
22
|
# How many unread items are in this parse queue?
|
25
|
-
def
|
26
|
-
|
23
|
+
def fwd_count
|
24
|
+
index_limit - @position
|
27
25
|
end
|
28
26
|
|
29
|
-
#
|
30
|
-
def
|
31
|
-
@
|
27
|
+
# How many already read items are still in this parse queue?
|
28
|
+
def rev_count
|
29
|
+
@position - @offset
|
32
30
|
end
|
33
31
|
|
34
32
|
# Get an item from the buffer.
|
35
33
|
def get
|
36
|
-
if @position
|
34
|
+
if @position == index_limit
|
37
35
|
item = @fetch.call
|
38
|
-
|
36
|
+
|
37
|
+
unless item
|
38
|
+
@fetch = DFB
|
39
|
+
fail ParseQueueNoFwd
|
40
|
+
end
|
41
|
+
|
39
42
|
@buffer << item
|
40
43
|
end
|
41
44
|
|
42
|
-
result = @buffer[
|
45
|
+
result = @buffer[rev_count]
|
43
46
|
@position += 1
|
44
47
|
result
|
45
48
|
end
|
46
49
|
|
47
|
-
#
|
48
|
-
def
|
50
|
+
# Fetch all possible items.
|
51
|
+
def fetch_all
|
49
52
|
loop do
|
50
53
|
item = @fetch.call
|
51
|
-
|
54
|
+
|
55
|
+
unless item
|
56
|
+
@fetch = DFB
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
52
60
|
@buffer << item
|
53
61
|
end
|
54
62
|
end
|
@@ -60,40 +68,40 @@ class ParseQueue
|
|
60
68
|
end
|
61
69
|
|
62
70
|
# Undo the last get.
|
63
|
-
def
|
64
|
-
@position -=
|
71
|
+
def unget(count=1)
|
72
|
+
@position -= count
|
65
73
|
validate_position
|
66
74
|
end
|
67
75
|
|
68
76
|
# Release any items before the current item.
|
69
77
|
def shift
|
70
|
-
@buffer.shift(
|
78
|
+
@buffer.shift(rev_count)
|
71
79
|
@offset = @position
|
72
80
|
end
|
73
81
|
|
74
82
|
# Try to process some items with roll back on failure.
|
75
83
|
def try(&block)
|
76
84
|
save = @position
|
77
|
-
|
78
|
-
|
85
|
+
self.position = save unless (result = block.call)
|
86
|
+
result
|
79
87
|
end
|
80
88
|
|
81
|
-
#
|
89
|
+
# Process some items with a shift on success and a roll back on failure.
|
82
90
|
def try!(&block)
|
83
|
-
|
84
|
-
|
85
|
-
if block.call
|
86
|
-
shift
|
87
|
-
else
|
88
|
-
@position = save
|
89
|
-
validate_position
|
90
|
-
end
|
91
|
+
shift if (result = try(&block))
|
92
|
+
result
|
91
93
|
end
|
92
94
|
|
95
|
+
private
|
96
|
+
|
93
97
|
# Is this a valid position?
|
94
98
|
def validate_position
|
95
99
|
fail ParseQueueNoRev if @position < @offset
|
96
|
-
fail ParseQueueNoFwd if @position >=
|
100
|
+
fail ParseQueueNoFwd if @position >= index_limit
|
97
101
|
end
|
98
102
|
|
103
|
+
# The first index past the end of the array
|
104
|
+
def index_limit
|
105
|
+
@buffer.length + @offset
|
106
|
+
end
|
99
107
|
end
|
data/parse_queue.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.required_ruby_version = '>=2.3.0'
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.15"
|
22
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
25
|
spec.add_development_dependency "minitest", "~> 5.0"
|
data/rakefile.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parse_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PeterCamilleri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
96
|
requirements:
|
97
97
|
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
99
|
+
version: 2.3.0
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
102
|
- - ">="
|