regexp_parser 2.5.0 → 2.6.2
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 +4 -4
- data/CHANGELOG.md +74 -39
- data/README.md +45 -31
- data/lib/regexp_parser/expression/base.rb +17 -9
- data/lib/regexp_parser/expression/classes/backreference.rb +14 -2
- data/lib/regexp_parser/expression/classes/escape_sequence.rb +1 -1
- data/lib/regexp_parser/expression/classes/group.rb +10 -0
- data/lib/regexp_parser/expression/classes/unicode_property.rb +1 -1
- data/lib/regexp_parser/expression/methods/human_name.rb +43 -0
- data/lib/regexp_parser/expression/methods/match_length.rb +8 -4
- data/lib/regexp_parser/expression/shared.rb +11 -2
- data/lib/regexp_parser/expression.rb +1 -0
- data/lib/regexp_parser/parser.rb +16 -4
- data/lib/regexp_parser/scanner/scanner.rl +2 -2
- data/lib/regexp_parser/scanner.rb +582 -578
- data/lib/regexp_parser/version.rb +1 -1
- metadata +3 -2
data/lib/regexp_parser/parser.rb
CHANGED
@@ -235,7 +235,15 @@ class Regexp::Parser
|
|
235
235
|
when :number, :number_ref
|
236
236
|
node << Backreference::Number.new(token, active_opts)
|
237
237
|
when :number_recursion_ref
|
238
|
-
node << Backreference::NumberRecursionLevel.new(token, active_opts)
|
238
|
+
node << Backreference::NumberRecursionLevel.new(token, active_opts).tap do |exp|
|
239
|
+
# TODO: should split off new token number_recursion_rel_ref and new
|
240
|
+
# class NumberRelativeRecursionLevel in v3.0.0 to get rid of this
|
241
|
+
if exp.text =~ /[<'][+-]/
|
242
|
+
assign_effective_number(exp)
|
243
|
+
else
|
244
|
+
exp.effective_number = exp.number
|
245
|
+
end
|
246
|
+
end
|
239
247
|
when :number_call
|
240
248
|
node << Backreference::NumberCall.new(token, active_opts)
|
241
249
|
when :number_rel_ref
|
@@ -254,6 +262,8 @@ class Regexp::Parser
|
|
254
262
|
def assign_effective_number(exp)
|
255
263
|
exp.effective_number =
|
256
264
|
exp.number + total_captured_group_count + (exp.number < 0 ? 1 : 0)
|
265
|
+
exp.effective_number > 0 ||
|
266
|
+
raise(ParserError, "Invalid reference: #{exp.reference}")
|
257
267
|
end
|
258
268
|
|
259
269
|
def conditional(token)
|
@@ -569,15 +579,17 @@ class Regexp::Parser
|
|
569
579
|
# an instance of Backreference::Number, its #referenced_expression is set to
|
570
580
|
# the instance of Group::Capture that it refers to via its number.
|
571
581
|
def assign_referenced_expressions
|
572
|
-
targets = {}
|
573
582
|
# find all referencable expressions
|
583
|
+
targets = { 0 => root }
|
574
584
|
root.each_expression do |exp|
|
575
585
|
exp.is_a?(Group::Capture) && targets[exp.identifier] = exp
|
576
586
|
end
|
577
587
|
# assign them to any refering expressions
|
578
588
|
root.each_expression do |exp|
|
579
|
-
exp.respond_to?(:reference)
|
580
|
-
|
589
|
+
next unless exp.respond_to?(:reference)
|
590
|
+
|
591
|
+
exp.referenced_expression = targets[exp.reference] ||
|
592
|
+
raise(ParserError, "Invalid reference: #{exp.reference}")
|
581
593
|
end
|
582
594
|
end
|
583
595
|
end # module Regexp::Parser
|
@@ -90,8 +90,8 @@
|
|
90
90
|
group_options = '?' . ( [^!#'():<=>~]+ . ':'? ) ?;
|
91
91
|
|
92
92
|
group_ref = [gk];
|
93
|
-
group_name_id_ab = ([
|
94
|
-
group_name_id_sq = ([^0-9\-']
|
93
|
+
group_name_id_ab = ([^!0-9\->] | utf8_multibyte) . ([^>] | utf8_multibyte)*;
|
94
|
+
group_name_id_sq = ([^0-9\-'] | utf8_multibyte) . ([^'] | utf8_multibyte)*;
|
95
95
|
group_number = '-'? . [1-9] . [0-9]*;
|
96
96
|
group_level = [+\-] . [0-9]+;
|
97
97
|
|