rexle-xpath-parser 0.1.1 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eab4821ed8ede5bd6583130f1b8010e6be40f006
4
- data.tar.gz: 7020ccef47cd7f31489057b3c6a7f27749e4bc3b
3
+ metadata.gz: e83436a145b867565019bd5bf8b2a2028fc7e59b
4
+ data.tar.gz: e4b6fffcd15477d8576a7c4f6fd4cce940a7bf84
5
5
  SHA512:
6
- metadata.gz: be752255841e13d4c23bf81b501123df2d07e6887f21d27060d21cc8b92be4fb2d4c85b3ebe48bd04a5ca00a81b67869cd0e99cabd45de31e8321afa15565249
7
- data.tar.gz: 16804a1b8ea249903b318a4b39b4e29e6cc0b972c30dc0f073e1a0aedbe3e255728230a2110d52c63d52df51f2ddb4c97fecb647951485ff85a205f5a50b1cfd
6
+ metadata.gz: a6a435fdf7d5bdd5112bfa582dc297309b2abfe5fd76af224729542f13bf85a1a06cd3131a5b72204aec2601ec221174967791d19c04cfc5d0a2fd1537088995
7
+ data.tar.gz: cbc71821bd6d7449369b1e997780a7c023551cad540851c264cd52078f695e3420409da494c958b43f2882043c4bd4d274b73a1934acaf2eb866b58340f83689
checksums.yaml.gz.sig CHANGED
@@ -1 +1 @@
1
- 1b�bI���( ��|My+�K�>- y[A]C�������@��>���`w��CQ�؋ȯBl`?��;C8<|ʮ�ګ�HbIZ*�' p�T���j]��z������h�+���#ib6wP���IX����:��}�"��v�d2߅�&�z(�;̱K!���hGx��Wg��޽� ���K���->�Au�x<t��C�]( [B�:
1
+ � �=6���� ���8kt��=� q��S ��߃�C�WD���E�Ж8$O^ŕ��aD����4Ol�����!�B��%�^��c�?Owy���F*��y����R�N����T�|ޠ���A���Hz ��e4���eF��]�áX��� QZ믗d1�z�3�#��-}���/�����&���o���u-s ��v�e9���*Ÿ�@6C����"�0��IM.��`|P*tǘ9���x@��S$
data.tar.gz.sig CHANGED
Binary file
@@ -10,7 +10,9 @@ class RexleXPathParser
10
10
  def initialize(string)
11
11
 
12
12
  tokens = tokenise string
13
+ #puts 'tokens: ' + tokens.inspect
13
14
  nested_tokens = tokens.map {|x| scan(x)}
15
+ #puts 'nested_tokens: ' + nested_tokens.inspect
14
16
  @to_a = functionalise nested_tokens
15
17
 
16
18
  end
@@ -24,9 +26,19 @@ class RexleXPathParser
24
26
 
25
27
  a.map do |x|
26
28
 
27
- if x =~ /\w+\[/ then
28
- epath, predicate = x.match(/^([^\[]+)\[([^\]]+)\]/).captures
29
- epath.split('/').map {|e| [:select, e]} + [:predicate, predicate]
29
+ if x =~ /[\w\/]+\[/ then
30
+
31
+ epath, predicate, remainder = x.match(/^([^\[]+)\[([^\]]+)\](.*)/).captures
32
+
33
+ r = if remainder.length > 0 then
34
+ remainder.slice!(0) if remainder[0] == '/'
35
+ r = functionalise(match(remainder))
36
+ else
37
+ []
38
+ end
39
+
40
+ epath.split('/').map {|e| [:select, e]} + [:predicate, predicate] + r
41
+
30
42
  elsif x =~ /\|/
31
43
  [:union]
32
44
  elsif x =~ /\w+\(/
@@ -63,7 +75,35 @@ class RexleXPathParser
63
75
 
64
76
  [c, token.join, remainder]
65
77
  end
78
+
66
79
 
80
+ # matches a right bracket for a left bracket which has already been found.
81
+ #
82
+ def rmatch(a, lchar, rchar)
83
+
84
+ token = []
85
+ c = a.first
86
+ token << c until (c = a.shift; c == lchar or c == rchar or a.empty?)
87
+ token << c
88
+
89
+ if c == lchar then
90
+
91
+ found, tokenx, remainderx = rmatch(a, lchar, rchar)
92
+ token << tokenx
93
+
94
+ # find the rmatch for the starting token
95
+ found, tokenx, remainderx = rmatch(a, lchar, rchar)
96
+ c = found
97
+ token << tokenx
98
+ remainder = remainderx
99
+
100
+ elsif c = rchar
101
+ remainder = a.join
102
+ end
103
+
104
+ [c, token.join, remainder]
105
+ end
106
+
67
107
  # tokeniser e.g. "a | d(c)" #=> ["a", " | ", "d(c)"]
68
108
  #
69
109
  def match(s)
@@ -78,11 +118,19 @@ class RexleXPathParser
78
118
  a << token
79
119
  end
80
120
 
81
- elsif s =~ /^\w+\[/
121
+ elsif s =~ /^[\w\/]+\[/
122
+
82
123
  found, token, remainder = lmatch(s.chars, '[',']')
83
124
  a << token
125
+ a2 = match remainder
126
+
127
+ token << a2.first if a2.first
128
+ a.concat a2[1..-1]
129
+
130
+ a2
131
+
84
132
  else
85
- token = s.slice!(/\w+/)
133
+ token = s.slice!(/^[\w\/]+/)
86
134
  a << token
87
135
  remainder = s
88
136
  end
@@ -95,33 +143,7 @@ class RexleXPathParser
95
143
 
96
144
  a
97
145
  end
98
-
99
- # matches a right bracket for a left bracket which has already been found.
100
- #
101
- def rmatch(a, lchar, rchar)
102
-
103
- token = []
104
- c = a.first
105
- token << c until (c = a.shift; c == lchar or c == rchar or a.empty?)
106
- token << c
107
-
108
- if c == lchar then
109
-
110
- found, tokenx, remainderx = rmatch(a, lchar, rchar)
111
- token << tokenx
112
146
 
113
- # find the rmatch for the starting token
114
- found, tokenx, remainderx = rmatch(a, lchar, rchar)
115
- c = found
116
- token << tokenx
117
- remainder = remainderx
118
-
119
- elsif c = rchar
120
- remainder = a.join
121
- end
122
-
123
- [c, token.join, remainder]
124
- end
125
147
 
126
148
  # accepts a token and drills into it to identify more tokens beneath it
127
149
  #
@@ -141,5 +163,6 @@ class RexleXPathParser
141
163
  end
142
164
 
143
165
  alias tokenise match
144
-
166
+
167
+
145
168
  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.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  adFNS7+S3VVpQqBQ7hIMoNW5ldGHINll6Z0dbjsCO8OFGOkrnzt9ovLffOXuQHpT
32
32
  Gpk2If0KQMuV2Q==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-06-04 00:00:00.000000000 Z
34
+ date: 2015-06-05 00:00:00.000000000 Z
35
35
  dependencies: []
36
36
  description:
37
37
  email: james@r0bertson.co.uk
metadata.gz.sig CHANGED
Binary file