ruby_grammar_builder 1.1.11 → 1.1.12

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
  SHA256:
3
- metadata.gz: 58d3e3e3fe4b1e992aa23abace8ae7ad9d0e7ca6b3e6b1237e1f9f800317fd81
4
- data.tar.gz: 2b2423273398cc66d8637d97e41434d7a62c270477b224d5343c339e7f51a33b
3
+ metadata.gz: 11a8a1b576e0b4aa298d5216fab27ecafbdfb89bdbcbe1604699b17f944e6773
4
+ data.tar.gz: 705f94bbb89097d41510042c581bab138bfbcb74bd703e540df429524547c6fd
5
5
  SHA512:
6
- metadata.gz: 21fb51484f36fcdf93a619ac6e29a96ac2fb50d26dfd3e2a8eb79d2ef7a0c83ec930817045d7340abf9aff5edc9369cb09d2ca4d34fb2c90c280b67527cd817b
7
- data.tar.gz: 10c1c631a8bca900ff2c40d9f38ada75cdd310bbcab36cace76f80d745b655f55fbe338fa5d015932a2eef694bbee5434c084e500f0afeb03803b9671b24a0bf
6
+ metadata.gz: e3121cb4e1efddf789f32c6c79a77ebd35bee9417ba654f33d6d99b4672ebffc09d4f54254826477f44ac75b38ff06c3efab0a1e73c73e56627021bc7c8e4411
7
+ data.tar.gz: 20de057ae05b377087bcbe77e3d42ddd12069640538e98a0507d05d90ffe75c2092be09820d9b7341327294ff86d4671896aeea21be4007d59954dee76196a45
@@ -42,7 +42,7 @@ class PatternBase
42
42
  # @return [Boolean] can this capture become capture group 0
43
43
  #
44
44
  def optimize_outer_group?
45
- needs_to_capture? and @next_pattern.nil?
45
+ self.needs_to_capture? and @next_pattern.nil?
46
46
  end
47
47
 
48
48
  #
@@ -73,18 +73,6 @@ class PatternBase
73
73
  new_pattern.insert!(pattern).freeze
74
74
  end
75
75
 
76
- #
77
- # Adds a capture group if needed
78
- #
79
- # @param [String] regex_as_string the pattern as a string
80
- #
81
- # @return [String] the pattern, potentially with a capture group
82
- #
83
- def add_capture_group_if_needed(regex_as_string)
84
- regex_as_string = "(#{regex_as_string})" if needs_to_capture?
85
- regex_as_string
86
- end
87
-
88
76
  #
89
77
  # Uses a block to transform all Patterns in the list
90
78
  #
@@ -306,7 +294,7 @@ class PatternBase
306
294
  #
307
295
  def to_tag
308
296
  output = {
309
- match: evaluate,
297
+ match: self.evaluate(),
310
298
  }
311
299
 
312
300
  output[:captures] = convert_group_attributes_to_captures(collect_group_attributes)
@@ -570,7 +558,12 @@ class PatternBase
570
558
  def do_evaluate_self(groups)
571
559
  match = @match
572
560
  match = match.evaluate(groups) if match.is_a? PatternBase
573
- add_capture_group_if_needed(match)
561
+ if self.needs_to_capture?
562
+ match = "(#{match})"
563
+ elsif not string_single_entity?(match)
564
+ match = "(?:#{match})"
565
+ end
566
+ return match
574
567
  end
575
568
 
576
569
  #
@@ -611,7 +604,7 @@ class PatternBase
611
604
 
612
605
  # (see string_single_entity)
613
606
  def single_entity?
614
- string_single_entity? evaluate
607
+ return string_single_entity?( self.evaluate() )
615
608
  end
616
609
 
617
610
  # does this pattern contain no capturing groups
@@ -696,7 +689,7 @@ class PatternBase
696
689
  #
697
690
  def do_collect_self_groups(next_group)
698
691
  groups = []
699
- groups << {group: next_group}.merge(@arguments) if needs_to_capture?
692
+ groups << {group: next_group}.merge(@arguments) if self.needs_to_capture?
700
693
  groups
701
694
  end
702
695
 
@@ -152,7 +152,13 @@ class RepeatablePattern < PatternBase
152
152
 
153
153
  # (see PatternBase#do_evaluate_self)
154
154
  def do_evaluate_self(groups)
155
- add_capture_group_if_needed(add_quantifier_options_to(@match, groups))
155
+ match = add_quantifier_options_to(@match, groups)
156
+ if self.needs_to_capture?
157
+ match = "(#{match})"
158
+ elsif not string_single_entity?(match)
159
+ match = "(?:#{match})"
160
+ end
161
+ return match
156
162
  end
157
163
 
158
164
  # controls weather @arguments[:at_most] et. al. set @at_most et. al.
@@ -52,21 +52,23 @@ end
52
52
  # @return [Boolean] if the string represents an single regex entity
53
53
  def string_single_entity?(regex_string)
54
54
  normal_char = '[a-zA-Z0-9_\-@&%#\'"<>=\/\.,`~\s;:!]'
55
+ escape_sequence = '\\\\[\w\W]'
56
+ character_class_that_doesnt_contain_bracket = '\[[^\]]*\]'
55
57
  # normal char
56
58
  if regex_string =~ /^#{normal_char}$/
57
59
  return true
58
60
  end
59
61
  # escape sequence (all are valid, even stuff like \@ ("\\@") or "\\" + "\n" )
60
- if regex_string =~ /^\\[\w\W]$/
62
+ if regex_string =~ /^#{escape_sequence}$/
61
63
  return true
62
64
  end
63
65
  # character class that doesn't contain ]
64
- if regex_string =~ /^\[[^\]]*\]$/
66
+ if regex_string =~ /^#{character_class_that_doesnt_contain_bracket}$/
65
67
  return true
66
68
  end
67
69
 
68
70
  # fail if more than one of any of the above
69
- if regex_string =~ /^(#{normal_char}|\\[\w\W]|\[[^\]]*\]){2,}$/
71
+ if regex_string =~ /^(#{normal_char}|#{escape_sequence}|#{character_class_that_doesnt_contain_bracket}){2,}$/
70
72
  return false
71
73
  end
72
74
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_grammar_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.11
4
+ version: 1.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Hykin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-05-30 00:00:00.000000000 Z
12
+ date: 2023-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deep_clone