parser_combinator 0.0.1 → 0.0.2
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/Rakefile +7 -0
- data/lib/parser_combinator/version.rb +1 -1
- data/lib/parser_combinator.rb +31 -8
- 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: d456efcd3b6e21d8ab0d1c0622247276f86a8ddf
|
4
|
+
data.tar.gz: 7a565356e08db305a2a0c020e549de9df6bcded9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9ed18d16f6bfc022f518cf70f41d93fa6a591945022b008f0282f69210efe2b98bf80bb07d49d1cce7b7880ecb1ddb7a98b26e0969509a32191059aecb3f923
|
7
|
+
data.tar.gz: db4e7c2760fea42ab14e77136b871864254a5e30e99e82b50986f2af6e95ca7836b410e09c43ef14b1b74721337de39496fbbb59ce42dc47d8a6755ad6f432d1
|
data/Rakefile
CHANGED
data/lib/parser_combinator.rb
CHANGED
@@ -97,9 +97,8 @@ class ParserCombinator
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
def initialize(status_handler=nil, name=nil &proc)
|
100
|
+
attr_reader :status_handler, :parser_name, :parser_proc
|
101
|
+
def initialize(status_handler=proc{nil}, name=nil, &proc)
|
103
102
|
@status_handler = status_handler
|
104
103
|
@parser_name = name
|
105
104
|
@parser_proc = proc
|
@@ -107,10 +106,17 @@ class ParserCombinator
|
|
107
106
|
|
108
107
|
def parse(items)
|
109
108
|
result = @parser_proc.call(items)
|
110
|
-
|
111
|
-
|
112
|
-
|
109
|
+
case result
|
110
|
+
when Fail
|
111
|
+
if @status_handler.call(items, result.status) != nil
|
112
|
+
result.class.new(@status_handler.call(items, result.status))
|
113
|
+
else
|
114
|
+
result
|
115
|
+
end
|
116
|
+
when Ok
|
113
117
|
result
|
118
|
+
else
|
119
|
+
raise "parsed object is #{result.inspect}/#{result.class}"
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
@@ -125,6 +131,13 @@ class ParserCombinator
|
|
125
131
|
end
|
126
132
|
end
|
127
133
|
|
134
|
+
def onparse(&proc)
|
135
|
+
self.class.new(@status_handler, @parser_name) do |*args|
|
136
|
+
proc.call(*args)
|
137
|
+
@parser_proc.call(*args)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
128
141
|
def name(new_name)
|
129
142
|
self.class.new(@status_handler, new_name, &parser_proc)
|
130
143
|
end
|
@@ -171,6 +184,8 @@ class ParserCombinator
|
|
171
184
|
result
|
172
185
|
when Ok
|
173
186
|
continuation_proc.call(result.parsed).parse(result.rest)
|
187
|
+
else
|
188
|
+
raise "error"
|
174
189
|
end
|
175
190
|
}
|
176
191
|
end
|
@@ -182,6 +197,8 @@ class ParserCombinator
|
|
182
197
|
parser2.parse(i)
|
183
198
|
when Ok
|
184
199
|
result1
|
200
|
+
else
|
201
|
+
raise "error"
|
185
202
|
end
|
186
203
|
}
|
187
204
|
end
|
@@ -197,6 +214,8 @@ class ParserCombinator
|
|
197
214
|
end
|
198
215
|
when Ok
|
199
216
|
result1
|
217
|
+
else
|
218
|
+
raise "error"
|
200
219
|
end
|
201
220
|
}
|
202
221
|
end
|
@@ -305,8 +324,12 @@ class ParserCombinator
|
|
305
324
|
if @cache[key]
|
306
325
|
return @cache[key]
|
307
326
|
else
|
308
|
-
|
309
|
-
|
327
|
+
status_handler = proc{ raise "this is never-called proc (status_handler)" }
|
328
|
+
parser_proc = proc{ raise "this is never-called proc (parser_proc)" }
|
329
|
+
@cache[key] = self.new(proc{|*args| status_handler.call(*args)}){|*args| parser_proc.call(*args)}
|
330
|
+
generated_parser = proc.call(*args)
|
331
|
+
parser_proc = generated_parser.parser_proc
|
332
|
+
status_handler = generated_parser.status_handler
|
310
333
|
return @cache[key]
|
311
334
|
end
|
312
335
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parser_combinator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kensuke Sawada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|