raabro 1.1.6 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +28 -0
- data/CREDITS.md +1 -0
- data/LICENSE.txt +1 -1
- data/Makefile +1 -1
- data/README.md +37 -9
- data/lib/raabro.rb +63 -27
- data/raabro.gemspec +1 -2
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c97c1720256a9bd016f9a3644bf6a0a407afde36122fe666a415f65d8f11fa2
|
4
|
+
data.tar.gz: 0e52242404f2309cbccfd92f7ee1d4ef06777c883d1c40254bddcf033a63752e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa0aebdcbfaeadd23dfd1ac8c442e52b839bced502c0ae144c5562bc97fc0e2a54c3114b0e048f47fdcb46c8ac2a7def92b7cd6169256195957bb7acbd65a9a6
|
7
|
+
data.tar.gz: e9c3eab148ede2853cafa1ec3fceec9967af83b4c3453017666f01741a0d51cb5eb200dde64e5d7c62ede442768b5f861a3a8bdb5587ded9a6a5afde73844b05
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,34 @@
|
|
2
2
|
# raabro CHANGELOG.md
|
3
3
|
|
4
4
|
|
5
|
+
## raabro 1.4.0 released 2020-10-06
|
6
|
+
|
7
|
+
* Ensure that jseq, for n elts, parses n-1 separators
|
8
|
+
* Introduce Tree #symbol, #symbod, #strind and #strinpd
|
9
|
+
|
10
|
+
|
11
|
+
## raabro 1.3.3 released 2020-09-24
|
12
|
+
|
13
|
+
* Merge Henrik's rewrite_ optimization
|
14
|
+
|
15
|
+
|
16
|
+
## raabro 1.3.2 released 2020-09-24
|
17
|
+
|
18
|
+
* Make a tiny rewrite_ optimization
|
19
|
+
|
20
|
+
|
21
|
+
## raabro 1.3.1 released 2020-05-10
|
22
|
+
|
23
|
+
* Add '!' (not) seq quantifier
|
24
|
+
|
25
|
+
|
26
|
+
## raabro 1.3.0 released 2020-05-10
|
27
|
+
|
28
|
+
* Add `nott` parser element
|
29
|
+
* Add Tree#strinp and #strim
|
30
|
+
* Skip 1.2.0 to align on http://github.com/jmettraux/jaabro
|
31
|
+
|
32
|
+
|
5
33
|
## raabro 1.1.6 released 2018-06-22
|
6
34
|
|
7
35
|
* Remove unused `add` var, gh-2, thanks to https://github.com/utilum
|
data/CREDITS.md
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Copyright (c) 2015-
|
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
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -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
|
31
|
-
def
|
32
|
-
|
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
|
-
|
54
|
-
t.children
|
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
|
|
data/lib/raabro.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module Raabro
|
3
4
|
|
4
|
-
VERSION = '1.
|
5
|
+
VERSION = '1.4.0'
|
5
6
|
|
6
7
|
class Input
|
7
8
|
|
@@ -78,15 +79,19 @@ module Raabro
|
|
78
79
|
@children = successful_children
|
79
80
|
end
|
80
81
|
|
81
|
-
def string
|
82
|
+
def string; @input.string[@offset, @length]; end
|
83
|
+
def strinp; string.strip; end
|
84
|
+
alias strim strinp
|
85
|
+
def nonstring(l=7); @input.string[@offset, l]; end
|
82
86
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
+
def stringd; string.downcase; end
|
88
|
+
alias strind stringd
|
89
|
+
def stringpd; strinp.downcase; end
|
90
|
+
alias strinpd stringpd
|
87
91
|
|
88
|
-
|
89
|
-
end
|
92
|
+
def symbol; strinp.to_sym; end
|
93
|
+
def symbold; symbol.downcase; end
|
94
|
+
alias symbod symbold
|
90
95
|
|
91
96
|
def lookup(name=nil)
|
92
97
|
|
@@ -177,7 +182,7 @@ module Raabro
|
|
177
182
|
.collect(&:inspect).join('/')
|
178
183
|
"parsing failed .../#{path}"
|
179
184
|
else
|
180
|
-
|
185
|
+
'parsing failed, not all input was consumed'
|
181
186
|
end
|
182
187
|
visual =
|
183
188
|
visual(line, column)
|
@@ -187,7 +192,7 @@ module Raabro
|
|
187
192
|
|
188
193
|
def lookup_error(stack=[])
|
189
194
|
|
190
|
-
#print
|
195
|
+
#print 'le(): '; Raabro.pp(self, colors: true)
|
191
196
|
return nil if @result != 0
|
192
197
|
return [ self, stack ] if @children.empty?
|
193
198
|
@children.each { |c|
|
@@ -263,10 +268,11 @@ module Raabro
|
|
263
268
|
# so that :plus and co can be overriden
|
264
269
|
|
265
270
|
case parser
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
271
|
+
when '?', :q, :qmark then [ 0, 1 ]
|
272
|
+
when '*', :s, :star then [ 0, 0 ]
|
273
|
+
when '+', :p, :plus then [ 1, 0 ]
|
274
|
+
when '!' then :bang
|
275
|
+
else nil
|
270
276
|
end
|
271
277
|
end
|
272
278
|
|
@@ -298,7 +304,11 @@ module Raabro
|
|
298
304
|
pa = parsers.shift
|
299
305
|
break unless pa
|
300
306
|
|
301
|
-
if
|
307
|
+
if parsers.first == '!'
|
308
|
+
parsers.shift
|
309
|
+
c = nott(nil, input, pa)
|
310
|
+
r.children << c
|
311
|
+
elsif q = _quantify(parsers.first)
|
302
312
|
parsers.shift
|
303
313
|
c = rep(nil, input, pa, *q)
|
304
314
|
r.children.concat(c.children)
|
@@ -409,6 +419,22 @@ module Raabro
|
|
409
419
|
end
|
410
420
|
alias rename ren
|
411
421
|
|
422
|
+
def nott(name, input, parser)
|
423
|
+
|
424
|
+
start = input.offset
|
425
|
+
|
426
|
+
r = ::Raabro::Tree.new(name, :nott, input)
|
427
|
+
c = _parse(parser, input)
|
428
|
+
r.children << c
|
429
|
+
|
430
|
+
r.length = 0
|
431
|
+
r.result = c.result == 1 ? 0 : 1
|
432
|
+
|
433
|
+
input.offset = start
|
434
|
+
|
435
|
+
r
|
436
|
+
end
|
437
|
+
|
412
438
|
def all(name, input, parser)
|
413
439
|
|
414
440
|
start = input.offset
|
@@ -450,26 +476,36 @@ module Raabro
|
|
450
476
|
|
451
477
|
if r.result == 1
|
452
478
|
|
453
|
-
|
479
|
+
on_elt = false
|
480
|
+
count = 0
|
481
|
+
empty_stack = 0
|
454
482
|
|
455
483
|
loop do
|
456
484
|
|
457
|
-
|
458
|
-
et = st == nil || st.result == 1 ? _parse(eltpa, input) : nil
|
485
|
+
on_elt = ! on_elt
|
459
486
|
|
460
|
-
|
461
|
-
break if st && et && st.empty? && et.empty?
|
487
|
+
cr = _parse(on_elt ? eltpa : seppa, input)
|
462
488
|
|
463
|
-
|
464
|
-
|
489
|
+
empty_stack = cr.empty? ? empty_stack + 1 : 0
|
490
|
+
cr.result = 0 if empty_stack > 1
|
491
|
+
#
|
492
|
+
# prevent "no progress"
|
465
493
|
|
466
|
-
|
467
|
-
|
494
|
+
r.children.push(cr)
|
495
|
+
|
496
|
+
if cr.result != 1
|
497
|
+
if on_elt && count > 0
|
498
|
+
lsep = r.children[-2]
|
499
|
+
lsep.result = 0
|
500
|
+
input.offset = lsep.offset
|
501
|
+
end
|
502
|
+
break
|
503
|
+
end
|
468
504
|
|
469
|
-
|
505
|
+
count += 1
|
470
506
|
end
|
471
507
|
|
472
|
-
r.result = 0 if jseq &&
|
508
|
+
r.result = 0 if jseq && count < 1
|
473
509
|
end
|
474
510
|
|
475
511
|
if r.result == 1 && endpa
|
@@ -549,7 +585,7 @@ module Raabro
|
|
549
585
|
|
550
586
|
def rewrite(tree)
|
551
587
|
|
552
|
-
return !! methods.find { |m| m.to_s.
|
588
|
+
return !! methods.find { |m| m.to_s.start_with?('rewrite_') } if tree == 0
|
553
589
|
# return true when "rewrite_xxx" methods seem to have been provided
|
554
590
|
|
555
591
|
send("rewrite_#{tree.name}", tree)
|
data/raabro.gemspec
CHANGED
@@ -10,8 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.authors = [ 'John Mettraux' ]
|
12
12
|
s.email = [ 'jmettraux+flor@gmail.com' ]
|
13
|
-
s.homepage = '
|
14
|
-
#s.rubyforge_project = 'rufus'
|
13
|
+
s.homepage = 'https://github.com/floraison/raabro'
|
15
14
|
s.license = 'MIT'
|
16
15
|
s.summary = 'a very dumb PEG parser library'
|
17
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raabro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -38,7 +38,7 @@ files:
|
|
38
38
|
- README.md
|
39
39
|
- lib/raabro.rb
|
40
40
|
- raabro.gemspec
|
41
|
-
homepage:
|
41
|
+
homepage: https://github.com/floraison/raabro
|
42
42
|
licenses:
|
43
43
|
- MIT
|
44
44
|
metadata: {}
|
@@ -57,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
|
-
|
61
|
-
rubygems_version: 2.5.2
|
60
|
+
rubygems_version: 3.0.3
|
62
61
|
signing_key:
|
63
62
|
specification_version: 4
|
64
63
|
summary: a very dumb PEG parser library
|