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.
- checksums.yaml +7 -0
- data/HISTORY.txt +284 -0
- data/LICENSE +23 -0
- data/README.adoc +454 -0
- data/Rakefile +71 -0
- data/lib/parslet/accelerator/application.rb +62 -0
- data/lib/parslet/accelerator/engine.rb +112 -0
- data/lib/parslet/accelerator.rb +162 -0
- data/lib/parslet/atoms/alternative.rb +53 -0
- data/lib/parslet/atoms/base.rb +157 -0
- data/lib/parslet/atoms/can_flatten.rb +137 -0
- data/lib/parslet/atoms/capture.rb +38 -0
- data/lib/parslet/atoms/context.rb +103 -0
- data/lib/parslet/atoms/dsl.rb +112 -0
- data/lib/parslet/atoms/dynamic.rb +32 -0
- data/lib/parslet/atoms/entity.rb +45 -0
- data/lib/parslet/atoms/ignored.rb +26 -0
- data/lib/parslet/atoms/infix.rb +115 -0
- data/lib/parslet/atoms/lookahead.rb +52 -0
- data/lib/parslet/atoms/named.rb +32 -0
- data/lib/parslet/atoms/re.rb +41 -0
- data/lib/parslet/atoms/repetition.rb +87 -0
- data/lib/parslet/atoms/scope.rb +26 -0
- data/lib/parslet/atoms/sequence.rb +48 -0
- data/lib/parslet/atoms/str.rb +42 -0
- data/lib/parslet/atoms/visitor.rb +89 -0
- data/lib/parslet/atoms.rb +34 -0
- data/lib/parslet/cause.rb +101 -0
- data/lib/parslet/context.rb +21 -0
- data/lib/parslet/convenience.rb +33 -0
- data/lib/parslet/error_reporter/contextual.rb +120 -0
- data/lib/parslet/error_reporter/deepest.rb +100 -0
- data/lib/parslet/error_reporter/tree.rb +63 -0
- data/lib/parslet/error_reporter.rb +8 -0
- data/lib/parslet/export.rb +163 -0
- data/lib/parslet/expression/treetop.rb +92 -0
- data/lib/parslet/expression.rb +51 -0
- data/lib/parslet/graphviz.rb +97 -0
- data/lib/parslet/parser.rb +68 -0
- data/lib/parslet/pattern/binding.rb +49 -0
- data/lib/parslet/pattern.rb +113 -0
- data/lib/parslet/position.rb +21 -0
- data/lib/parslet/rig/rspec.rb +52 -0
- data/lib/parslet/scope.rb +42 -0
- data/lib/parslet/slice.rb +105 -0
- data/lib/parslet/source/line_cache.rb +99 -0
- data/lib/parslet/source.rb +96 -0
- data/lib/parslet/transform.rb +265 -0
- data/lib/parslet/version.rb +5 -0
- data/lib/parslet.rb +314 -0
- data/plurimath-parslet.gemspec +42 -0
- data/spec/acceptance/infix_parser_spec.rb +145 -0
- data/spec/acceptance/mixing_parsers_spec.rb +74 -0
- data/spec/acceptance/regression_spec.rb +329 -0
- data/spec/acceptance/repetition_and_maybe_spec.rb +44 -0
- data/spec/acceptance/unconsumed_input_spec.rb +21 -0
- data/spec/examples/boolean_algebra_spec.rb +257 -0
- data/spec/examples/calc_spec.rb +278 -0
- data/spec/examples/capture_spec.rb +137 -0
- data/spec/examples/comments_spec.rb +186 -0
- data/spec/examples/deepest_errors_spec.rb +420 -0
- data/spec/examples/documentation_spec.rb +205 -0
- data/spec/examples/email_parser_spec.rb +275 -0
- data/spec/examples/empty_spec.rb +37 -0
- data/spec/examples/erb_spec.rb +482 -0
- data/spec/examples/ip_address_spec.rb +153 -0
- data/spec/examples/json_spec.rb +413 -0
- data/spec/examples/local_spec.rb +302 -0
- data/spec/examples/mathn_spec.rb +151 -0
- data/spec/examples/minilisp_spec.rb +492 -0
- data/spec/examples/modularity_spec.rb +340 -0
- data/spec/examples/nested_errors_spec.rb +322 -0
- data/spec/examples/optimized_erb_spec.rb +299 -0
- data/spec/examples/parens_spec.rb +239 -0
- data/spec/examples/prec_calc_spec.rb +525 -0
- data/spec/examples/readme_spec.rb +228 -0
- data/spec/examples/scopes_spec.rb +187 -0
- data/spec/examples/seasons_spec.rb +196 -0
- data/spec/examples/sentence_spec.rb +119 -0
- data/spec/examples/simple_xml_spec.rb +250 -0
- data/spec/examples/string_parser_spec.rb +407 -0
- data/spec/fixtures/examples/boolean_algebra.rb +62 -0
- data/spec/fixtures/examples/calc.rb +86 -0
- data/spec/fixtures/examples/capture.rb +36 -0
- data/spec/fixtures/examples/comments.rb +22 -0
- data/spec/fixtures/examples/deepest_errors.rb +99 -0
- data/spec/fixtures/examples/documentation.rb +32 -0
- data/spec/fixtures/examples/email_parser.rb +42 -0
- data/spec/fixtures/examples/empty.rb +10 -0
- data/spec/fixtures/examples/erb.rb +39 -0
- data/spec/fixtures/examples/ip_address.rb +103 -0
- data/spec/fixtures/examples/json.rb +107 -0
- data/spec/fixtures/examples/local.rb +60 -0
- data/spec/fixtures/examples/mathn.rb +47 -0
- data/spec/fixtures/examples/minilisp.rb +75 -0
- data/spec/fixtures/examples/modularity.rb +60 -0
- data/spec/fixtures/examples/nested_errors.rb +95 -0
- data/spec/fixtures/examples/optimized_erb.rb +105 -0
- data/spec/fixtures/examples/parens.rb +25 -0
- data/spec/fixtures/examples/prec_calc.rb +71 -0
- data/spec/fixtures/examples/readme.rb +59 -0
- data/spec/fixtures/examples/scopes.rb +43 -0
- data/spec/fixtures/examples/seasons.rb +40 -0
- data/spec/fixtures/examples/sentence.rb +18 -0
- data/spec/fixtures/examples/simple_xml.rb +51 -0
- data/spec/fixtures/examples/string_parser.rb +77 -0
- data/spec/parslet/atom_results_spec.rb +39 -0
- data/spec/parslet/atoms/alternative_spec.rb +26 -0
- data/spec/parslet/atoms/base_spec.rb +127 -0
- data/spec/parslet/atoms/capture_spec.rb +21 -0
- data/spec/parslet/atoms/combinations_spec.rb +5 -0
- data/spec/parslet/atoms/dsl_spec.rb +7 -0
- data/spec/parslet/atoms/entity_spec.rb +77 -0
- data/spec/parslet/atoms/ignored_spec.rb +15 -0
- data/spec/parslet/atoms/infix_spec.rb +5 -0
- data/spec/parslet/atoms/lookahead_spec.rb +22 -0
- data/spec/parslet/atoms/named_spec.rb +4 -0
- data/spec/parslet/atoms/re_spec.rb +14 -0
- data/spec/parslet/atoms/repetition_spec.rb +24 -0
- data/spec/parslet/atoms/scope_spec.rb +26 -0
- data/spec/parslet/atoms/sequence_spec.rb +28 -0
- data/spec/parslet/atoms/str_spec.rb +15 -0
- data/spec/parslet/atoms/visitor_spec.rb +101 -0
- data/spec/parslet/atoms_spec.rb +488 -0
- data/spec/parslet/convenience_spec.rb +54 -0
- data/spec/parslet/error_reporter/contextual_spec.rb +118 -0
- data/spec/parslet/error_reporter/deepest_spec.rb +82 -0
- data/spec/parslet/error_reporter/tree_spec.rb +7 -0
- data/spec/parslet/export_spec.rb +40 -0
- data/spec/parslet/expression/treetop_spec.rb +74 -0
- data/spec/parslet/minilisp.citrus +29 -0
- data/spec/parslet/minilisp.tt +29 -0
- data/spec/parslet/parser_spec.rb +36 -0
- data/spec/parslet/parslet_spec.rb +38 -0
- data/spec/parslet/pattern_spec.rb +272 -0
- data/spec/parslet/position_spec.rb +14 -0
- data/spec/parslet/rig/rspec_spec.rb +54 -0
- data/spec/parslet/scope_spec.rb +45 -0
- data/spec/parslet/slice_spec.rb +186 -0
- data/spec/parslet/source/line_cache_spec.rb +74 -0
- data/spec/parslet/source_spec.rb +210 -0
- data/spec/parslet/transform/context_spec.rb +56 -0
- data/spec/parslet/transform_spec.rb +183 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/support/opal.rb +8 -0
- data/spec/support/opal.rb.erb +14 -0
- data/spec/support/parslet_matchers.rb +96 -0
- metadata +240 -0
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'parslet'
|
4
|
+
|
5
|
+
describe Parslet::Transform do
|
6
|
+
include Parslet
|
7
|
+
|
8
|
+
let(:transform) { Parslet::Transform.new }
|
9
|
+
|
10
|
+
class A < Struct.new(:elt); end
|
11
|
+
class B < Struct.new(:elt); end
|
12
|
+
class C < Struct.new(:elt); end
|
13
|
+
class Bi < Struct.new(:a, :b); end
|
14
|
+
|
15
|
+
describe "delayed construction" do
|
16
|
+
context "given simple(:x) => A.new(x)" do
|
17
|
+
before(:each) do
|
18
|
+
transform.rule(simple(:x)) { |d| A.new(d[:x]) }
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should transform 'a' into A.new('a')" do
|
22
|
+
transform.apply('a').should == A.new('a')
|
23
|
+
end
|
24
|
+
it "should transform ['a', 'b'] into [A.new('a'), A.new('b')]" do
|
25
|
+
transform.apply(['a', 'b']).should ==
|
26
|
+
[A.new('a'), A.new('b')]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context "given rules on {:a => simple(:x)} and {:b => :_x}" do
|
30
|
+
before(:each) do
|
31
|
+
transform.rule(:a => simple(:x)) { |d| A.new(d[:x]) }
|
32
|
+
transform.rule(:b => simple(:x)) { |d| B.new(d[:x]) }
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should transform {:d=>{:b=>'c'}} into d => B('c')" do
|
36
|
+
transform.apply({:d=>{:b=>'c'}}).should == {:d => B.new('c')}
|
37
|
+
end
|
38
|
+
it "should transform {:a=>{:b=>'c'}} into A(B('c'))" do
|
39
|
+
transform.apply({:a=>{:b=>'c'}}).should == A.new(B.new('c'))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
describe "pulling out subbranches" do
|
43
|
+
before(:each) do
|
44
|
+
transform.rule(:a => {:b => simple(:x)}, :d => {:e => simple(:y)}) { |d|
|
45
|
+
Bi.new(*d.values_at(:x, :y))
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should yield Bi.new('c', 'f')" do
|
50
|
+
transform.apply(:a => {:b => 'c'}, :d => {:e => 'f'}).should ==
|
51
|
+
Bi.new('c', 'f')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
describe "dsl construction" do
|
56
|
+
let(:transform) { Parslet::Transform.new do
|
57
|
+
rule(simple(:x)) { A.new(x) }
|
58
|
+
end
|
59
|
+
}
|
60
|
+
|
61
|
+
it "should still evaluate rules correctly" do
|
62
|
+
transform.apply('a').should == A.new('a')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
describe "class construction" do
|
66
|
+
class OptimusPrime < Parslet::Transform
|
67
|
+
rule(:a => simple(:x)) { A.new(x) }
|
68
|
+
rule(:b => simple(:x)) { B.new(x) }
|
69
|
+
end
|
70
|
+
let(:transform) { OptimusPrime.new }
|
71
|
+
|
72
|
+
it "should evaluate rules" do
|
73
|
+
transform.apply(:a => 'a').should == A.new('a')
|
74
|
+
end
|
75
|
+
|
76
|
+
context "optionally raise when no match found" do
|
77
|
+
class BumbleBee < Parslet::Transform
|
78
|
+
def initialize(&block)
|
79
|
+
super(raise_on_unmatch: true, &block)
|
80
|
+
end
|
81
|
+
rule(:a => simple(:x)) { A.new(x) }
|
82
|
+
end
|
83
|
+
let(:transform) { BumbleBee.new }
|
84
|
+
|
85
|
+
it "should evaluate rules" do
|
86
|
+
transform.apply(:a => 'a').should == A.new('a')
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should raise when no rules are matched" do
|
90
|
+
lambda {
|
91
|
+
transform.apply(:z => 'z')
|
92
|
+
}.should raise_error(NotImplementedError, /Failed to match/)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "with inheritance" do
|
97
|
+
class OptimusPrimeJunior < OptimusPrime
|
98
|
+
rule(:b => simple(:x)) { B.new(x.upcase) }
|
99
|
+
rule(:c => simple(:x)) { C.new(x) }
|
100
|
+
end
|
101
|
+
let(:transform) { OptimusPrimeJunior.new }
|
102
|
+
|
103
|
+
it "should inherit rules from its parent" do
|
104
|
+
transform.apply(:a => 'a').should == A.new('a')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should be able to override rules from its parent" do
|
108
|
+
transform.apply(:b => 'b').should == B.new('B')
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should be able to define new rules" do
|
112
|
+
transform.apply(:c => 'c').should == C.new('c')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
describe "<- #call_on_match" do
|
117
|
+
let(:bindings) { { :foo => 'test' } }
|
118
|
+
context "when given a block of arity 1" do
|
119
|
+
it "should call the block" do
|
120
|
+
called = false
|
121
|
+
transform.call_on_match(bindings, lambda do |dict|
|
122
|
+
called = true
|
123
|
+
end)
|
124
|
+
|
125
|
+
called.should == true
|
126
|
+
end
|
127
|
+
it "should yield the bindings" do
|
128
|
+
transform.call_on_match(bindings, lambda do |dict|
|
129
|
+
dict.should == bindings
|
130
|
+
end)
|
131
|
+
end
|
132
|
+
it "should execute in the current context" do
|
133
|
+
foo = 'test'
|
134
|
+
transform.call_on_match(bindings, lambda do |dict|
|
135
|
+
foo.should == 'test'
|
136
|
+
end)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
context "when given a block of arity 0" do
|
140
|
+
it "should call the block" do
|
141
|
+
called = false
|
142
|
+
transform.call_on_match(bindings, proc do
|
143
|
+
called = true
|
144
|
+
end)
|
145
|
+
|
146
|
+
called.should == true
|
147
|
+
end
|
148
|
+
it "should have bindings as local variables" do
|
149
|
+
transform.call_on_match(bindings, proc do
|
150
|
+
foo.should == 'test'
|
151
|
+
end)
|
152
|
+
end
|
153
|
+
it "should execute in its own context" do
|
154
|
+
@bar = 'test'
|
155
|
+
transform.call_on_match(bindings, proc do
|
156
|
+
if instance_variable_defined?("@bar")
|
157
|
+
instance_variable_get("@bar").should_not == 'test'
|
158
|
+
end
|
159
|
+
end)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "various transformations (regression)" do
|
165
|
+
context "hashes" do
|
166
|
+
it "are matched completely" do
|
167
|
+
transform.rule(:a => simple(:x)) { fail }
|
168
|
+
transform.apply(:a => 'a', :b => 'b')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context "when not using the bindings as hash, but as local variables" do
|
174
|
+
it "should access the variables" do
|
175
|
+
transform.rule(simple(:x)) { A.new(x) }
|
176
|
+
transform.apply('a').should == A.new('a')
|
177
|
+
end
|
178
|
+
it "should allow context as local variable" do
|
179
|
+
transform.rule(simple(:x)) { foo }
|
180
|
+
transform.apply('a', :foo => 'bar').should == 'bar'
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'support/opal' if RUBY_ENGINE == 'opal'
|
4
|
+
|
5
|
+
require 'parslet'
|
6
|
+
require 'parslet/rig/rspec'
|
7
|
+
require 'parslet/atoms/visitor'
|
8
|
+
|
9
|
+
# Load custom matchers
|
10
|
+
require_relative 'support/parslet_matchers'
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'ae'
|
14
|
+
rescue LoadError
|
15
|
+
# AE not available
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
# Allow both old and new syntax for backward compatibility
|
20
|
+
config.expect_with :rspec do |expectations|
|
21
|
+
expectations.syntax = %i[should expect]
|
22
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
23
|
+
end
|
24
|
+
|
25
|
+
# Use rspec mocks
|
26
|
+
config.mock_with :rspec do |mocks|
|
27
|
+
mocks.verify_partial_doubles = true
|
28
|
+
end
|
29
|
+
|
30
|
+
# Shared context and examples
|
31
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
32
|
+
|
33
|
+
# This is not a Rails project, so no Rails-specific configuration needed
|
34
|
+
|
35
|
+
# Exclude other ruby versions by giving :ruby => '2.7' or :ruby => '3.0'
|
36
|
+
config.filter_run_excluding ruby: lambda { |version|
|
37
|
+
RUBY_VERSION !~ /^#{Regexp.escape(version.to_s)}/
|
38
|
+
}
|
39
|
+
|
40
|
+
# Run specs in random order to surface order dependencies
|
41
|
+
config.order = :random
|
42
|
+
Kernel.srand config.seed
|
43
|
+
end
|
44
|
+
|
45
|
+
def catch_failed_parse
|
46
|
+
exception = nil
|
47
|
+
begin
|
48
|
+
yield
|
49
|
+
rescue Parslet::ParseFailed => e
|
50
|
+
exception = e
|
51
|
+
end
|
52
|
+
exception&.parse_failure_cause
|
53
|
+
end
|
54
|
+
|
55
|
+
def slet(name, &block)
|
56
|
+
let(name, &block)
|
57
|
+
subject(&block)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Helper method to convert Parslet::Slice objects to plain strings for comparison
|
61
|
+
def strip_positions(obj)
|
62
|
+
case obj
|
63
|
+
when Parslet::Slice
|
64
|
+
obj.to_s
|
65
|
+
when Hash
|
66
|
+
obj.transform_values { |v| strip_positions(v) }
|
67
|
+
when Array
|
68
|
+
obj.map { |item| strip_positions(item) }
|
69
|
+
when String
|
70
|
+
obj.gsub(/@\d+/, '') # Remove slice of text
|
71
|
+
else
|
72
|
+
obj
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# A set of patches required to run Opal-RSpec
|
2
|
+
require 'nodejs/yaml'
|
3
|
+
|
4
|
+
module AE
|
5
|
+
# Compile in AE metadata
|
6
|
+
@metadata =
|
7
|
+
{ 'revision' => 2013, 'type' => 'ruby', 'sources' => ['var'], 'authors' => [{ 'name' => 'Trans', 'email' => 'transfire@gmail.com' }], 'organizations' => [], 'requirements' => [{ 'name' => 'ansi' }, { 'groups' => ['build'], 'development' => true, 'name' => 'detroit' }, { 'groups' => ['test'], 'development' => true, 'name' => 'qed' }], 'conflicts' => [], 'alternatives' => [], 'resources' => [{ 'type' => 'home', 'uri' => 'http://rubyworks.github.com/ae', 'label' => 'Homepage' }, { 'type' => 'code', 'uri' => 'http://github.com/rubyworks/ae', 'label' => 'Source Code' }, { 'type' => 'docs', 'uri' => 'http://rubydoc.info/gems/ae', 'label' => 'Documentation' }, { 'type' => 'wiki', 'uri' => 'http://wiki.github.com/rubyworks/ae', 'label' => 'User Guide' }, { 'type' => 'bugs', 'uri' => 'http://github.com/rubyworks/ae/issues', 'label' => 'Issue Tracker' }, { 'type' => 'mail', 'uri' => 'http://groups.google.com/group/rubyworks-mailinglist', 'label' => 'Mailing List' }], 'repositories' => [{ 'name' => 'upstream', 'scm' => 'git', 'uri' => 'git://github.com/rubyworks/ae.git' }], 'categories' => [], 'copyrights' => [{ 'holder' => 'Rubyworks', 'year' => '2008', 'license' => 'BSD-2-Clause' }], 'customs' => [], 'paths' => { 'lib' => ['lib'] }, 'created' => '2008-08-17', 'summary' => 'Assertive Expressive', 'title' => 'AE', 'version' => '1.8.2', 'name' => 'ae', 'description' => "Assertive Expressive is an assertions library specifically designed \nfor reuse by other test frameworks.", 'date' => '2013-02-18' }
|
8
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# A set of patches required to run Opal-RSpec
|
2
|
+
require 'nodejs/yaml'
|
3
|
+
|
4
|
+
module AE
|
5
|
+
# Compile in AE metadata
|
6
|
+
@metadata = (
|
7
|
+
<%=
|
8
|
+
require 'yaml'
|
9
|
+
YAML.load(
|
10
|
+
File.read(
|
11
|
+
File.expand_path('lib/ae.yml', Gem::Specification.find_by_name('ae').gem_dir)))
|
12
|
+
%>
|
13
|
+
)
|
14
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Custom RSpec matchers for Parslet structures
|
2
|
+
# These matchers handle the comparison of Parslet::Slice objects and nested structures
|
3
|
+
|
4
|
+
RSpec::Matchers.define :parse_as do |expected|
|
5
|
+
match do |actual|
|
6
|
+
normalize_parslet_structure(actual) == normalize_parslet_structure(expected)
|
7
|
+
end
|
8
|
+
|
9
|
+
failure_message do |actual|
|
10
|
+
"expected #{normalize_parslet_structure(actual)} to parse as #{normalize_parslet_structure(expected)}"
|
11
|
+
end
|
12
|
+
|
13
|
+
failure_message_when_negated do |actual|
|
14
|
+
"expected #{normalize_parslet_structure(actual)} not to parse as #{normalize_parslet_structure(expected)}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def normalize_parslet_structure(obj)
|
18
|
+
case obj
|
19
|
+
when Hash
|
20
|
+
obj.transform_values { |v| normalize_parslet_structure(v) }
|
21
|
+
when Array
|
22
|
+
obj.map { |item| normalize_parslet_structure(item) }
|
23
|
+
when Parslet::Slice
|
24
|
+
obj.to_s
|
25
|
+
else
|
26
|
+
obj
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec::Matchers.define :match_structure do |expected|
|
32
|
+
match do |actual|
|
33
|
+
deep_match(actual, expected)
|
34
|
+
end
|
35
|
+
|
36
|
+
failure_message do |actual|
|
37
|
+
"expected structure to match:\n#{format_structure(expected)}\n\nbut got:\n#{format_structure(actual)}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def deep_match(actual, expected)
|
41
|
+
case expected
|
42
|
+
when Hash
|
43
|
+
return false unless actual.is_a?(Hash)
|
44
|
+
expected.all? do |key, value|
|
45
|
+
actual.key?(key) && deep_match(actual[key], value)
|
46
|
+
end
|
47
|
+
when Array
|
48
|
+
return false unless actual.is_a?(Array)
|
49
|
+
return false unless actual.length == expected.length
|
50
|
+
actual.zip(expected).all? { |a, e| deep_match(a, e) }
|
51
|
+
when String
|
52
|
+
actual.to_s == expected
|
53
|
+
when Symbol
|
54
|
+
actual.to_s == expected.to_s
|
55
|
+
when Class
|
56
|
+
actual.is_a?(expected)
|
57
|
+
else
|
58
|
+
actual == expected
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def format_structure(obj, indent = 0)
|
63
|
+
spaces = " " * indent
|
64
|
+
case obj
|
65
|
+
when Hash
|
66
|
+
if obj.empty?
|
67
|
+
"{}"
|
68
|
+
else
|
69
|
+
"{\n" + obj.map { |k, v| "#{spaces} #{k.inspect} => #{format_structure(v, indent + 1)}" }.join(",\n") + "\n#{spaces}}"
|
70
|
+
end
|
71
|
+
when Array
|
72
|
+
if obj.empty?
|
73
|
+
"[]"
|
74
|
+
else
|
75
|
+
"[\n" + obj.map { |item| "#{spaces} #{format_structure(item, indent + 1)}" }.join(",\n") + "\n#{spaces}]"
|
76
|
+
end
|
77
|
+
when Parslet::Slice
|
78
|
+
obj.to_s.inspect + " (Slice)"
|
79
|
+
else
|
80
|
+
obj.inspect
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Helper method to create expected structures more easily
|
86
|
+
def slice(str)
|
87
|
+
str
|
88
|
+
end
|
89
|
+
|
90
|
+
def hash_with(**keys)
|
91
|
+
keys
|
92
|
+
end
|
93
|
+
|
94
|
+
def array_of(*items)
|
95
|
+
items
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,240 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plurimath-parslet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kaspar Schiess
|
8
|
+
- Ribose Inc.
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2025-06-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '13.0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '13.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rdoc
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '6.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '6.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
description: A small Ruby library for constructing parsers in the PEG (Parsing Expression
|
57
|
+
Grammar) fashion. This is a fork of the original parslet gem with Opal (JavaScript-based
|
58
|
+
Ruby) compatibility.
|
59
|
+
email:
|
60
|
+
- open.source@ribose.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- HISTORY.txt
|
66
|
+
- LICENSE
|
67
|
+
- README.adoc
|
68
|
+
- Rakefile
|
69
|
+
- lib/parslet.rb
|
70
|
+
- lib/parslet/accelerator.rb
|
71
|
+
- lib/parslet/accelerator/application.rb
|
72
|
+
- lib/parslet/accelerator/engine.rb
|
73
|
+
- lib/parslet/atoms.rb
|
74
|
+
- lib/parslet/atoms/alternative.rb
|
75
|
+
- lib/parslet/atoms/base.rb
|
76
|
+
- lib/parslet/atoms/can_flatten.rb
|
77
|
+
- lib/parslet/atoms/capture.rb
|
78
|
+
- lib/parslet/atoms/context.rb
|
79
|
+
- lib/parslet/atoms/dsl.rb
|
80
|
+
- lib/parslet/atoms/dynamic.rb
|
81
|
+
- lib/parslet/atoms/entity.rb
|
82
|
+
- lib/parslet/atoms/ignored.rb
|
83
|
+
- lib/parslet/atoms/infix.rb
|
84
|
+
- lib/parslet/atoms/lookahead.rb
|
85
|
+
- lib/parslet/atoms/named.rb
|
86
|
+
- lib/parslet/atoms/re.rb
|
87
|
+
- lib/parslet/atoms/repetition.rb
|
88
|
+
- lib/parslet/atoms/scope.rb
|
89
|
+
- lib/parslet/atoms/sequence.rb
|
90
|
+
- lib/parslet/atoms/str.rb
|
91
|
+
- lib/parslet/atoms/visitor.rb
|
92
|
+
- lib/parslet/cause.rb
|
93
|
+
- lib/parslet/context.rb
|
94
|
+
- lib/parslet/convenience.rb
|
95
|
+
- lib/parslet/error_reporter.rb
|
96
|
+
- lib/parslet/error_reporter/contextual.rb
|
97
|
+
- lib/parslet/error_reporter/deepest.rb
|
98
|
+
- lib/parslet/error_reporter/tree.rb
|
99
|
+
- lib/parslet/export.rb
|
100
|
+
- lib/parslet/expression.rb
|
101
|
+
- lib/parslet/expression/treetop.rb
|
102
|
+
- lib/parslet/graphviz.rb
|
103
|
+
- lib/parslet/parser.rb
|
104
|
+
- lib/parslet/pattern.rb
|
105
|
+
- lib/parslet/pattern/binding.rb
|
106
|
+
- lib/parslet/position.rb
|
107
|
+
- lib/parslet/rig/rspec.rb
|
108
|
+
- lib/parslet/scope.rb
|
109
|
+
- lib/parslet/slice.rb
|
110
|
+
- lib/parslet/source.rb
|
111
|
+
- lib/parslet/source/line_cache.rb
|
112
|
+
- lib/parslet/transform.rb
|
113
|
+
- lib/parslet/version.rb
|
114
|
+
- plurimath-parslet.gemspec
|
115
|
+
- spec/acceptance/infix_parser_spec.rb
|
116
|
+
- spec/acceptance/mixing_parsers_spec.rb
|
117
|
+
- spec/acceptance/regression_spec.rb
|
118
|
+
- spec/acceptance/repetition_and_maybe_spec.rb
|
119
|
+
- spec/acceptance/unconsumed_input_spec.rb
|
120
|
+
- spec/examples/boolean_algebra_spec.rb
|
121
|
+
- spec/examples/calc_spec.rb
|
122
|
+
- spec/examples/capture_spec.rb
|
123
|
+
- spec/examples/comments_spec.rb
|
124
|
+
- spec/examples/deepest_errors_spec.rb
|
125
|
+
- spec/examples/documentation_spec.rb
|
126
|
+
- spec/examples/email_parser_spec.rb
|
127
|
+
- spec/examples/empty_spec.rb
|
128
|
+
- spec/examples/erb_spec.rb
|
129
|
+
- spec/examples/ip_address_spec.rb
|
130
|
+
- spec/examples/json_spec.rb
|
131
|
+
- spec/examples/local_spec.rb
|
132
|
+
- spec/examples/mathn_spec.rb
|
133
|
+
- spec/examples/minilisp_spec.rb
|
134
|
+
- spec/examples/modularity_spec.rb
|
135
|
+
- spec/examples/nested_errors_spec.rb
|
136
|
+
- spec/examples/optimized_erb_spec.rb
|
137
|
+
- spec/examples/parens_spec.rb
|
138
|
+
- spec/examples/prec_calc_spec.rb
|
139
|
+
- spec/examples/readme_spec.rb
|
140
|
+
- spec/examples/scopes_spec.rb
|
141
|
+
- spec/examples/seasons_spec.rb
|
142
|
+
- spec/examples/sentence_spec.rb
|
143
|
+
- spec/examples/simple_xml_spec.rb
|
144
|
+
- spec/examples/string_parser_spec.rb
|
145
|
+
- spec/fixtures/examples/boolean_algebra.rb
|
146
|
+
- spec/fixtures/examples/calc.rb
|
147
|
+
- spec/fixtures/examples/capture.rb
|
148
|
+
- spec/fixtures/examples/comments.rb
|
149
|
+
- spec/fixtures/examples/deepest_errors.rb
|
150
|
+
- spec/fixtures/examples/documentation.rb
|
151
|
+
- spec/fixtures/examples/email_parser.rb
|
152
|
+
- spec/fixtures/examples/empty.rb
|
153
|
+
- spec/fixtures/examples/erb.rb
|
154
|
+
- spec/fixtures/examples/ip_address.rb
|
155
|
+
- spec/fixtures/examples/json.rb
|
156
|
+
- spec/fixtures/examples/local.rb
|
157
|
+
- spec/fixtures/examples/mathn.rb
|
158
|
+
- spec/fixtures/examples/minilisp.rb
|
159
|
+
- spec/fixtures/examples/modularity.rb
|
160
|
+
- spec/fixtures/examples/nested_errors.rb
|
161
|
+
- spec/fixtures/examples/optimized_erb.rb
|
162
|
+
- spec/fixtures/examples/parens.rb
|
163
|
+
- spec/fixtures/examples/prec_calc.rb
|
164
|
+
- spec/fixtures/examples/readme.rb
|
165
|
+
- spec/fixtures/examples/scopes.rb
|
166
|
+
- spec/fixtures/examples/seasons.rb
|
167
|
+
- spec/fixtures/examples/sentence.rb
|
168
|
+
- spec/fixtures/examples/simple_xml.rb
|
169
|
+
- spec/fixtures/examples/string_parser.rb
|
170
|
+
- spec/parslet/atom_results_spec.rb
|
171
|
+
- spec/parslet/atoms/alternative_spec.rb
|
172
|
+
- spec/parslet/atoms/base_spec.rb
|
173
|
+
- spec/parslet/atoms/capture_spec.rb
|
174
|
+
- spec/parslet/atoms/combinations_spec.rb
|
175
|
+
- spec/parslet/atoms/dsl_spec.rb
|
176
|
+
- spec/parslet/atoms/entity_spec.rb
|
177
|
+
- spec/parslet/atoms/ignored_spec.rb
|
178
|
+
- spec/parslet/atoms/infix_spec.rb
|
179
|
+
- spec/parslet/atoms/lookahead_spec.rb
|
180
|
+
- spec/parslet/atoms/named_spec.rb
|
181
|
+
- spec/parslet/atoms/re_spec.rb
|
182
|
+
- spec/parslet/atoms/repetition_spec.rb
|
183
|
+
- spec/parslet/atoms/scope_spec.rb
|
184
|
+
- spec/parslet/atoms/sequence_spec.rb
|
185
|
+
- spec/parslet/atoms/str_spec.rb
|
186
|
+
- spec/parslet/atoms/visitor_spec.rb
|
187
|
+
- spec/parslet/atoms_spec.rb
|
188
|
+
- spec/parslet/convenience_spec.rb
|
189
|
+
- spec/parslet/error_reporter/contextual_spec.rb
|
190
|
+
- spec/parslet/error_reporter/deepest_spec.rb
|
191
|
+
- spec/parslet/error_reporter/tree_spec.rb
|
192
|
+
- spec/parslet/export_spec.rb
|
193
|
+
- spec/parslet/expression/treetop_spec.rb
|
194
|
+
- spec/parslet/minilisp.citrus
|
195
|
+
- spec/parslet/minilisp.tt
|
196
|
+
- spec/parslet/parser_spec.rb
|
197
|
+
- spec/parslet/parslet_spec.rb
|
198
|
+
- spec/parslet/pattern_spec.rb
|
199
|
+
- spec/parslet/position_spec.rb
|
200
|
+
- spec/parslet/rig/rspec_spec.rb
|
201
|
+
- spec/parslet/scope_spec.rb
|
202
|
+
- spec/parslet/slice_spec.rb
|
203
|
+
- spec/parslet/source/line_cache_spec.rb
|
204
|
+
- spec/parslet/source_spec.rb
|
205
|
+
- spec/parslet/transform/context_spec.rb
|
206
|
+
- spec/parslet/transform_spec.rb
|
207
|
+
- spec/spec_helper.rb
|
208
|
+
- spec/support/opal.rb
|
209
|
+
- spec/support/opal.rb.erb
|
210
|
+
- spec/support/parslet_matchers.rb
|
211
|
+
homepage: https://github.com/plurimath/plurimath-parslet
|
212
|
+
licenses:
|
213
|
+
- MIT
|
214
|
+
metadata:
|
215
|
+
bug_tracker_uri: https://github.com/plurimath/plurimath-parslet/issues
|
216
|
+
changelog_uri: https://github.com/plurimath/plurimath-parslet/blob/main/HISTORY.txt
|
217
|
+
documentation_uri: https://kschiess.github.io/parslet/
|
218
|
+
homepage_uri: https://github.com/plurimath/plurimath-parslet
|
219
|
+
source_code_uri: https://github.com/plurimath/plurimath-parslet
|
220
|
+
rubygems_mfa_required: 'true'
|
221
|
+
post_install_message:
|
222
|
+
rdoc_options: []
|
223
|
+
require_paths:
|
224
|
+
- lib
|
225
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: 2.7.0
|
230
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
231
|
+
requirements:
|
232
|
+
- - ">="
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '0'
|
235
|
+
requirements: []
|
236
|
+
rubygems_version: 3.5.22
|
237
|
+
signing_key:
|
238
|
+
specification_version: 4
|
239
|
+
summary: Parser construction library with great error reporting in Ruby.
|
240
|
+
test_files: []
|