lib/regexp-examples/parser.rb in regexp-examples-1.0.0 vs lib/regexp-examples/parser.rb in regexp-examples-1.0.1
- old
+ new
@@ -97,25 +97,26 @@
group = parse_single_char_group( parse_escape_sequence($1) )
when rest_of_string =~ /\Au(\h{4}|\{\h{1,4}\})/ # Unicode sequence
@current_position += $1.length
sequence = $1.match(/\h{1,4}/)[0] # Strip off "{" and "}"
group = parse_single_char_group( parse_unicode_sequence(sequence) )
- when rest_of_string =~ /\Ap\{(\^?)([^}]+)\}/ # Named properties
- @current_position += ($1.length + $2.length + 2)
+ when rest_of_string =~ /\A(p)\{(\^?)([^}]+)\}/i # Named properties
+ @current_position += ($2.length + $3.length + 2)
+ is_negative = ($1 == "P") ^ ($2 == "^") # Beware of double negatives! E.g. /\P{^Space}/
group = CharGroup.new(
- if($1 == "^")
- CharSets::Any.dup - NamedPropertyCharMap[$2.downcase]
+ if is_negative
+ CharSets::Any.dup - NamedPropertyCharMap[$3.downcase]
else
- NamedPropertyCharMap[$2.downcase]
+ NamedPropertyCharMap[$3.downcase]
end,
@ignorecase
)
when next_char == 'K' # Keep (special lookbehind that CAN be supported safely!)
group = PlaceHolderGroup.new
when next_char == 'R' # Linebreak
group = CharGroup.new(["\r\n", "\n", "\v", "\f", "\r"], @ignorecase) # A bit hacky...
when next_char == 'g' # Subexpression call
- raise IllegalSyntaxError, "Subexpression calls (\g) are not yet supported"
+ raise IllegalSyntaxError, "Subexpression calls (\\g) cannot be supported, as they are not regular"
when next_char =~ /[bB]/ # Anchors
raise IllegalSyntaxError, "Anchors ('\\#{next_char}') cannot be supported, as they are not regular"
when next_char =~ /[AG]/ # Start of string
if @current_position == 1
group = PlaceHolderGroup.new