cannonbol 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/cannonbol/version.rb +1 -1
- data/lib/cannonbol.rb +35 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a648c8cfd875765efac54d699ee04acbbcd7f422
|
4
|
+
data.tar.gz: 47910f41c8d1cfb8953247fa8b788a09ce7d20fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dea1273241b4517b6542de8f557f2401fcd6880330d5662edc533428e3878fc15680bfb8a5ae0537c21cfa2a7a62a85dc12e080a74922e8fdbd5a053492d66d
|
7
|
+
data.tar.gz: 14bd53603b2c261ea45cc25f9593fc38c7437aa040eef859651e0b428e40525761b5842237996818f27fecf2d6e45db599fc1dfd5711daa2e216cc0704a57540
|
data/README.md
CHANGED
@@ -4,11 +4,11 @@ CannonBol is a ruby DSL for patten matching based on SNOBOL4 and SPITBOL.
|
|
4
4
|
|
5
5
|
* Makes complex patterns easier to read and write!
|
6
6
|
* Combine regexes, plain strings and powerful new primitive match functions!
|
7
|
-
* Makes capturing match results
|
7
|
+
* Makes capturing match results simple!
|
8
8
|
* Allows recursive patterns!
|
9
9
|
* Complete SNOBOL4 + SPITBOL extensions!
|
10
10
|
* Based on the well documented, proven SNOBOL4 language!
|
11
|
-
* Simple syntax looks great
|
11
|
+
* Simple syntax looks great within your ruby code!
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
@@ -30,7 +30,7 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
### Basic Matching `- &, |, capture?, match_any, match_all`
|
32
32
|
|
33
|
-
Strings, Regexes and primitives are combined using & (concatenation) and | (alternation) operators
|
33
|
+
Strings, Regexes and primitives are combined using & (concatenation) and | (alternation) operators. Once the gem is installed you are good to go.
|
34
34
|
|
35
35
|
Here is a simple pattern that matches a simple noun clause:
|
36
36
|
|
data/lib/cannonbol/version.rb
CHANGED
data/lib/cannonbol.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "cannonbol/version"
|
2
|
-
|
3
1
|
module Cannonbol
|
4
2
|
|
5
3
|
class MatchFailed < Exception; end
|
@@ -19,10 +17,10 @@ module Cannonbol
|
|
19
17
|
end
|
20
18
|
|
21
19
|
def replace_match_with(s)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
before_match = ""
|
21
|
+
before_match = @cannonbol_string[0..@match_start-1] if @match_start > 0
|
22
|
+
after_match = @cannonbol_string[@match_end+1..-1] || ""
|
23
|
+
before_match + s + after_match
|
26
24
|
end
|
27
25
|
|
28
26
|
end
|
@@ -54,7 +52,7 @@ module Cannonbol
|
|
54
52
|
@success_blocks = []
|
55
53
|
@ignore_case = ignore_case
|
56
54
|
match = pattern._match?(self)
|
57
|
-
break if
|
55
|
+
break if !match and anchor
|
58
56
|
end
|
59
57
|
rescue MatchFailed
|
60
58
|
end
|
@@ -130,14 +128,10 @@ module Cannonbol
|
|
130
128
|
|
131
129
|
end
|
132
130
|
|
133
|
-
class Pattern
|
131
|
+
class Pattern
|
134
132
|
|
135
133
|
include Operators
|
136
134
|
|
137
|
-
def to_s
|
138
|
-
"#{self.class.name}[#{self.collect(&:to_s).join(', ')}]"
|
139
|
-
end
|
140
|
-
|
141
135
|
def __match?(needle)
|
142
136
|
[]
|
143
137
|
end
|
@@ -147,16 +141,17 @@ module Cannonbol
|
|
147
141
|
class Choose < Pattern
|
148
142
|
|
149
143
|
def __match?(needle, i = 0, s = [])
|
150
|
-
while i <
|
151
|
-
s =
|
144
|
+
while i < @params.length
|
145
|
+
s = @params[i]._match?(needle, *s)
|
152
146
|
return [i, s] if s
|
153
147
|
s = []
|
154
148
|
i += 1
|
155
149
|
end
|
150
|
+
nil
|
156
151
|
end
|
157
152
|
|
158
153
|
def initialize(p1, p2)
|
159
|
-
|
154
|
+
@params = [p1, p2]
|
160
155
|
end
|
161
156
|
|
162
157
|
end
|
@@ -164,15 +159,15 @@ module Cannonbol
|
|
164
159
|
class Concat < Pattern
|
165
160
|
|
166
161
|
def __match?(needle, i = 0, s = [])
|
167
|
-
while i <
|
168
|
-
s[i] =
|
162
|
+
while i < @params.length and i >= 0
|
163
|
+
s[i] = @params[i]._match?(needle, *(s[i] || []))
|
169
164
|
i = s[i] ? i+1 : i-1
|
170
165
|
end
|
171
|
-
[i-1, s] if i ==
|
166
|
+
[i-1, s] if i == @params.length
|
172
167
|
end
|
173
168
|
|
174
169
|
def initialize(p1, p2)
|
175
|
-
|
170
|
+
@params = [p1, p2]
|
176
171
|
end
|
177
172
|
|
178
173
|
end
|
@@ -311,7 +306,6 @@ module Cannonbol
|
|
311
306
|
@initial_param_value = opts
|
312
307
|
end
|
313
308
|
@block = block
|
314
|
-
self << @param << @block
|
315
309
|
end
|
316
310
|
|
317
311
|
def self.parameter(name, &post_processor)
|
@@ -568,7 +562,15 @@ class Regexp
|
|
568
562
|
include Cannonbol::Operators
|
569
563
|
|
570
564
|
def __match?(needle, thread_state = nil)
|
571
|
-
|
565
|
+
if defined? Opal
|
566
|
+
options = ""
|
567
|
+
options += "m" if `#{self}.multiline`
|
568
|
+
options += "g" if `#{self}.global`
|
569
|
+
options += "i" if needle.ignore_case or `#{self}.ignoreCase`
|
570
|
+
else
|
571
|
+
options = self.options | (needle.ignore_case ? Regexp::IGNORECASE : 0)
|
572
|
+
end
|
573
|
+
@cannonbol_regex ||= Regexp.new("^#{self.source}", options )
|
572
574
|
if thread_state
|
573
575
|
needle.pull(thread_state)
|
574
576
|
elsif m = @cannonbol_regex.match(needle.remaining_string)
|
@@ -578,6 +580,18 @@ class Regexp
|
|
578
580
|
|
579
581
|
end
|
580
582
|
|
583
|
+
if defined? Opal
|
584
|
+
|
585
|
+
class Proc
|
586
|
+
|
587
|
+
def parameters
|
588
|
+
/.*function[^(]*\(([^)]*)\)/.match(`#{self}.toString()`)[1].split(",").collect { |param| [:req, param.strip.to_sym]}
|
589
|
+
end
|
590
|
+
|
591
|
+
end
|
592
|
+
|
593
|
+
end
|
594
|
+
|
581
595
|
module Enumerable
|
582
596
|
|
583
597
|
def match_any
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cannonbol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- catmando
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|