raabro 1.1.5 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aacf8b3ef595904e286ba4ed9544c3e7901e8815479a1a01cb70e02f40e03eda
4
+ data.tar.gz: b359e9b7c05039623d288dfc69c931b2b38e2ae8ee1c3e211d66f9218c12e32e
5
+ SHA512:
6
+ metadata.gz: f31a3a5db74555d01b7d6a384ab4bd91dbf5beec8544aa99d7b012a60ce87767b51c1f6e74dd81e5c99b56eaea1bd0cb3cc1096452d58119a1fc33ada07e803e
7
+ data.tar.gz: 75b99b8c242258baab31f85d325585ad5c611ec0d98ce80110a1972d2b39762b035cb49fc66b0964b32edf8a1867b6a858756836ab40da6625921af8afd4eb3f
@@ -2,6 +2,33 @@
2
2
  # raabro CHANGELOG.md
3
3
 
4
4
 
5
+ ## raabro 1.3.3 released 2020-09-24
6
+
7
+ * Merge Henrik's rewrite_ optimization
8
+
9
+
10
+ ## raabro 1.3.2 released 2020-09-24
11
+
12
+ * Make a tiny rewrite_ optimization
13
+
14
+
15
+ ## raabro 1.3.1 released 2020-05-10
16
+
17
+ * Add '!' (not) seq quantifier
18
+
19
+
20
+ ## raabro 1.3.0 released 2020-05-10
21
+
22
+ * Add `nott` parser element
23
+ * Add Tree#strinp and #strim
24
+ * Skip 1.2.0 to align on http://github.com/jmettraux/jaabro
25
+
26
+
27
+ ## raabro 1.1.6 released 2018-06-22
28
+
29
+ * Remove unused `add` var, gh-2, thanks to https://github.com/utilum
30
+
31
+
5
32
  ## raabro 1.1.5 released 2017-08-19
6
33
 
7
34
  * Default name to nil for Tree#subgather, #gather, #sublookup, and #lookup
@@ -0,0 +1,15 @@
1
+
2
+ # raabro credits
3
+
4
+ * Henryk Nyh https://github.com/henrik optimized rewrite_, gh-6
5
+ * Utilum https://github.com/utilum removed unused var
6
+ * John Mettraux https://github.com/jmettraux author and maintainer
7
+
8
+
9
+ ## aabro and jaabro credits
10
+
11
+ Thanks to all the people who contributed to aabro and jaabro as well.
12
+
13
+ * https://github.com/flon-io/aabro
14
+ * https://github.com/jmettraux/jaabro
15
+
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2015-2017, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2015-2020, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
@@ -19,3 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
19
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  THE SOFTWARE.
21
21
 
22
+
23
+ Made in Japan.
24
+
data/Makefile CHANGED
@@ -1,9 +1,15 @@
1
1
 
2
+ ## gem tasks ##
3
+
2
4
  NAME = \
3
5
  $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
4
6
  VERSION = \
5
7
  $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version")
6
8
 
9
+ count_lines:
10
+ find lib -name "*.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
11
+ find spec -name "*_spec.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
12
+ cl: count_lines
7
13
 
8
14
  gemspec_validate:
9
15
  @echo "---"
@@ -13,11 +19,21 @@ gemspec_validate:
13
19
  name: gemspec_validate
14
20
  @echo "$(NAME) $(VERSION)"
15
21
 
22
+ cw:
23
+ find lib -name "*.rb" -exec ruby -cw {} \;
24
+
16
25
  build: gemspec_validate
17
26
  gem build $(NAME).gemspec
18
27
  mkdir -p pkg
19
28
  mv $(NAME)-$(VERSION).gem pkg/
20
29
 
21
30
  push: build
