radd_djur 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -2
- data/lib/radd_djur/dsl.rb +21 -0
- data/lib/radd_djur/grammar.rb +15 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a42890f07e0cbcca892af8f2ae54374c34a4c1a0
|
4
|
+
data.tar.gz: f19ac74763ed3f23d2dd52198b457c03203253ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99ee8d2eca9c7a9ca943586bb9db2229e364e6804674a718b059f05a792267eb4137b58501eef70a765575ac0ce3dc841f6ab705ac3c211d04e9963139bd6a27
|
7
|
+
data.tar.gz: f6c97cd1f7d987e3c0e1329c73d32080470f63dbde20b33b49b529a285f7e89609d6c25a37f38db3ba5d4d7595c48aa794f1acf6609c29d131fefbdb4a0e9971
|
data/README.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
radd\_djur - Packrat parser combinator library for Ruby
|
2
2
|
=======================================================
|
3
3
|
|
4
|
-
|
4
|
+
Packrat parser combinator library for Ruby
|
5
|
+
|
6
|
+
[![Build Status](https://secure.travis-ci.org/shugo/radd_djur.png)](http://travis-ci.org/shugo/radd_djur)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/radd_djur.png)](http://badge.fury.io/rb/radd_djur)
|
8
|
+
[![Dependency Status](https://gemnasium.com/shugo/radd_djur.svg)](https://gemnasium.com/shugo/radd_djur)
|
5
9
|
|
6
10
|
Install
|
7
11
|
-------
|
@@ -13,7 +17,7 @@ $ gem install radd_djur
|
|
13
17
|
Documentation
|
14
18
|
-------------
|
15
19
|
|
16
|
-
* [API Reference](http://rubydoc.info/github/shugo/radd_djur/
|
20
|
+
* [API Reference](http://www.rubydoc.info/github/shugo/radd_djur/master)
|
17
21
|
|
18
22
|
Example
|
19
23
|
-------
|
@@ -74,6 +78,15 @@ Example
|
|
74
78
|
}
|
75
79
|
p g.parse("2*(3+4)")
|
76
80
|
|
81
|
+
The above rules can be simplified using Array:
|
82
|
+
|
83
|
+
# additive <- multitive '+' additive / multitive
|
84
|
+
define :additive do
|
85
|
+
[:multitive, "+", :additive].bind { |x, *, y|
|
86
|
+
ret x + y
|
87
|
+
} / :multitive
|
88
|
+
end
|
89
|
+
|
77
90
|
License
|
78
91
|
-------
|
79
92
|
|
data/lib/radd_djur/dsl.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module RaddDjur
|
2
2
|
module DSL
|
3
|
+
include Immutable
|
4
|
+
|
3
5
|
refine Object do
|
4
6
|
def bind(&block)
|
5
7
|
to_parser.bind(&block)
|
@@ -49,5 +51,24 @@ module RaddDjur
|
|
49
51
|
}
|
50
52
|
end
|
51
53
|
end
|
54
|
+
|
55
|
+
refine Array do
|
56
|
+
def bind(&block)
|
57
|
+
list = List.from_array(self)
|
58
|
+
bind_list(list, List[], block)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def bind_list(list, args, block)
|
64
|
+
if list.empty?
|
65
|
+
block.call(*args.reverse.to_a)
|
66
|
+
else
|
67
|
+
list.head.bind { |x|
|
68
|
+
bind_list(list.tail, Cons[x, args], block)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
52
73
|
end
|
53
74
|
end
|
data/lib/radd_djur/grammar.rb
CHANGED
@@ -5,6 +5,14 @@ using RaddDjur::DSL
|
|
5
5
|
|
6
6
|
module RaddDjur
|
7
7
|
class Grammar
|
8
|
+
INSTANCE_EVAL_USING_AVAILABLE =
|
9
|
+
begin
|
10
|
+
instance_eval(using: RaddDjur::DSL) {}
|
11
|
+
true
|
12
|
+
rescue
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
8
16
|
class Result
|
9
17
|
end
|
10
18
|
|
@@ -165,7 +173,13 @@ module RaddDjur
|
|
165
173
|
def initialize(start_symbol, &block)
|
166
174
|
@parsers = {}
|
167
175
|
@start_symbol = start_symbol
|
168
|
-
|
176
|
+
if block
|
177
|
+
if INSTANCE_EVAL_USING_AVAILABLE
|
178
|
+
instance_eval(using: RaddDjur::DSL, &block)
|
179
|
+
else
|
180
|
+
instance_eval(&block)
|
181
|
+
end
|
182
|
+
end
|
169
183
|
end
|
170
184
|
|
171
185
|
def parse(str)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radd_djur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shugo Maeda
|
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
55
|
rubyforge_project:
|
56
|
-
rubygems_version: 2.
|
56
|
+
rubygems_version: 2.6.6
|
57
57
|
signing_key:
|
58
58
|
specification_version: 4
|
59
59
|
summary: Packrat parser combinator library for Ruby
|