rexle-xpath-parser 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 033a1413cf694a63b30d9b3c1d227522e7d7272f
4
- data.tar.gz: b0a3a467c18bb03b282c19af964b5c8c43a55f00
3
+ metadata.gz: 0eb094bc9685658e7742f8cf6b12b640f057ac2c
4
+ data.tar.gz: b18b160e6dc524e45ed86ba2a4b3a33cb67a9e62
5
5
  SHA512:
6
- metadata.gz: 22f15c9d1d02917210117fd9bd94c9432fec3df417d511f07a2efd27d47bd62afeb340e46ef099e76472f41996cb5c466bf955c78bf751de1a82d35b459eb4ee
7
- data.tar.gz: d4ee4a855c76449e1d1ed783110df04b49c3fa25edadf2b5cccff5d38aaa7fcb0de24ef375ad677bb3712b5bf900e5e3b8d74e979750b2ea396f42dac6a82f8b
6
+ metadata.gz: a16e477fec94065135404d1026d3011ae1d3901075de32e1034844ef6fbaee3431a1c10235e3a9fa3c125ad09a16a84b24cd1475e37ccbe019f2348df3b1f9dd
7
+ data.tar.gz: 2d580efe36ce525a3ad51f51bc6e5acbe844acf340a9ce6cf2e68e8853cb12f5f1a11fd78ec8b4d626da477f0385a474f25be0ef634d4b0f51e25611583df606
checksums.yaml.gz.sig CHANGED
@@ -1 +1,2 @@
1
- ��4h�o+z+�e_D��0��7Yp'^����[7D?�n{��'pAջ�iN��Չ�[c۞��/?Xx�������xs#��֟b��@�~E8IVW��Z���F�Tb��|3IFZ�>�ر8EYChG
1
+ VenL{�aMBBsGX��-�ݱ$N1+"�u�3~f��i9IN�3s˔���g�>Hv�F�g%�\:�Ki��H����<�/�wQ���fNeg��ĿS�U����eWLX��_�,-Y�c���"������C�WQB��Y�ӱ$�R�-�gE۷���z�N羟 ?��$���lc'f����ُ�m
2
+ \$����,"�4Ԃ�L������d ��i������&
data.tar.gz.sig CHANGED
Binary file
@@ -24,14 +24,23 @@ class RexleXPathParser
24
24
  #
25
25
  def functionalise(a, r2=[])
26
26
 
27
- a.inject(r2) do |r,x|
27
+ r4 = a.inject(r2) do |r,x|
28
28
 
29
29
  return r << functionalise(x) if x.is_a? Array
30
30
 
31
- if /^(?<func>\w+)\(\)/ =~ x then
32
- r << func.to_sym
31
+ if x =~ /^or$/ then
32
+ r << :|
33
+
34
+ elsif /^(?<func>\w+)\(\)(?:\s+(?<operator>[<>=])\s+(?<value>\w+))?/ =~ x
35
+
36
+ r << if operator then
37
+ x = ''
38
+ [func.to_sym, operator.to_sym, value]
39
+ else
40
+ func.to_sym
41
+ end
33
42
  elsif /^@(?<attribute>[\w\/]+)/ =~ x
34
- r << [[:attribute, attribute]]
43
+ r << [:attribute, attribute]
35
44
  elsif x =~ /^\/\//
36
45
  r << [:recursive, *RexleXPathParser.new(x[2..-1]).to_a]
37
46
  elsif x =~ /^[\w\/\*]+\[/
@@ -50,9 +59,9 @@ class RexleXPathParser
50
59
  end
51
60
 
52
61
  elsif /!=(?<value>.*)/ =~ x
53
- r[-1] << [:value, :'!=', value.sub(/^["'](.*)["']$/,'\1')]
62
+ r << [:value, :'!=', value.sub(/^["'](.*)["']$/,'\1')]
54
63
  elsif /=(?<value>.*)/ =~ x
55
- r[-1] << [:value, :==, value.sub(/^["'](.*)["']$/,'\1')]
64
+ r << [:value, :==, value.sub(/^["'](.*)["']$/,'\1')]
56
65
  elsif x =~ /\|/
57
66
  r << [:union]
58
67
  elsif x =~ /\s+or\s+/
@@ -63,21 +72,25 @@ class RexleXPathParser
63
72
  r << [:index, x]
64
73
  elsif /^attribute::(?<attribute>\w+)/ =~ x
65
74
  r << [:attribute, attribute]
66
- elsif /^(?<name>[\w\*\.]+)\/?/ =~ x
75
+ elsif x.is_a? String and /^(?<name>[\w\*\.]+)\/?/ =~ x
67
76
 
68
77
  x.slice!(/^[\w\*\.]+\/?/)
69
- r3 = [[:select, name]]
78
+ r3 = [:select, name]
70
79
 
71
80
  if x.length > 0 then
72
81
  functionalise([x], r3)
73
82
 
74
83
  end
75
84
  r << r3
85
+ else
76
86
 
87
+ r
77
88
  end
78
89
 
79
90
  end
80
91
 
92
+ r4
93
+
81
94
  end
82
95
 
83
96
  # matches a left bracket with a right bracket recursively if necessary
@@ -134,11 +147,21 @@ class RexleXPathParser
134
147
  def match(s)
135
148
 
136
149
  a = []
137
-
138
- #puts 's: ' + s.inspect
150
+
151
+ # it's a function with no arguments
139
152
  # e.g. position()
140
- if /^\w+\(\)$/ =~ s then
153
+ if /^\w+\(\)/ =~ s then
154
+
141
155
  a << s
156
+
157
+ elsif /^\w+\(\)/ =~ s then
158
+
159
+ fn, operator, val = s.match(/^(\w+)\(\)\s+(<|>|=)\s+(\w+)/).captures
160
+
161
+ a << [fn.to_sym, operator.to_sym, val]
162
+ return a
163
+
164
+ # it's a function with arguments
142
165
  elsif s =~ /^\w+\(/
143
166
 
144
167
  found, token, remainder = lmatch(s.chars, '(',')')
@@ -147,6 +170,7 @@ class RexleXPathParser
147
170
  a << token
148
171
  end
149
172
 
173
+ # it contains a predicate
150
174
  # e.g. b[c='45']
151
175
  elsif s =~ /^[\w\/\*]+\[/
152
176
 
@@ -158,16 +182,21 @@ class RexleXPathParser
158
182
  a.concat a2[1..-1]
159
183
 
160
184
  a2
185
+
186
+ # it's an element name e.g. b
161
187
  elsif /^(?<name>[\w\*]+)\// =~ s
162
188
  a << name << match($')
189
+
190
+ # it's something else e.g. @colour='red'
163
191
  else
164
192
 
165
193
  token = s.slice!(/^[@?\w\/:\*\(\)\.]+/)
194
+
166
195
  a << token
167
196
  remainder = s
168
197
  end
169
198
 
170
- return a if remainder.nil? or remainder.empty?
199
+ return a if remainder.nil? or remainder.strip.empty?
171
200
 
172
201
  operator = remainder.slice!(/^\s*(?:\||or)\s*/)
173
202
 
@@ -185,7 +214,7 @@ class RexleXPathParser
185
214
  #
186
215
  def scan(s)
187
216
 
188
- if s =~ /^\w+\(/ then
217
+ if s =~ /^\w+\([^\)]/ then
189
218
 
190
219
  func = s.slice!(/\w+\(/)
191
220
  remainder = s[0..-2]
@@ -203,6 +232,22 @@ class RexleXPathParser
203
232
  end
204
233
  end
205
234
 
206
- alias tokenise match
235
+ #alias tokenise match
236
+ def tokenise(s)
237
+
238
+ if s =~ /\[/ then
239
+ match s
240
+ else
241
+ s.split(/(?=\bor\b)/).flat_map do |x|
242
+
243
+ if /^or\b\s+(?<exp>.*)/ =~ x then
244
+ match(exp).unshift 'or'
245
+ else
246
+ match x
247
+ end
248
+
249
+ end
250
+ end
251
+ end
207
252
 
208
253
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexle-xpath-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  mkV2keVfUpfaTKNzUzo9lt/HSN8u98bD+dZh7rT5z8OBu6Kh0he35JvmyxOTg+Hg
32
32
  u9W2yccAzoPxYA==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-07-09 00:00:00.000000000 Z
34
+ date: 2016-08-07 00:00:00.000000000 Z
35
35
  dependencies: []
36
36
  description:
37
37
  email: james@r0bertson.co.uk
metadata.gz.sig CHANGED
@@ -1 +1,2 @@
1
- ��rEO����r �F [� ��Y�����n��R8�$��������� qA�?�sd˝��i��R��7܃����"ł:f��l��sM���j#���R^�YVz�g ĭӱ��cd��c�u>��E��&����99�8�4��g���4�.��v��seM��5Y���'j0� �R�|�s�����V� k�:;���-��?����1�!@�z4!���|�E@��k<��?���u<�
1
+ t�^]�s`�
2
+ 5���gX��v~$io��ȩi�1R��d( Jr������E�AX����*�H���^`�51\�Ve��5��7�:5��r���=4C�Z�Xu�/}/��ޜ��pY�R �)���o�o�]%C\tw�S`7