plurimath-parslet 3.0.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.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY.txt +284 -0
  3. data/LICENSE +23 -0
  4. data/README.adoc +454 -0
  5. data/Rakefile +71 -0
  6. data/lib/parslet/accelerator/application.rb +62 -0
  7. data/lib/parslet/accelerator/engine.rb +112 -0
  8. data/lib/parslet/accelerator.rb +162 -0
  9. data/lib/parslet/atoms/alternative.rb +53 -0
  10. data/lib/parslet/atoms/base.rb +157 -0
  11. data/lib/parslet/atoms/can_flatten.rb +137 -0
  12. data/lib/parslet/atoms/capture.rb +38 -0
  13. data/lib/parslet/atoms/context.rb +103 -0
  14. data/lib/parslet/atoms/dsl.rb +112 -0
  15. data/lib/parslet/atoms/dynamic.rb +32 -0
  16. data/lib/parslet/atoms/entity.rb +45 -0
  17. data/lib/parslet/atoms/ignored.rb +26 -0
  18. data/lib/parslet/atoms/infix.rb +115 -0
  19. data/lib/parslet/atoms/lookahead.rb +52 -0
  20. data/lib/parslet/atoms/named.rb +32 -0
  21. data/lib/parslet/atoms/re.rb +41 -0
  22. data/lib/parslet/atoms/repetition.rb +87 -0
  23. data/lib/parslet/atoms/scope.rb +26 -0
  24. data/lib/parslet/atoms/sequence.rb +48 -0
  25. data/lib/parslet/atoms/str.rb +42 -0
  26. data/lib/parslet/atoms/visitor.rb +89 -0
  27. data/lib/parslet/atoms.rb +34 -0
  28. data/lib/parslet/cause.rb +101 -0
  29. data/lib/parslet/context.rb +21 -0
  30. data/lib/parslet/convenience.rb +33 -0
  31. data/lib/parslet/error_reporter/contextual.rb +120 -0
  32. data/lib/parslet/error_reporter/deepest.rb +100 -0
  33. data/lib/parslet/error_reporter/tree.rb +63 -0
  34. data/lib/parslet/error_reporter.rb +8 -0
  35. data/lib/parslet/export.rb +163 -0
  36. data/lib/parslet/expression/treetop.rb +92 -0
  37. data/lib/parslet/expression.rb +51 -0
  38. data/lib/parslet/graphviz.rb +97 -0
  39. data/lib/parslet/parser.rb +68 -0
  40. data/lib/parslet/pattern/binding.rb +49 -0
  41. data/lib/parslet/pattern.rb +113 -0
  42. data/lib/parslet/position.rb +21 -0
  43. data/lib/parslet/rig/rspec.rb +52 -0
  44. data/lib/parslet/scope.rb +42 -0
  45. data/lib/parslet/slice.rb +105 -0
  46. data/lib/parslet/source/line_cache.rb +99 -0
  47. data/lib/parslet/source.rb +96 -0
  48. data/lib/parslet/transform.rb +265 -0
  49. data/lib/parslet/version.rb +5 -0
  50. data/lib/parslet.rb +314 -0
  51. data/plurimath-parslet.gemspec +42 -0
  52. data/spec/acceptance/infix_parser_spec.rb +145 -0
  53. data/spec/acceptance/mixing_parsers_spec.rb +74 -0
  54. data/spec/acceptance/regression_spec.rb +329 -0
  55. data/spec/acceptance/repetition_and_maybe_spec.rb +44 -0
  56. data/spec/acceptance/unconsumed_input_spec.rb +21 -0
  57. data/spec/examples/boolean_algebra_spec.rb +257 -0
  58. data/spec/examples/calc_spec.rb +278 -0
  59. data/spec/examples/capture_spec.rb +137 -0
  60. data/spec/examples/comments_spec.rb +186 -0
  61. data/spec/examples/deepest_errors_spec.rb +420 -0
  62. data/spec/examples/documentation_spec.rb +205 -0
  63. data/spec/examples/email_parser_spec.rb +275 -0
  64. data/spec/examples/empty_spec.rb +37 -0
  65. data/spec/examples/erb_spec.rb +482 -0
  66. data/spec/examples/ip_address_spec.rb +153 -0
  67. data/spec/examples/json_spec.rb +413 -0
  68. data/spec/examples/local_spec.rb +302 -0
  69. data/spec/examples/mathn_spec.rb +151 -0
  70. data/spec/examples/minilisp_spec.rb +492 -0
  71. data/spec/examples/modularity_spec.rb +340 -0
  72. data/spec/examples/nested_errors_spec.rb +322 -0
  73. data/spec/examples/optimized_erb_spec.rb +299 -0
  74. data/spec/examples/parens_spec.rb +239 -0
  75. data/spec/examples/prec_calc_spec.rb +525 -0
  76. data/spec/examples/readme_spec.rb +228 -0
  77. data/spec/examples/scopes_spec.rb +187 -0
  78. data/spec/examples/seasons_spec.rb +196 -0
  79. data/spec/examples/sentence_spec.rb +119 -0
  80. data/spec/examples/simple_xml_spec.rb +250 -0
  81. data/spec/examples/string_parser_spec.rb +407 -0
  82. data/spec/fixtures/examples/boolean_algebra.rb +62 -0
  83. data/spec/fixtures/examples/calc.rb +86 -0
  84. data/spec/fixtures/examples/capture.rb +36 -0
  85. data/spec/fixtures/examples/comments.rb +22 -0
  86. data/spec/fixtures/examples/deepest_errors.rb +99 -0
  87. data/spec/fixtures/examples/documentation.rb +32 -0
  88. data/spec/fixtures/examples/email_parser.rb +42 -0
  89. data/spec/fixtures/examples/empty.rb +10 -0
  90. data/spec/fixtures/examples/erb.rb +39 -0
  91. data/spec/fixtures/examples/ip_address.rb +103 -0
  92. data/spec/fixtures/examples/json.rb +107 -0
  93. data/spec/fixtures/examples/local.rb +60 -0
  94. data/spec/fixtures/examples/mathn.rb +47 -0
  95. data/spec/fixtures/examples/minilisp.rb +75 -0
  96. data/spec/fixtures/examples/modularity.rb +60 -0
  97. data/spec/fixtures/examples/nested_errors.rb +95 -0
  98. data/spec/fixtures/examples/optimized_erb.rb +105 -0
  99. data/spec/fixtures/examples/parens.rb +25 -0
  100. data/spec/fixtures/examples/prec_calc.rb +71 -0
  101. data/spec/fixtures/examples/readme.rb +59 -0
  102. data/spec/fixtures/examples/scopes.rb +43 -0
  103. data/spec/fixtures/examples/seasons.rb +40 -0
  104. data/spec/fixtures/examples/sentence.rb +18 -0
  105. data/spec/fixtures/examples/simple_xml.rb +51 -0
  106. data/spec/fixtures/examples/string_parser.rb +77 -0
  107. data/spec/parslet/atom_results_spec.rb +39 -0
  108. data/spec/parslet/atoms/alternative_spec.rb +26 -0
  109. data/spec/parslet/atoms/base_spec.rb +127 -0
  110. data/spec/parslet/atoms/capture_spec.rb +21 -0
  111. data/spec/parslet/atoms/combinations_spec.rb +5 -0
  112. data/spec/parslet/atoms/dsl_spec.rb +7 -0
  113. data/spec/parslet/atoms/entity_spec.rb +77 -0
  114. data/spec/parslet/atoms/ignored_spec.rb +15 -0
  115. data/spec/parslet/atoms/infix_spec.rb +5 -0
  116. data/spec/parslet/atoms/lookahead_spec.rb +22 -0
  117. data/spec/parslet/atoms/named_spec.rb +4 -0
  118. data/spec/parslet/atoms/re_spec.rb +14 -0
  119. data/spec/parslet/atoms/repetition_spec.rb +24 -0
  120. data/spec/parslet/atoms/scope_spec.rb +26 -0
  121. data/spec/parslet/atoms/sequence_spec.rb +28 -0
  122. data/spec/parslet/atoms/str_spec.rb +15 -0
  123. data/spec/parslet/atoms/visitor_spec.rb +101 -0
  124. data/spec/parslet/atoms_spec.rb +488 -0
  125. data/spec/parslet/convenience_spec.rb +54 -0
  126. data/spec/parslet/error_reporter/contextual_spec.rb +118 -0
  127. data/spec/parslet/error_reporter/deepest_spec.rb +82 -0
  128. data/spec/parslet/error_reporter/tree_spec.rb +7 -0
  129. data/spec/parslet/export_spec.rb +40 -0
  130. data/spec/parslet/expression/treetop_spec.rb +74 -0
  131. data/spec/parslet/minilisp.citrus +29 -0
  132. data/spec/parslet/minilisp.tt +29 -0
  133. data/spec/parslet/parser_spec.rb +36 -0
  134. data/spec/parslet/parslet_spec.rb +38 -0
  135. data/spec/parslet/pattern_spec.rb +272 -0
  136. data/spec/parslet/position_spec.rb +14 -0
  137. data/spec/parslet/rig/rspec_spec.rb +54 -0
  138. data/spec/parslet/scope_spec.rb +45 -0
  139. data/spec/parslet/slice_spec.rb +186 -0
  140. data/spec/parslet/source/line_cache_spec.rb +74 -0
  141. data/spec/parslet/source_spec.rb +210 -0
  142. data/spec/parslet/transform/context_spec.rb +56 -0
  143. data/spec/parslet/transform_spec.rb +183 -0
  144. data/spec/spec_helper.rb +74 -0
  145. data/spec/support/opal.rb +8 -0
  146. data/spec/support/opal.rb.erb +14 -0
  147. data/spec/support/parslet_matchers.rb +96 -0
  148. metadata +240 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bf6bccf90d999dc5cf0482874564c015cb5411ca3901fe3d8cf1ff8ed73d5604
