raabro 1.1.6 → 1.3.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 +5 -5
- data/CHANGELOG.md +7 -0
- data/LICENSE.txt +1 -1
- data/Makefile +1 -1
- data/README.md +25 -9
- data/lib/raabro.rb +21 -10
- data/raabro.gemspec +0 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 72a0f2a013fa2997e7c6e8edd1a821634dba5b593afdfb00369add4b257f3015
|
4
|
+
data.tar.gz: 4a62a9fcdb3571eab480dde394269c85768c9c6e48e6b07e4891032982ea970d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab5adf883c241fefde881980f4b9783d26d49cbb651058803f1ee888d0e0eb7aa4ba6276c05e795eaa7bcae9d9b4c245add84d61e0f48ee1c720c5bc16eff7d
|
7
|
+
data.tar.gz: 139efc8e983e62d9d0911e7dd25276171948ea453c6caaf950fa67107d5b724ffb81dab705151ae77727e7b2a7b93688328339e4613ce4ceda32ad2748d74559
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
# raabro CHANGELOG.md
|
3
3
|
|
4
4
|
|
5
|
+
## raabro 1.3.0 released 2020-05-10
|
6
|
+
|
7
|
+
* Add `nott` parser element
|
8
|
+
* Add Tree#strinp and #strim
|
9
|
+
* Skip 1.2.0 to align on http://github.com/jmettraux/jaabro
|
10
|
+
|
11
|
+
|
5
12
|
## raabro 1.1.6 released 2018-06-22
|
6
13
|
|
7
14
|
* Remove unused `add` var, gh-2, thanks to https://github.com/utilum
|
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
|
|
data/lib/raabro.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Raabro
|
3
3
|
|
4
|
-
VERSION = '1.
|
4
|
+
VERSION = '1.3.0'
|
5
5
|
|
6
6
|
class Input
|
7
7
|
|
@@ -78,15 +78,10 @@ module Raabro
|
|
78
78
|
@children = successful_children
|
79
79
|
end
|
80
80
|
|
81
|
-
def string
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
def nonstring(l=7)
|
87
|
-
|
88
|
-
@input.string[@offset, l]
|
89
|
-
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
|
90
85
|
|
91
86
|
def lookup(name=nil)
|
92
87
|
|
@@ -409,6 +404,22 @@ module Raabro
|
|
409
404
|
end
|
410
405
|
alias rename ren
|
411
406
|
|
407
|
+
def nott(name, input, parser)
|
408
|
+
|
409
|
+
start = input.offset
|
410
|
+
|
411
|
+
r = ::Raabro::Tree.new(name, :nott, input)
|
412
|
+
c = _parse(parser, input)
|
413
|
+
r.children << c
|
414
|
+
|
415
|
+
r.length = 0
|
416
|
+
r.result = c.result == 1 ? 0 : 1
|
417
|
+
|
418
|
+
input.offset = start
|
419
|
+
|
420
|
+
r
|
421
|
+
end
|
422
|
+
|
412
423
|
def all(name, input, parser)
|
413
424
|
|
414
425
|
start = input.offset
|
data/raabro.gemspec
CHANGED
@@ -11,7 +11,6 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.authors = [ 'John Mettraux' ]
|
12
12
|
s.email = [ 'jmettraux+flor@gmail.com' ]
|
13
13
|
s.homepage = 'http://github.com/floraison/raabro'
|
14
|
-
#s.rubyforge_project = 'rufus'
|
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.3.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-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -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
|