Skip to content

Commit

Permalink
Support \g, \k without group id as literal escapes
Browse files Browse the repository at this point in the history
[#65]
  • Loading branch information
jaynetics committed Sep 12, 2020
1 parent 74856d9 commit 84b5650
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/regexp_parser/scanner/scanner.rl
Expand Up @@ -128,7 +128,7 @@
utf8_4_byte = (0xf0..0xf4 0x80..0xbf 0x80..0xbf 0x80..0xbf);

non_literal_escape = char_type_char | anchor_char | escaped_ascii |
group_ref | keep_mark | [xucCM];
keep_mark | [xucCM];

non_set_escape = (anchor_char - 'b') | group_ref | keep_mark |
multi_codepoint_char_type | [0-9cCM];
Expand Down
4 changes: 4 additions & 0 deletions spec/scanner/escapes_spec.rb
Expand Up @@ -13,6 +13,10 @@

include_examples 'scan', 'c\qt', 1 => [:escape, :literal, '\q', 1, 3]

# these incomplete ref/call sequences are treated as literal escapes by Ruby
include_examples 'scan', 'c\gt', 1 => [:escape, :literal, '\g', 1, 3]
include_examples 'scan', 'c\kt', 1 => [:escape, :literal, '\k', 1, 3]

include_examples 'scan', 'a\012c', 1 => [:escape, :octal, '\012', 1, 5]
include_examples 'scan', 'a\0124', 1 => [:escape, :octal, '\012', 1, 5]
include_examples 'scan', '\712+7', 0 => [:escape, :octal, '\712', 0, 4]
Expand Down

0 comments on commit 84b5650

Please sign in to comment.