cannonbol 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f21caaed4e70356c5f043a524241bf103d8eddd8
4
- data.tar.gz: 4ce959eb2fa8b569860d59bbb3de119b2b5c11ae
3
+ metadata.gz: a648c8cfd875765efac54d699ee04acbbcd7f422
4
+ data.tar.gz: 47910f41c8d1cfb8953247fa8b788a09ce7d20fd
5
5
  SHA512:
6
- metadata.gz: 98cf5aa3d8ea84c36503b5cfde8d22f833957ac44c650bf0629bf8ca44b672cc56d66408e0ce732ebc83c6ee3d71923a7497ca7c2cecd70fa8e37e149db0f5b4
7
- data.tar.gz: 0ac7d0acbb284131ab62eca5456ad3152877949c51282cf40cc11a896fb1e752028bc1f66f036e0e4157e35a4afca933c936c3846212c2d3cb175c7bf4b494a8
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 easy!
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 alongside ruby!
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
 
@@ -1,3 +1,3 @@
1
1
  module Cannonbol
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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
- @cannonbol_string.dup.tap do |new_s|
23
- new_s[@match_start..@match_end] = "" if @match_end >= 0
24
- new_s.insert(@match_start, s)
25
- end
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 anchor and !match
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 < Array
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 < self.length
151
- s = self[i]._match?(needle, *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
- self << p1 << p2
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 < self.length and i >= 0
168
- s[i] = self[i]._match?(needle, *(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 == self.length
166
+ [i-1, s] if i == @params.length
172
167
  end
173
168
 
174
169
  def initialize(p1, p2)
175
- self << p1 << p2
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
- @cannonbol_regex ||= Regexp.new("^#{self.source}", self.options | (needle.ignore_case ? Regexp::IGNORECASE : 0) )
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.0.0
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-17 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler