sexp_path 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/sexp_path.rb +10 -2
- data/lib/sexp_path/matcher/base.rb +4 -0
- data/lib/sexp_path/matcher/remaining.rb +5 -1
- data/test/sexp_path_capture_test.rb +12 -0
- metadata +19 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 642b64481c3c3122cce88572f5b3391da7de2008
|
4
|
+
data.tar.gz: ec790db6019e7294d18d7147d1efb14fb050440d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b0f98e4a951f85bd66c8669265ea113c31044deba3bd22c94f3cf08baa7ec45a75d75376464a54ae3589120ab4acaee53bc3342b00fb6a8196d22b7144671f9
|
7
|
+
data.tar.gz: 30abfada1970daee876e4a790fc65b907949285afeb652f88f8b2d97f889fa2a53e093fa214999a4d23a7f5bc930da4736fb06bf432caef3cf576f33fb2e780c
|
data/lib/sexp_path.rb
CHANGED
@@ -52,8 +52,16 @@ class Sexp
|
|
52
52
|
# Extends Sexp to allow any Sexp to be used as a SexpPath matcher
|
53
53
|
def satisfy?(o, data={})
|
54
54
|
return false unless o.is_a? Sexp
|
55
|
-
return false unless
|
56
|
-
|
55
|
+
return false unless length == o.length || (last.is_a?(Sexp) && last.greedy?)
|
56
|
+
|
57
|
+
each_with_index do |child,i|
|
58
|
+
if child.is_a?(Sexp)
|
59
|
+
candidate = child.greedy? ? o[i..-1] : o[i]
|
60
|
+
return false unless child.satisfy?( candidate, data )
|
61
|
+
else
|
62
|
+
return false unless child == o[i]
|
63
|
+
end
|
64
|
+
end
|
57
65
|
|
58
66
|
capture_match(o, data)
|
59
67
|
end
|
@@ -128,4 +128,16 @@ class SexpPathCaptureTest < Test::Unit::TestCase
|
|
128
128
|
assert_equal s(:c), res['c']
|
129
129
|
end
|
130
130
|
|
131
|
+
def test_capturing_remaining
|
132
|
+
sexp = s(s(:a), s(:b), s(:c))
|
133
|
+
assert res = Q?{ s(s(:a), ___ % 'match') }.satisfy?( sexp )
|
134
|
+
assert_equal [s(:b), s(:c)], res['match']
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_capturing_remaining_atoms
|
138
|
+
sexp = s(:a, :b, :c)
|
139
|
+
assert res = Q?{ s(:a, ___ % 'match') }.satisfy?( sexp )
|
140
|
+
assert_equal [:b, :c], res['match']
|
141
|
+
end
|
142
|
+
|
131
143
|
end
|
metadata
CHANGED
@@ -1,48 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sexp_path
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Adam Sanderson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: sexp_processor
|
16
|
-
prerelease: false
|
17
15
|
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '4.2'
|
22
|
-
none: false
|
23
20
|
type: :runtime
|
21
|
+
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
23
|
requirements:
|
26
|
-
- - ~>
|
24
|
+
- - "~>"
|
27
25
|
- !ruby/object:Gem::Version
|
28
26
|
version: '4.2'
|
29
|
-
none: false
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: ruby_parser
|
32
|
-
prerelease: false
|
33
29
|
requirement: !ruby/object:Gem::Requirement
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '3.2'
|
38
|
-
none: false
|
39
34
|
type: :development
|
35
|
+
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
37
|
requirements:
|
42
|
-
- - ~>
|
38
|
+
- - "~>"
|
43
39
|
- !ruby/object:Gem::Version
|
44
40
|
version: '3.2'
|
45
|
-
none: false
|
46
41
|
description: Example based structural pattern matching for S-Expressions
|
47
42
|
email: netghost@gmail.com
|
48
43
|
executables: []
|
@@ -50,6 +45,11 @@ extensions: []
|
|
50
45
|
extra_rdoc_files:
|
51
46
|
- README.rdoc
|
52
47
|
files:
|
48
|
+
- Gemfile
|
49
|
+
- README.rdoc
|
50
|
+
- examples/print_methods.rb
|
51
|
+
- examples/sexp_grep.rb
|
52
|
+
- lib/sexp_path.rb
|
53
53
|
- lib/sexp_path/matcher/all.rb
|
54
54
|
- lib/sexp_path/matcher/any.rb
|
55
55
|
- lib/sexp_path/matcher/atom.rb
|
@@ -68,41 +68,35 @@ files:
|
|
68
68
|
- lib/sexp_path/sexp_query_builder.rb
|
69
69
|
- lib/sexp_path/sexp_result.rb
|
70
70
|
- lib/sexp_path/traverse.rb
|
71
|
-
- lib/sexp_path.rb
|
72
|
-
- examples/print_methods.rb
|
73
|
-
- examples/sexp_grep.rb
|
74
71
|
- test/sample.rb
|
75
72
|
- test/sexp_path_capture_test.rb
|
76
73
|
- test/sexp_path_matching_test.rb
|
77
74
|
- test/sexp_replacement_test.rb
|
78
75
|
- test/use_case_test.rb
|
79
|
-
- README.rdoc
|
80
|
-
- Gemfile
|
81
76
|
homepage: https://github.com/adamsanderson/sexp_path
|
82
77
|
licenses:
|
83
78
|
- MIT
|
79
|
+
metadata: {}
|
84
80
|
post_install_message:
|
85
81
|
rdoc_options:
|
86
|
-
- --main
|
82
|
+
- "--main"
|
87
83
|
- README.rdoc
|
88
84
|
require_paths:
|
89
85
|
- lib
|
90
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
87
|
requirements:
|
92
|
-
- -
|
88
|
+
- - ">="
|
93
89
|
- !ruby/object:Gem::Version
|
94
90
|
version: '1.9'
|
95
|
-
none: false
|
96
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
92
|
requirements:
|
98
|
-
- -
|
93
|
+
- - ">="
|
99
94
|
- !ruby/object:Gem::Version
|
100
95
|
version: '0'
|
101
|
-
none: false
|
102
96
|
requirements: []
|
103
97
|
rubyforge_project:
|
104
|
-
rubygems_version:
|
98
|
+
rubygems_version: 2.2.1
|
105
99
|
signing_key:
|
106
|
-
specification_version:
|
100
|
+
specification_version: 4
|
107
101
|
summary: Pattern matching for S-Expressions
|
108
102
|
test_files: []
|