lib/regexp-examples/parser.rb in regexp-examples-0.5.2 vs lib/regexp-examples/parser.rb in regexp-examples-0.5.3
- old
+ new
@@ -42,26 +42,26 @@
group = parse_dot_group
when '|'
group = parse_or_group(repeaters)
when '\\'
group = parse_after_backslash_group
- when '^', 'A'
+ when '^'
if @current_position == 0
- group = parse_single_char_group('') # Ignore the "illegal" character
+ group = PlaceHolderGroup.new # Ignore the "illegal" character
else
- raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
+ raise IllegalSyntaxError, "Anchors ('#{next_char}') cannot be supported, as they are not regular"
end
- when '$', 'z', 'Z'
+ when '$'
if @current_position == (regexp_string.length - 1)
- group = parse_single_char_group('') # Ignore the "illegal" character
+ group = PlaceHolderGroup.new # Ignore the "illegal" character
else
- raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
+ raise IllegalSyntaxError, "Anchors ('#{next_char}') cannot be supported, as they are not regular"
end
when /[#\s]/
if @extended
parse_extended_whitespace
- group = parse_single_char_group('') # Ignore the whitespace/comment
+ group = PlaceHolderGroup.new # Ignore the whitespace/comment
else
group = parse_single_char_group(next_char)
end
else
group = parse_single_char_group(next_char)
@@ -101,26 +101,30 @@
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)
raise UnsupportedSyntaxError, "Named properties ({\\p#{$1}}) are not yet supported"
- when rest_of_string =~ /\Ag/ # Subexpression call
+ 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
# TODO: Should this be IllegalSyntaxError ?
raise UnsupportedSyntaxError, "Subexpression calls (\g) are not yet supported"
- when rest_of_string =~ /\A[GbB]/ # Anchors
- raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
- when rest_of_string =~ /\AA/ # Start of string
+ 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 = parse_single_char_group('') # Ignore the "illegal" character
+ group = PlaceHolderGroup.new
else
- raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
+ raise IllegalSyntaxError, "Anchors ('\\#{next_char}') cannot be supported, as they are not regular"
end
- when rest_of_string =~ /\A[zZ]/ # End of string
+ when next_char =~ /[zZ]/ # End of string
if @current_position == (regexp_string.length - 1)
- group = parse_single_char_group('') # Ignore the "illegal" character
+ group = PlaceHolderGroup.new
else
- raise IllegalSyntaxError, "Anchors cannot be supported, as they are not regular"
+ raise IllegalSyntaxError, "Anchors ('\\#{next_char}') cannot be supported, as they are not regular"
end
else
group = parse_single_char_group( next_char )
end
group
@@ -180,10 +184,10 @@
regexp_options_toggle($1, $2)
@current_position += $&.length + 1
if next_char == ':' # e.g. /(?i:subexpr)/
@current_position += 1
else
- return parse_single_char_group('')
+ return PlaceHolderGroup.new
end
when %w(! =).include?(match[2]) # e.g. /(?=lookahead)/, /(?!neglookahead)/
raise IllegalSyntaxError, "Lookaheads are not regular; cannot generate examples"
when %w(! =).include?(match[3]) # e.g. /(?<=lookbehind)/, /(?<!neglookbehind)/
raise IllegalSyntaxError, "Lookbehinds are not regular; cannot generate examples"