4
+ data.tar.gz: 821e7f32ba221e8b9c8c704f78c41abc889ab5e1e77ebc6f785e5cc1984bbda4
5
+ SHA512:
6
+ metadata.gz: 162ae4c4b0ed8f5eee07c91c14bad543f6798c3870884a803f63166eea2682c1d67db3e6d550b5b97f451d7fab524bcd0280cbe83be4ffc715baa58e92f41bd8
7
+ data.tar.gz: 7de9a239b025432fccbecfd9177b7b1478a908a27fca4de78bf9b161ec574d3de47179abe830fafd2bb1ed09cedd50fd71a7cbe695044311ca97f436870069da
data/HISTORY.txt ADDED
@@ -0,0 +1,284 @@
1
+
2
+ = 2.1 / ???
3
+
4
+ We're in maintenance mode! The community is really stepping up here though, sending
5
+ interesting additions our way. Here's what has been merged this far:
6
+
7
+ + Specification for mixing parslet parsers (Artur Komarov).
8
+
9
+ + Update to Github Actions CI/CD. I guess newer is better? (Matt Larraz).
10
+ Also includes testing on newer Ruby versions.
11
+
12
+
13
+ = 2.0 / 16Feb2020
14
+
15
+ This release is essentially what is called a 'done' release, meaning I consider
16
+ that parslet meets its goals and doesn't need (much) more evolution.
17
+
18
+ - prsnt? and absnt? are now finally banned into oblivion. Wasting vocals for
19
+ the win.
20
+
21
+ - Because Ruby 2.6 broke Integer() conversion for non-Strings, we've removed
22
+ to_int for slices; to assert Integer type, you must now 'Integer(slice.to_s)'.
23
+ (Broken? How? Integer now (2.6) calls to_int - and when that fails - to_i.
24
+ A class that has both will never raise an exception. Incientially, this makes
25
+ String a unicorn class.)
26
+
27
+ = 1.8.2 / 13Feb2018
28
+
29
+ ! Improvements to performance in cases where atoms are dynamically generated
30
+ (Kevin Olbrich).
31
+
32
+ = 1.8.1 / 19Nov2017
33
+
34
+ - Minor fixes for language compatibility.
35
+
36
+ = 1.8 / 3Apr2017
37
+
38
+ + The `ignored` atom that allows to ignore a part of the matched text.
39
+ `str('foo').ignore` will match 'foo', but not yield any parse output.
40
+ Thanks to chrismwendt (Chris Wendt).
41
+ + Infix expression parser (arithmetics, anyone?) now supports custom reducers
42
+ in block form. Thanks to chrismwendt (Chris Wendt).
43
+ ! Small patches to memory footprint (Christophe Bliard).
44
+ - blankslate dependency removed. You should be good - but if things break,
45
+ please let us know (Nikita Shilnikov).
46
+ ! Parslet now has `parse_failure_cause`, replaces the earlier `cause`.
47
+ ! Fixes all these interpreter warnings on modern rubies.
48
+
49
+ = 1.7 / 12Mar2015
50
+
51
+ ! Small speed gains from improvements on the hot spots.
52
+ + Contextual error reporter, a flavor of error reporting that emphasizes
53
+ context.
54
+
55
+ = 1.6 / 1May2014, 13Okt14
56
+
57
+ + EXPERIMENTAL: Parslet accelerators permit replacing parts of your parser
58
+ with optimized atoms using pattern matching. Look at
59
+ examples/optimized_erb.rb or the introduction to the feature in
60
+ qed/accelerators.md.
61
+
62
+ + infix_expression permits to declare an infix expression parser (think
63
+ calculator) directly. This will solve many of the problems we have
64
+ more elegantly.
65
+
66
+ + Rspec 3 syntax, though hideous, should now work.
67
+
68
+ - Drops 1.8.7 compatibility.
69
+
70
+ ! A performance anomaly when parsing multibyte characters has been detected
71
+ and fixed with the help of Zach Moazeni (@zmoazeni).
72
+
73
+ ! A few small bug fixes and optimisations have been introduced. API should
74
+ remain unchanged.
75
+
76
+ + More lenient on the blankslate version.
77
+ + Modernizes the test suite to run with rspec again. (!)
78
+
79
+ = 1.5 / 27Dec2012
80
+
81
+ + Handles unconsumed input at end of parse completely differently. Instead
82
+ of generating a toplevel error, it now raises an error in every branch
83
+ of the parse. More information in the resulting exception ensues! Thanks
84
+ again to John Mettraux for inspiration & acceptance specs.
85
+
86
+ NOTE that this means that the UnconsumedInput exception is gone, since the
87
+ unconsumed input case is nothing special anymore.
88
+
89
+ * This history now finally reads like the Changelog of the linux kernel.
90
+ Meaning that probably no one ever reads this.
91
+
92
+ + Captures and parsing subsequent input based on captured values. This has
93
+ been long overdue - finally you can parse HEREdocs with parslet!
94
+
95
+ = 1.4.0 / 25May2012
96
+
97
+ + Revised documentation. A few new API features have finally made it into
98
+ the documentation. Examples in the documentation are now curated and
99
+ run against the current code so that they really really work.
100
+ Also, the website generation tools have been replaced with 2012-style
101
+ tools. Much less pain to update now.
102
+
103
+ + Parslet::Source now doesn't hold a StringIO, it directly holds the
104
+ buffer to be parsed. The api of Source has changed a tiny bit. This change
105
+ has been made for speed optimisation reasons.
106
+
107
+ + :reporter argument to parse, allowing to customize error reporting within
108
+ wide boundaries. See issue #64 for a discussion.
109
+ Included are two error reporters, one (default) with the existing error
110
+ tree functionality, one reporting deepest errors as defined by the above
111
+ ticket.
112
+
113
+ + Optimistic parse: Parsing is two phase, with the first phase assuming
114
+ there will be no errors. This yields ~ 20% speed improvement in the
115
+ case where the parse succeeds.
116
+ Also, internal error handling is now using tuples. This and other
117
+ optimizations have yielded ~ 30% overall improvement.
118
+
119
+ ! #error_tree and #cause removed from all of parslet. The
120
+ Parslet::ParseFailed exception now contains a #cause field that can
121
+ be asked for an #ascii_tree as before.
122
+ Cleaner internal error handling, not stateful in atoms anymore. Some
123
+ parsers will see correct error reporting for the first time. (issue #65)
124
+
125
+ + Made it possible to pass a custom Parslet::Source implementor to #parse.
126
+ (see #63)
127
+
128
+ + #parse has now a second argument that is an options hash. See
129
+ Parslet::Atoms::Base#parse for documentation.
130
+
131
+ - VM engine on the way out. No benefit except for the intellectual
132
+ challenge.
133
+
134
+ = 1.3.0 / 5Mar2012
135
+
136
+ ! Parslet::Transform::Context is now much more well-behaved. It has
137
+ #respond_to? and #method_missing; it now looks like a plain old Ruby
138
+ object with instance variables and attribute readers.
139
+
140
+ - Grammar transforms turned out to be a dead end and have been removed.
141
+
142
+ ! A few problems in error message generation have been fixed. This will
143
+ improve diagnostics further.
144
+
145
+ + A VM driven parser engine: Removes the limitation that parsing needs a
146
+ lot of stack space, something dearly missing from Ruby 1.9.3 fibers.
147
+ This engine is experimental and might be removed in the future.
148
+
149
+ ! Interaction with mathn fixed - Line number generation will terminate.
150
+
151
+ . Internal reorganisation, removing cruft and bit rot.
152
+
153
+ = 1.2.3 / 22Sep2011
154
+
155
+ + Transform#apply can now be called with a hash as second argument. This
156
+ provides bindings and a way to inject context.
157
+
158
+ ! Fixes a bug thar modified parslet atoms in place, defeating oop chaining.
159
+ (#50)
160
+
161
+ = 1.2.1 / 6Jun2011
162
+
163
+ ! FIX: Input at the end of a parse raises Parslet::UnconsumedInput. (see
164
+ issue 18)
165
+
166
+ ! FIX: Unicode parsing should now work as expected. (see issue 38)
167
+
168
+ ! FIX: Slice#slice returned wrong bits at times (see issue 36).
169
+
170
+ = 1.2.0 / 4Feb2011
171
+
172
+ + Parslet::Parser is now also a grammar atom, it can be composed freely with
173
+ other atoms. (str('f') >> MiniLispParser.new >> str('b'))
174
+
175
+ + No strings, only slices are returned as part of the parser result.
176
+ Parslet::Slice is almost a string class, but one that remembers the
177
+ source offset. This has also bought us a slight speedup.
178
+
179
+ + require 'parslet/convenience' now brings #parse_with_debug to all parslets.
180
+ This is a consequence of the above change.
181
+
182
+ + Deprecates prsnt? and absnt? in favor of the more readable absent? and
183
+ prsnt?. Uses 3 bytes more RAM. The old variants will exist until we release
184
+ 2.0.
185
+
186
+ INTERNALLY
187
+
188
+ + Visitors now should have methods that all begin with 'visit_*'. #str
189
+ becomes #visit_str.
190
+
191
+ + Parslet::Atoms::Entity now takes only a block argument instead of context
192
+ and block.
193
+
194
+ = 1.1.1 / 4Feb2011
195
+
196
+ ! FIX: Line counting was broken by performance optimisations.
197
+
198
+ + Squeezed out another few drops of performance.
199
+
200
+ = 1.1.0 / 2Feb2011
201
+
202
+ + Uses return (fail/success), cached line counts, memoizing of parse results
203
+ and other tricks internally for at least an order of magnitude increase
204
+ in execution speed.
205
+
206
+ + str('foo').maybe will now return an empty string again. Use .as(...) to
207
+ name things and get back [] from #repeat and nil from #maybe.
208
+
209
+ + If you require 'parslet/atoms/visitor', you'll get an accept method on
210
+ all known Parslet::Atoms.
211
+
212
+ + If you require 'parslet/export', you can call #to_citrus and #to_treetop
213
+ to produce string versions of your grammar in those dialects.
214
+
215
+ + Requiring 'parslet/convenience' will given you a parse_with_debug on
216
+ your Parslet::Parser class. This prints some diagnostics on parse failure.
217
+ (Thanks to Florian Hanke)
218
+
219
+ = 1.0.1 / 17Jan2011
220
+
221
+ A happy new year!
222
+
223
+ ! FIX: Parslet::Transform was wrongly fixed earlier - it now wont mangle
224
+ hashes anymore. (Blake Sweeney)
225
+
226
+ + parslet/rig/rspec.rb contains useful rspec matchers. (R. Konstantin Haase)
227
+
228
+ = 1.0.0 / 29Dez2010
229
+
230
+ - #each_match was removed. There was some duplication of code that even
231
+ confused me - and we should not have 2 methods of achieving the same
232
+ goal.
233
+
234
+ + Full documentation. Fixed sdoc.
235
+
236
+ = 0.11.0 / 25Nov2010
237
+
238
+ ! Bugfixes to tree handling. Let's hope that was the last such significant
239
+ change to the core.
240
+
241
+ = 0.10.1 / 22Nov2010
242
+
243
+ + Allow match['a-z'], shortcut for match('[a-z]')
244
+
245
+ ! Fixed output inconsistencies (behaviour in connection to 'maybe')
246
+
247
+ = 0.10.0 / 22Nov2010
248
+
249
+ + Parslet::Transform now takes a block on initialisation, wherein you can
250
+ define all the rules directly.
251
+
252
+ + Parslet::Transform now only passes a hash to the block during transform
253
+ when its arity is 1. Otherwise all hash contents as bound as local
254
+ variables.
255
+
256
+ + Both inline and other documentation have been improved.
257
+
258
+ + You can now use 'subtree(:x)' to bind any subtree to x during tree pattern
259
+ matching.
260
+
261
+ + Transform classes can now include rules into class definition. This makes
262
+ Parser and Transformer behave the same.
263
+
264
+ = 0.9.0 / 28Oct2010
265
+ * More of everything: Examples, documentation, etc...
266
+
267
+ * Breaking change: Ruby's binary or ('|') is now used for alternatives,
268
+ instead of the division sign ('/') - this reduces the amount of
269
+ parenthesis needed for a grammar overall.
270
+
271
+ * parslet.maybe now yields the result or nil in case of parse failure. This
272
+ is probably better than the array it did before; the jury is still out on
273
+ that.
274
+
275
+ * parslet.repeat(min, max) is now valid syntax
276
+
277
+ = 0.1.0 / not released.
278
+
279
+ * Initial version. Classes for parsing, matching in the resulting trees
280
+ and transforming the trees into something more useful.
281
+
282
+ * Parses and outputs intermediary trees
283
+
284
+ * Matching of single elements and sequences
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2025 Ribose Inc.
2
+ Copyright (c) 2010-2018 Kaspar Schiess
3
+
4
+ Permission is hereby granted, free of charge, to any person
5
+ obtaining a copy of this software and associated documentation
6
+ files (the "Software"), to deal in the Software without
7
+ restriction, including without limitation the rights to use,
8
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following
11
+ conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ OTHER DEALINGS IN THE SOFTWARE.