Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/constraints/extensional_regexp.rb | 105 | 68 | 100.00%
|
100.00%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 module Gecode |
2 module Mixin |
3 # Specifies an integer regexp that matches +regexp+ repeated between |
4 # +at_least+ and +at_most+ times (inclusive). If +at_most+ is |
5 # omitted then no upper bound is placed. If both +at_least+ and |
6 # +at_most+ are omitted then no bounds are placed. |
7 # |
8 # See IntEnum::Extensional::RegexpConstraint for the |
9 # allowed syntax of +regexp+. |
10 def repeat(regexp, at_least = nil, at_most = nil) |
11 unless at_least.nil? or at_least.kind_of? Fixnum |
12 raise TypeError, |
13 "Expected the at_least argument to be a Fixnum, got #{at_least.class}" |
14 end |
15 unless at_most.nil? or at_most.kind_of?(Fixnum) |
16 raise TypeError, |
17 "Expected the at_most argument to be a Fixnum, got #{at_most.class}" |
18 end |
19 |
20 reg = Util::Extensional.parse_regexp regexp |
21 if at_most.nil? |
22 if at_least.nil? |
23 reg.send '*' |
24 else |
25 reg.send('()', at_least) |
26 end |
27 else |
28 reg.send('()', at_least, at_most) |
29 end |
30 end |
31 |
32 # Matches +regexp+ repeated zero or one time (i.e. like '?' in normal |
33 # regexps). Produces the same result as calling |
34 # |
35 # repeat(regexp, 0, 1) |
36 def at_most_once(regexp) |
37 repeat(regexp, 0, 1) |
38 end |
39 |
40 # Matches +regexp+ repeated at least one time (i.e. like '+' in normal |
41 # regexps). Produces the same result as calling |
42 # |
43 # repeat(regexp, 1) |
44 def at_least_once(regexp) |
45 repeat(regexp, 1) |
46 end |
47 |
48 # Matches any of the specified +regexps+. |
49 def any(*regexps) |
50 regexps.inject(Gecode::Raw::REG.new) do |result, regexp| |
51 result | Util::Extensional.parse_regexp(regexp) |
52 end |
53 end |
54 end |
55 |
56 module Util::Extensional |
57 module_function |
58 |
59 # Parses a regular expression over the integer domain, returning |
60 # an instance of Gecode::REG . |
61 # |
62 # Pseudo-BNF of the integer regexp representation: |
63 # regexp ::= <Fixnum> | <TrueClass> | <FalseClass> | <Gecode::Raw::REG> |
64 # | [<regexp>, ...] |
65 def parse_regexp(regexp) |
66 # Check the involved types. |
67 unless regexp.kind_of? Enumerable |
68 regexp = [regexp] |
69 end |
70 regexp.to_a.flatten.each do |element| |
71 unless element.kind_of?(Fixnum) or element.kind_of?(Gecode::Raw::REG) or |
72 element.kind_of?(TrueClass) or element.kind_of?(FalseClass) |
73 raise TypeError, |
74 "Can't translate #{element.class} into integer or boolean regexp." |
75 end |
76 end |
77 |
78 # Convert it into a regexp. |
79 internal_parse_regexp(regexp) |
80 end |
81 |
82 private |
83 |
84 # Recursively converts arg into an instance of Gecode::REG. It is |
85 # assumed that arg is of kind Gecode::Raw::REG, Fixnum, TrueClass, |
86 # FalseClass or Enumerable. |
87 def self.internal_parse_regexp(arg) |
88 case arg |
89 when Gecode::Raw::REG |
90 arg |
91 when Fixnum |
92 Gecode::Raw::REG.new(arg) |
93 when TrueClass |
94 Gecode::Raw::REG.new(1) |
95 when FalseClass |
96 Gecode::Raw::REG.new(0) |
97 when Enumerable |
98 # Recursively convert the elements of the arg. |
99 arg.inject(Gecode::Raw::REG.new) do |regexp, element| |
100 regexp += internal_parse_regexp(element) |
101 end |
102 end |
103 end |
104 end |
105 end |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0