tdparser 1.5.1 → 1.6.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README +5 -0
- data/Rakefile +4 -0
- data/lib/tdparser/action_parser.rb +29 -0
- data/lib/tdparser/any_parser.rb +20 -0
- data/lib/tdparser/backref_parser.rb +29 -0
- data/lib/tdparser/buffer_utils.rb +13 -0
- data/lib/tdparser/choice_parser.rb +80 -0
- data/lib/tdparser/composite_parser.rb +29 -0
- data/lib/tdparser/concat_parser.rb +21 -0
- data/lib/tdparser/condition_parser.rb +28 -0
- data/lib/tdparser/empty_parser.rb +15 -0
- data/lib/tdparser/fail_parser.rb +15 -0
- data/lib/tdparser/grammar.rb +23 -0
- data/lib/tdparser/iteration_parser.rb +73 -0
- data/lib/tdparser/label_parser.rb +25 -0
- data/lib/tdparser/negative_parser.rb +17 -0
- data/lib/tdparser/non_terminal_parser.rb +33 -0
- data/lib/tdparser/none_parser.rb +18 -0
- data/lib/tdparser/parallel_parser.rb +18 -0
- data/lib/tdparser/parser.rb +104 -0
- data/lib/tdparser/reference_parser.rb +23 -0
- data/lib/tdparser/sequence.rb +7 -0
- data/lib/tdparser/stack_parser.rb +29 -0
- data/lib/tdparser/stackref_parser.rb +29 -0
- data/lib/tdparser/state_parser.rb +28 -0
- data/lib/tdparser/terminal_parser.rb +28 -0
- data/lib/tdparser/token_buffer.rb +43 -0
- data/lib/tdparser/token_generator.rb +43 -0
- data/lib/tdparser/utils.rb +3 -3
- data/lib/tdparser/version.rb +1 -1
- data/lib/tdparser/xml.rb +13 -11
- data/lib/tdparser.rb +45 -799
- data/sig/tdparser.rbs +334 -0
- data/updoc +11 -0
- metadata +32 -4
data/sig/tdparser.rbs
ADDED
@@ -0,0 +1,334 @@
|
|
1
|
+
module TDParser
|
2
|
+
ParserException: Class | singleton(RuntimeError)
|
3
|
+
VERSION: String
|
4
|
+
include BufferUtils
|
5
|
+
|
6
|
+
def rule: (untyped sym, *untyped opts) -> NonTerminalParser
|
7
|
+
def token: (untyped x, ?:=== eqsym) -> TerminalParser
|
8
|
+
|
9
|
+
def back_ref: (untyped x, ?:=== eqsym) -> BackrefParser
|
10
|
+
alias backref back_ref
|
11
|
+
|
12
|
+
def stack_ref: (untyped stack, ?:=== eqsym) -> StackrefParser
|
13
|
+
alias stackref stack_ref
|
14
|
+
|
15
|
+
def state: (untyped s) -> StateParser
|
16
|
+
|
17
|
+
def empty_rule: -> EmptyParser
|
18
|
+
alias empty empty_rule
|
19
|
+
|
20
|
+
def any_rule: -> AnyParser
|
21
|
+
alias any any_rule
|
22
|
+
|
23
|
+
def none_rule: -> NoneParser
|
24
|
+
alias none none_rule
|
25
|
+
|
26
|
+
def fail_rule: -> FailParser
|
27
|
+
alias fail fail_rule
|
28
|
+
|
29
|
+
def condition_rule: -> ConditionParser
|
30
|
+
alias condition condition_rule
|
31
|
+
|
32
|
+
def left_rec: (*untyped rules) -> FailParser
|
33
|
+
alias leftrec left_rec
|
34
|
+
|
35
|
+
def right_rec: (*untyped rules) -> FailParser
|
36
|
+
alias rightrec right_rec
|
37
|
+
|
38
|
+
def chain_left: (untyped base, *untyped infixes) -> untyped
|
39
|
+
alias chainl chain_left
|
40
|
+
|
41
|
+
def chain_right: (untyped base, *untyped infixes) -> untyped
|
42
|
+
alias chainr chain_right
|
43
|
+
|
44
|
+
def self.define: (*untyped _args) -> untyped
|
45
|
+
|
46
|
+
class Token
|
47
|
+
attr_accessor kind: untyped
|
48
|
+
attr_accessor value: String
|
49
|
+
def initialize: (untyped kind, String value) -> void
|
50
|
+
def ==: (untyped other) -> bool
|
51
|
+
def ===: (untyped other) -> true
|
52
|
+
def =~: (untyped other) -> untyped
|
53
|
+
end
|
54
|
+
|
55
|
+
class BasicStringTokenizer
|
56
|
+
@rule: untyped
|
57
|
+
@scan_pattern: Regexp
|
58
|
+
@ignore_pattern: Regexp?
|
59
|
+
|
60
|
+
def self.[]: (untyped rule, ?nil ignore) -> BasicStringTokenizer
|
61
|
+
def initialize: (untyped rule, ?Regexp? ignore) -> void
|
62
|
+
def generate: (untyped str) -> untyped
|
63
|
+
end
|
64
|
+
|
65
|
+
class StringTokenizer < BasicStringTokenizer
|
66
|
+
def initialize: (untyped rule, ?nil ignore) -> void
|
67
|
+
end
|
68
|
+
|
69
|
+
class WaitingTokenGenerator
|
70
|
+
@terminated: bool
|
71
|
+
|
72
|
+
def initialize: (*untyped args) -> void
|
73
|
+
def terminate: -> true
|
74
|
+
def shift: -> nil
|
75
|
+
end
|
76
|
+
|
77
|
+
module XMLParser
|
78
|
+
XMLTokenGenerator: singleton(XMLTokenGenerator) | singleton(XMLTokenGenerator)
|
79
|
+
|
80
|
+
def start_element: (?singleton(String) name) -> untyped
|
81
|
+
def end_element: (?singleton(String) name) -> untyped
|
82
|
+
def element: (?singleton(String) elem) -> untyped
|
83
|
+
def text: (?singleton(String) match) -> untyped
|
84
|
+
def pi: -> untyped
|
85
|
+
def cdata: (?singleton(String) match) -> untyped
|
86
|
+
def comment: (?singleton(String) match) -> untyped
|
87
|
+
def xmldecl: -> untyped
|
88
|
+
def start_doctype: (?singleton(String) name) -> untyped
|
89
|
+
def end_doctype: -> untyped
|
90
|
+
def doctype: (?singleton(String) name) -> untyped
|
91
|
+
def externalentity: (?singleton(String) entity) -> untyped
|
92
|
+
def elementdecl: (?singleton(String) elem) -> untyped
|
93
|
+
def entitydecl: (?singleton(String) _entity) -> untyped
|
94
|
+
def attlistdecl: (?singleton(String) _decl) -> untyped
|
95
|
+
def notationdecl: (?singleton(String) _decl) -> untyped
|
96
|
+
def any_node: -> untyped
|
97
|
+
def dom_constructor: -> untyped
|
98
|
+
|
99
|
+
class XArray < Array[untyped]
|
100
|
+
def ===: (untyped ary) -> bool
|
101
|
+
end
|
102
|
+
|
103
|
+
class XHash < Hash[untyped, untyped]
|
104
|
+
def ===: (untyped h) -> bool
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class TokenGenerator
|
109
|
+
@enumerator: Enumerator[bot, bot]
|
110
|
+
@buffer: Array[untyped]
|
111
|
+
|
112
|
+
def initialize: (?nil args) -> void
|
113
|
+
def next: -> bot
|
114
|
+
def next?: -> false
|
115
|
+
def to_a: -> Array[untyped]
|
116
|
+
def shift: -> nil
|
117
|
+
def unshift: (*untyped token) -> Array[untyped]
|
118
|
+
end
|
119
|
+
|
120
|
+
class TokenBuffer
|
121
|
+
extend Forwardable
|
122
|
+
# include Enumerable # TODO: Somehow cause error.
|
123
|
+
@array: Array[untyped]
|
124
|
+
|
125
|
+
attr_accessor map: Hash[untyped, untyped]
|
126
|
+
attr_accessor state: untyped
|
127
|
+
def initialize: (*untyped args) -> void
|
128
|
+
def []: (untyped idx) -> nil
|
129
|
+
def []=: (untyped idx, untyped val) -> untyped
|
130
|
+
def clear: -> void
|
131
|
+
alias self.[] self.new
|
132
|
+
end
|
133
|
+
|
134
|
+
class Sequence < Array[untyped]
|
135
|
+
def +: (untyped other) -> Sequence
|
136
|
+
end
|
137
|
+
|
138
|
+
module BufferUtils
|
139
|
+
def prepare: (TokenBuffer? buff) -> TokenBuffer
|
140
|
+
def recover: (TokenBuffer? buff, untyped ts) -> TokenBuffer
|
141
|
+
end
|
142
|
+
|
143
|
+
class Parser
|
144
|
+
include TDParser
|
145
|
+
include BufferUtils
|
146
|
+
@tokens: nil
|
147
|
+
|
148
|
+
def to_proc: -> ^(*untyped) -> nil
|
149
|
+
def to_s: -> String
|
150
|
+
def call: (*TokenBuffer? args) -> nil
|
151
|
+
def optimize: (?false _default) -> Parser
|
152
|
+
def ==: ((ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser)? _other) -> false
|
153
|
+
def same?: ((ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser)? r) -> bool
|
154
|
+
def -: (ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser other) -> ConcatParser
|
155
|
+
def +: (ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser other) -> ParallelParser
|
156
|
+
def |: (untyped other) -> (ActionParser | ChoiceParser | ConcatParser | ParallelParser)
|
157
|
+
def *: (untyped other) -> IterationParser
|
158
|
+
def >>: (^(Array[untyped]) -> nil? other) -> ActionParser
|
159
|
+
def /: (untyped other) -> LabelParser
|
160
|
+
def %: (untyped other) -> StackParser
|
161
|
+
def >: (untyped other) -> Parser
|
162
|
+
def ~: -> NegativeParser
|
163
|
+
def parse: (?nil tokens, ?nil buff) -> nil
|
164
|
+
def peek: -> untyped
|
165
|
+
def do: -> ActionParser
|
166
|
+
end
|
167
|
+
|
168
|
+
class NonTerminalParser < Parser
|
169
|
+
attr_reader context: Grammar | TDParser
|
170
|
+
attr_reader symbol: untyped
|
171
|
+
attr_reader options: Array[untyped]
|
172
|
+
def initialize: (Grammar | TDParser context, untyped sym, *untyped options) -> void
|
173
|
+
def call: (untyped tokens, untyped buff) -> nil
|
174
|
+
def ==: (untyped other) -> bool
|
175
|
+
def to_s: -> untyped
|
176
|
+
end
|
177
|
+
|
178
|
+
class TerminalParser < Parser
|
179
|
+
attr_reader symbol: untyped
|
180
|
+
attr_reader equality: :===
|
181
|
+
def initialize: (untyped obj, :=== eqsym) -> void
|
182
|
+
def call: (untyped tokens, untyped buff) -> Array[untyped]?
|
183
|
+
def ==: (untyped other) -> bool
|
184
|
+
def to_s: -> untyped
|
185
|
+
end
|
186
|
+
|
187
|
+
class CompositeParser < Parser
|
188
|
+
attr_accessor parsers: Array[ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser]
|
189
|
+
def initialize: (*ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser parsers) -> void
|
190
|
+
def optimize: (?false default) -> (ActionParser | ChoiceParser | ConcatParser | ParallelParser)
|
191
|
+
def ==: ((ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser)? other) -> bool
|
192
|
+
def same?: ((ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser)? r) -> bool
|
193
|
+
def to_s: -> String
|
194
|
+
end
|
195
|
+
|
196
|
+
class ActionParser < CompositeParser
|
197
|
+
attr_reader action: ^(Array[untyped]) -> nil?
|
198
|
+
def initialize: (ConcatParser | Parser parser, ^(Array[untyped]) -> nil? act) -> void
|
199
|
+
def call: (untyped tokens, TokenBuffer? buff) -> Array[nil]?
|
200
|
+
def ==: ((ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser)? other) -> bool
|
201
|
+
def to_s: -> String
|
202
|
+
end
|
203
|
+
|
204
|
+
class LabelParser < CompositeParser
|
205
|
+
attr_reader label: untyped
|
206
|
+
def initialize: (Parser parser, untyped label) -> void
|
207
|
+
def call: (untyped tokens, untyped buff) -> Array[Array[nil]?]?
|
208
|
+
def ==: (untyped other) -> false
|
209
|
+
def to_s: -> String
|
210
|
+
end
|
211
|
+
|
212
|
+
class StackParser < CompositeParser
|
213
|
+
attr_reader stack: untyped
|
214
|
+
def initialize: (Parser parser, untyped stack) -> void
|
215
|
+
def call: (untyped tokens, untyped buff) -> Array[Array[nil]?]?
|
216
|
+
def ==: (untyped other) -> false
|
217
|
+
def same?: (untyped _r) -> false
|
218
|
+
def to_s: -> String
|
219
|
+
end
|
220
|
+
|
221
|
+
class ConcatParser < CompositeParser
|
222
|
+
def call: (untyped tokens, TokenBuffer? buff) -> Array[Array[nil]?]?
|
223
|
+
def -: (ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser other) -> ConcatParser
|
224
|
+
def to_s: -> String
|
225
|
+
end
|
226
|
+
|
227
|
+
class ChoiceParser < CompositeParser
|
228
|
+
def call: (untyped tokens, TokenBuffer? buff) -> Array[Array[nil]?]?
|
229
|
+
def to_s: -> String
|
230
|
+
def shared_sequence: (ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser r1, ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser r2) -> ([(ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser)?, ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser, ActionParser | ChoiceParser | ConcatParser | ParallelParser | Parser])
|
231
|
+
def optimize: (?bool default) -> (ActionParser | ChoiceParser | ConcatParser | ParallelParser)
|
232
|
+
end
|
233
|
+
|
234
|
+
class ParallelParser < CompositeParser
|
235
|
+
def call: (untyped tokens, TokenBuffer? buff) -> Array[Array[Array[untyped]?]]
|
236
|
+
def to_s: -> String
|
237
|
+
end
|
238
|
+
|
239
|
+
class IterationParser < CompositeParser
|
240
|
+
attr_reader min: untyped
|
241
|
+
attr_reader range: nil
|
242
|
+
def initialize: (Parser parser, untyped n, nil range) -> void
|
243
|
+
def call: (untyped ts, untyped buff) -> (Array[Array[(Array[untyped] | true)?]]?)
|
244
|
+
def to_s: -> String
|
245
|
+
def ==: (untyped other) -> bool
|
246
|
+
end
|
247
|
+
|
248
|
+
class NegativeParser < CompositeParser
|
249
|
+
def call: (untyped tokens, untyped buff) -> Array[Array[untyped]]?
|
250
|
+
def to_s: -> String
|
251
|
+
end
|
252
|
+
|
253
|
+
class FailParser < Parser
|
254
|
+
def call: (untyped _tokens, untyped _buff) -> nil
|
255
|
+
def to_s: -> String
|
256
|
+
def ==: -> bool
|
257
|
+
end
|
258
|
+
|
259
|
+
class EmptyParser < Parser
|
260
|
+
def call: (untyped _tokens, untyped _buff) -> Array[nil]
|
261
|
+
def to_s: -> String
|
262
|
+
def ==: (untyped _other) -> true
|
263
|
+
end
|
264
|
+
|
265
|
+
class AnyParser < Parser
|
266
|
+
def call: (untyped tokens, untyped _buff) -> Array[untyped]?
|
267
|
+
def to_s: -> String
|
268
|
+
def ==: (untyped _other) -> true
|
269
|
+
end
|
270
|
+
|
271
|
+
class NoneParser < Parser
|
272
|
+
def call: (untyped tokens, untyped _buff) -> Array[nil]?
|
273
|
+
def to_s: -> String
|
274
|
+
def ==: (untyped _other) -> true
|
275
|
+
end
|
276
|
+
|
277
|
+
class ReferenceParser < Parser
|
278
|
+
private
|
279
|
+
|
280
|
+
def back_ref: (untyped xs, :=== eqsym) -> untyped
|
281
|
+
alias __backref__ back_ref
|
282
|
+
|
283
|
+
def same?: (untyped _r) -> false
|
284
|
+
end
|
285
|
+
|
286
|
+
class BackrefParser < ReferenceParser
|
287
|
+
attr_reader label: untyped
|
288
|
+
attr_reader equality: :===
|
289
|
+
def initialize: (untyped label, :=== eqsym) -> void
|
290
|
+
def call: (untyped tokens, untyped buff) -> nil
|
291
|
+
def to_s: -> String
|
292
|
+
def ==: (untyped other) -> false
|
293
|
+
end
|
294
|
+
|
295
|
+
class StackrefParser < ReferenceParser
|
296
|
+
attr_reader stack: untyped
|
297
|
+
attr_reader equality: :===
|
298
|
+
def initialize: (untyped stack, :=== eqsym) -> void
|
299
|
+
def call: (untyped tokens, untyped buff) -> nil
|
300
|
+
def to_s: -> String
|
301
|
+
def ==: (untyped other) -> false
|
302
|
+
end
|
303
|
+
|
304
|
+
class ConditionParser < Parser
|
305
|
+
attr_reader condition: nil
|
306
|
+
def initialize: -> void
|
307
|
+
def call: (untyped _tokens, untyped buff) -> Array[untyped]?
|
308
|
+
def to_s: -> String
|
309
|
+
def ==: (untyped other) -> false
|
310
|
+
def same?: (untyped _r) -> false
|
311
|
+
end
|
312
|
+
|
313
|
+
class StateParser < Parser
|
314
|
+
attr_reader state: untyped
|
315
|
+
def initialize: (untyped s) -> void
|
316
|
+
def call: (untyped _tokens, untyped buff) -> Array[untyped]?
|
317
|
+
def to_s: -> String
|
318
|
+
def ==: (untyped other) -> false
|
319
|
+
def same?: (untyped _r) -> false
|
320
|
+
end
|
321
|
+
|
322
|
+
class Grammar
|
323
|
+
include TDParser
|
324
|
+
|
325
|
+
alias define instance_eval
|
326
|
+
def method_missing: (untyped sym, *untyped args) -> (NonTerminalParser | true)
|
327
|
+
end
|
328
|
+
|
329
|
+
class XMLTokenGenerator
|
330
|
+
@xparser: untyped
|
331
|
+
|
332
|
+
def initialize: (untyped src) -> void
|
333
|
+
end
|
334
|
+
end
|
data/updoc
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takaaki Tateishi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-11-
|
12
|
+
date: 2024-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: TDParser (formerly TDP4R) is a top-down parser library that consists
|
15
15
|
of parser combinators and utility functions.
|
@@ -30,6 +30,32 @@ files:
|
|
30
30
|
- doc/faq.rdoc
|
31
31
|
- doc/guide.rdoc
|
32
32
|
- lib/tdparser.rb
|
33
|
+
- lib/tdparser/action_parser.rb
|
34
|
+
- lib/tdparser/any_parser.rb
|
35
|
+
- lib/tdparser/backref_parser.rb
|
36
|
+
- lib/tdparser/buffer_utils.rb
|
37
|
+
- lib/tdparser/choice_parser.rb
|
38
|
+
- lib/tdparser/composite_parser.rb
|
39
|
+
- lib/tdparser/concat_parser.rb
|
40
|
+
- lib/tdparser/condition_parser.rb
|
41
|
+
- lib/tdparser/empty_parser.rb
|
42
|
+
- lib/tdparser/fail_parser.rb
|
43
|
+
- lib/tdparser/grammar.rb
|
44
|
+
- lib/tdparser/iteration_parser.rb
|
45
|
+
- lib/tdparser/label_parser.rb
|
46
|
+
- lib/tdparser/negative_parser.rb
|
47
|
+
- lib/tdparser/non_terminal_parser.rb
|
48
|
+
- lib/tdparser/none_parser.rb
|
49
|
+
- lib/tdparser/parallel_parser.rb
|
50
|
+
- lib/tdparser/parser.rb
|
51
|
+
- lib/tdparser/reference_parser.rb
|
52
|
+
- lib/tdparser/sequence.rb
|
53
|
+
- lib/tdparser/stack_parser.rb
|
54
|
+
- lib/tdparser/stackref_parser.rb
|
55
|
+
- lib/tdparser/state_parser.rb
|
56
|
+
- lib/tdparser/terminal_parser.rb
|
57
|
+
- lib/tdparser/token_buffer.rb
|
58
|
+
- lib/tdparser/token_generator.rb
|
33
59
|
- lib/tdparser/utils.rb
|
34
60
|
- lib/tdparser/version.rb
|
35
61
|
- lib/tdparser/xml.rb
|
@@ -43,6 +69,8 @@ files:
|
|
43
69
|
- samples/sample_list.rb
|
44
70
|
- samples/sample_optimize.rb
|
45
71
|
- samples/sample_xml.rb
|
72
|
+
- sig/tdparser.rbs
|
73
|
+
- updoc
|
46
74
|
homepage: https://git.disroot.org/gemmaro/tdparser
|
47
75
|
licenses:
|
48
76
|
- BSD-3-Clause
|
@@ -50,10 +78,10 @@ metadata:
|
|
50
78
|
rubygems_mfa_required: 'true'
|
51
79
|
bug_tracker_uri: https://git.disroot.org/gemmaro/tdparser/issues
|
52
80
|
changelog_uri: https://git.disroot.org/gemmaro/tdparser/src/branch/main/CHANGELOG.md
|
53
|
-
documentation_uri: https://
|
81
|
+
documentation_uri: https://gemmaro.github.io/tdparser
|
54
82
|
homepage_uri: https://git.disroot.org/gemmaro/tdparser
|
55
83
|
source_code_uri: https://git.disroot.org/gemmaro/tdparser
|
56
|
-
wiki_uri: https://git.disroot.org/gemmaro/tdparser
|
84
|
+
wiki_uri: https://git.disroot.org/gemmaro/tdparser/wiki
|
57
85
|
post_install_message:
|
58
86
|
rdoc_options: []
|
59
87
|
require_paths:
|