22
- gem push pkg/$(NAME)-$(VERSION).gem
31
+ gem push --otp "$(OTP)" pkg/$(NAME)-$(VERSION).gem
32
+
33
+ spec:
34
+ bundle exec rspec
35
+ test: spec
36
+
37
+
38
+ .PHONY: count_lines gemspec_validate name cw build push spec
23
39
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  # raabro
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/jmettraux/raabro.svg)](http://travis-ci.org/jmettraux/raabro)
4
+ [![Build Status](https://secure.travis-ci.org/floraison/raabro.svg)](http://travis-ci.org/floraison/raabro)
5
5
  [![Gem Version](https://badge.fury.io/rb/raabro.svg)](http://badge.fury.io/rb/raabro)
6
6
 
7
7
  A very dumb PEG parser library.
@@ -27,31 +27,44 @@ module Fun include Raabro
27
27
  #
28
28
  # Last function is the root, "i" stands for "input".
29
29
 
30
- def pa(i); rex(nil, i, /\(\s*/); end
31
- def pz(i); rex(nil, i, /\)\s*/); end
32
- def com(i); rex(nil, i, /,\s*/); end
30
+ def pstart(i); rex(nil, i, /\(\s*/); end
31
+ def pend(i); rex(nil, i, /\)\s*/); end
32
+ # parenthese start and end, including trailing white space
33
+
34
+ def comma(i); rex(nil, i, /,\s*/); end
35
+ # a comma, including trailing white space
33
36
 
34
37
  def num(i); rex(:num, i, /-?[0-9]+\s*/); end
38
+ # name is :num, a positive or negative integer
39
+
40
+ def args(i); eseq(nil, i, :pstart, :exp, :comma, :pend); end
41
+ # a set of :exp, beginning with a (, punctuated by commas and ending with )
35
42
 
36
- def args(i); eseq(nil, i, :pa, :exp, :com, :pz); end
37
43
  def funame(i); rex(nil, i, /[a-z][a-z0-9]*/); end
38
44
  def fun(i); seq(:fun, i, :funame, :args); end
45
+ # name is :fun, a function composed of a function name
46
+ # followed by arguments
39
47
 
40
48
  def exp(i); alt(nil, i, :fun, :num); end
49
+ # an expression is either (alt) a function or a number
41
50
 
42
51
  # rewrite
43
52
  #
44
53
  # Names above (:num, :fun, ...) get a rewrite_xxx function.
45
54
  # "t" stands for "tree".
46
- #
47
- # The trees with a nil name are handled by rewrite_(tree) a default
48
- # rewrite function
49
55
 
56
+ def rewrite_exp(t); rewrite(t.children[0]); end
50
57
  def rewrite_num(t); t.string.to_i; end
51
58
 
52
59
  def rewrite_fun(t)
53
- [ t.children[0].string ] +
54
- t.children[1].odd_children.collect { |a| rewrite(a) }
60
+
61
+ funame, args = t.children
62
+
63
+ [ funame.string ] +
64
+ args.gather.collect { |e| rewrite(e) }
65
+ #
66
+ # #gather collect all the children in a tree that have
67
+ # a name, in this example, names can be :exp, :num, :fun
55
68
  end
56
69
  end
57
70
 
@@ -121,6 +134,9 @@ def altg(name, input, *parsers)
121
134
  def rep(name, input, parser, min, max=0)
122
135
  # repeats the the wrapped parser
123
136
 
137
+ def nott(name, input, parser)
138
+ # succeeds if the wrapped parser fails, fails if it succeeds
139
+
124
140
  def ren(name, input, parser)
125
141
  # renames the output of the wrapped parser
126
142
 
@@ -143,6 +159,8 @@ def eseq(name, input, startpa, eltpa, seppa, endpa)
143
159
 
144
160
  `seq` is special, it understands "quantifiers": `'?'`, `'+'` or `'*'`. They make behave `seq` a bit like a classical regex.
145
161
 
162
+ The `'!'` (bang, not) quantifier is explained at the end of this section.
163
+
146
164
  ```ruby
147
165
  module CartParser include Raabro
148
166
 
@@ -162,6 +180,16 @@ end
162
180
 
163
181
  (Yes, this sample parser parses string like "appletomatocabbage", it's not very useful, but I hope you get the point about `.seq`)
164
182
 
183
+ The `'!'` (bang, not) quantifier is a kind of "negative lookahead".
184
+
185
+ ```ruby
186
+ def menu(i)
187
+ seq(:menu, i, :mise_en_bouche, :main, :main, '!', :dessert)
188
+ end
189
+ ```
190
+
191
+ Lousy example, but here a main cannot follow a main.
192
+
165
193
 
166
194
  ## trees
167
195
 
@@ -187,7 +215,7 @@ end
187
215
 
188
216
  I'm using "child or sub-child" instead of "descendant" because once a child or sub-child matches, those methods do not consider the children or sub-children of that matching entity.
189
217
 
190
- Here is a closeup on the rewrite functions of the sample parser at [doc/readme1.rb](doc/readme1.rb) (extracted from an early version of [floraison/dense](https://github.com/floraison/dense):
218
+ Here is a closeup on the rewrite functions of the sample parser at [doc/readme1.rb](doc/readme1.rb) (extracted from an early version of [floraison/dense](https://github.com/floraison/dense)):
191
219
  ```ruby
192
220
  require 'raabro'
193
221
 
@@ -1,31 +1,7 @@
1
- #--
2
- # Copyright (c) 2015-2017, John Mettraux, jmettraux@gmail.com
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in
12
- # all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #
22
- # Made in Japan.
23
- #++
24
-
25
1
 
26
2
  module Raabro
27
3
 
28
- VERSION = '1.1.5'
4
+ VERSION = '1.3.3'
29
5
 
30
6
  class Input
31
7
 
@@ -102,15 +78,10 @@ module Raabro
102
78
  @children = successful_children
103
79
  end
104
80
 
105
- def string
106
-
107
- @input.string[@offset, @length]
108
- end
109
-
110
- def nonstring(l=7)
111
-
112
- @input.string[@offset, l]
113
- end
81
+ def string; @input.string[@offset, @length]; end
82
+ def strinp; @input.string[@offset, @length].strip; end
83
+ alias strim strinp
84
+ def nonstring(l=7); @input.string[@offset, l]; end
114
85
 
115
86
  def lookup(name=nil)
116
87
 
@@ -201,7 +172,7 @@ module Raabro
201
172
  .collect(&:inspect).join('/')
202
173
  "parsing failed .../#{path}"
203
174
  else
204
- "parsing failed, not all input was consumed"
175
+ 'parsing failed, not all input was consumed'
205
176
  end
206
177
  visual =
207
178
  visual(line, column)
@@ -211,7 +182,7 @@ module Raabro
211
182
 
212
183
  def lookup_error(stack=[])
213
184
 
214
- #print "le(): "; Raabro.pp(self, colors: true)
185
+ #print 'le(): '; Raabro.pp(self, colors: true)
215
186
  return nil if @result != 0
216
187
  return [ self, stack ] if @children.empty?
217
188
  @children.each { |c|
@@ -287,10 +258,11 @@ module Raabro
287
258
  # so that :plus and co can be overriden
288
259
 
289
260
  case parser
290
- when '?', :q, :qmark then [ 0, 1 ]
291
- when '*', :s, :star then [ 0, 0 ]
292
- when '+', :p, :plus then [ 1, 0 ]
293
- else nil
261
+ when '?', :q, :qmark then [ 0, 1 ]
262
+ when '*', :s, :star then [ 0, 0 ]
263
+ when '+', :p, :plus then [ 1, 0 ]
264
+ when '!' then :bang
265
+ else nil
294
266
  end
295
267
  end
296
268
 
@@ -322,7 +294,11 @@ module Raabro
322
294
  pa = parsers.shift
323
295
  break unless pa
324
296
 
325
- if q = _quantify(parsers.first)
297
+ if parsers.first == '!'
298
+ parsers.shift
299
+ c = nott(nil, input, pa)
300
+ r.children << c
301
+ elsif q = _quantify(parsers.first)
326
302
  parsers.shift
327
303
  c = rep(nil, input, pa, *q)
328
304
  r.children.concat(c.children)
@@ -433,6 +409,22 @@ module Raabro
433
409
  end
434
410
  alias rename ren
435
411
 
412
+ def nott(name, input, parser)
413
+
414
+ start = input.offset
415
+
416
+ r = ::Raabro::Tree.new(name, :nott, input)
417
+ c = _parse(parser, input)
418
+ r.children << c
419
+
420
+ r.length = 0
421
+ r.result = c.result == 1 ? 0 : 1
422
+
423
+ input.offset = start
424
+
425
+ r
426
+ end
427
+
436
428
  def all(name, input, parser)
437
429
 
438
430
  start = input.offset
@@ -478,8 +470,6 @@ module Raabro
478
470
 
479
471
  loop do
480
472
 
481
- add = true
482
-
483
473
  st = i > 0 ? _parse(seppa, input) : nil
484
474
  et = st == nil || st.result == 1 ? _parse(eltpa, input) : nil
485
475
 
@@ -575,7 +565,7 @@ module Raabro
575
565
 
576
566
  def rewrite(tree)
577
567
 
578
- return !! methods.find { |m| m.to_s.match(/^rewrite_/) } if tree == 0
568
+ return !! methods.find { |m| m.to_s.start_with?('rewrite_') } if tree == 0
579
569
  # return true when "rewrite_xxx" methods seem to have been provided
580
570
 
581
571
  send("rewrite_#{tree.name}", tree)
@@ -9,9 +9,8 @@ Gem::Specification.new do |s|
9
9
 
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.authors = [ 'John Mettraux' ]
12
- s.email = [ 'jmettraux@gmail.com' ]
13
- s.homepage = 'http://github.com/jmettraux/raabro'
14
- #s.rubyforge_project = 'rufus'
12
+ s.email = [ 'jmettraux+flor@gmail.com' ]
13
+ s.homepage = 'http://github.com/floraison/raabro'
15
14
  s.license = 'MIT'
16
15
  s.summary = 'a very dumb PEG parser library'
17
16
 
@@ -30,7 +29,7 @@ A very dumb PEG parser library, with a horrible interface.
30
29
 
31
30
  #s.add_runtime_dependency 'tzinfo'
32
31
 
33
- s.add_development_dependency 'rspec', '~> 3.4.0'
32
+ s.add_development_dependency 'rspec', '~> 3.7'
34
33
 
35
34
  s.require_path = 'lib'
36
35
  end
metadata CHANGED
@@ -1,68 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raabro
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
5
- prerelease:
4
+ version: 1.3.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - John Mettraux
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2020-09-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 3.4.0
19
+ version: '3.7'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 3.4.0
26
+ version: '3.7'
30
27
  description: A very dumb PEG parser library, with a horrible interface.
31
28
  email:
32
- - jmettraux@gmail.com
29
+ - jmettraux+flor@gmail.com
33
30
  executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - README.md
38
34
  - CHANGELOG.md
35
+ - CREDITS.md
39
36
  - LICENSE.txt
40
37
  - Makefile
38
+ - README.md
41
39
  - lib/raabro.rb
42
40
  - raabro.gemspec
43
- homepage: http://github.com/jmettraux/raabro
41
+ homepage: http://github.com/floraison/raabro
44
42
  licenses:
45
43
  - MIT
44
+ metadata: {}
46
45
  post_install_message:
47
46
  rdoc_options: []
48
47
  require_paths:
49
48
  - lib
50
49
  required_ruby_version: !ruby/object:Gem::Requirement
51
- none: false
52
50
  requirements:
53
- - - ! '>='
51
+ - - ">="
54
52
  - !ruby/object:Gem::Version
55
53
  version: '0'
56
54
  required_rubygems_version: !ruby/object:Gem::Requirement
57
- none: false
58
55
  requirements:
59
- - - ! '>='
56
+ - - ">="
60
57
  - !ruby/object:Gem::Version
61
58
  version: '0'
62
59
  requirements: []
63
- rubyforge_project:
64
- rubygems_version: 1.8.23.2
60
+ rubygems_version: 3.0.3
65
61
  signing_key:
66
- specification_version: 3
62
+ specification_version: 4
67
63
  summary: a very dumb PEG parser library
68
64
  test_files: []