mirror of
https://github.com/ruby/ruby.git
synced 2025-09-17 09:33:59 +02:00
parent
ea529dd409
commit
ec1eda7b62
5 changed files with 72 additions and 2 deletions
|
@ -565,23 +565,38 @@ pm_regexp_parse_group(pm_regexp_parser_t *parser) {
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
pm_regexp_parse_item(pm_regexp_parser_t *parser) {
|
pm_regexp_parse_item(pm_regexp_parser_t *parser) {
|
||||||
switch (*parser->cursor++) {
|
switch (*parser->cursor) {
|
||||||
case '^':
|
case '^':
|
||||||
case '$':
|
case '$':
|
||||||
|
parser->cursor++;
|
||||||
return true;
|
return true;
|
||||||
case '\\':
|
case '\\':
|
||||||
|
parser->cursor++;
|
||||||
if (!pm_regexp_char_is_eof(parser)) {
|
if (!pm_regexp_char_is_eof(parser)) {
|
||||||
parser->cursor++;
|
parser->cursor++;
|
||||||
}
|
}
|
||||||
return pm_regexp_parse_quantifier(parser);
|
return pm_regexp_parse_quantifier(parser);
|
||||||
case '(':
|
case '(':
|
||||||
|
parser->cursor++;
|
||||||
return pm_regexp_parse_group(parser) && pm_regexp_parse_quantifier(parser);
|
return pm_regexp_parse_group(parser) && pm_regexp_parse_quantifier(parser);
|
||||||
case '[':
|
case '[':
|
||||||
|
parser->cursor++;
|
||||||
return pm_regexp_parse_lbracket(parser) && pm_regexp_parse_quantifier(parser);
|
return pm_regexp_parse_lbracket(parser) && pm_regexp_parse_quantifier(parser);
|
||||||
default:
|
default: {
|
||||||
|
size_t width;
|
||||||
|
if (!parser->encoding_changed) {
|
||||||
|
width = pm_encoding_utf_8_char_width(parser->cursor, (ptrdiff_t) (parser->end - parser->cursor));
|
||||||
|
} else {
|
||||||
|
width = parser->encoding->char_width(parser->cursor, (ptrdiff_t) (parser->end - parser->cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width == 0) return false; // TODO: add appropriate error
|
||||||
|
parser->cursor += width;
|
||||||
|
|
||||||
return pm_regexp_parse_quantifier(parser);
|
return pm_regexp_parse_quantifier(parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* expression : item+
|
* expression : item+
|
||||||
|
|
3
test/prism/fixtures/regex_char_width.txt
Normal file
3
test/prism/fixtures/regex_char_width.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# encoding: sjis
|
||||||
|
/Ⅷ(?<a>.)Ⅹ(?<b>.)/ =~ 'ⅧaⅩb'
|
||||||
|
[a, b]
|
|
@ -55,6 +55,7 @@ module Prism
|
||||||
dos_endings.txt
|
dos_endings.txt
|
||||||
heredocs_with_ignored_newlines.txt
|
heredocs_with_ignored_newlines.txt
|
||||||
regex.txt
|
regex.txt
|
||||||
|
regex_char_width.txt
|
||||||
spanning_heredoc.txt
|
spanning_heredoc.txt
|
||||||
spanning_heredoc_newlines.txt
|
spanning_heredoc_newlines.txt
|
||||||
tilde_heredocs.txt
|
tilde_heredocs.txt
|
||||||
|
|
|
@ -30,6 +30,7 @@ module Prism
|
||||||
todos = %w[
|
todos = %w[
|
||||||
heredocs_nested.txt
|
heredocs_nested.txt
|
||||||
newline_terminated.txt
|
newline_terminated.txt
|
||||||
|
regex_char_width.txt
|
||||||
seattlerb/bug169.txt
|
seattlerb/bug169.txt
|
||||||
seattlerb/dstr_evstr.txt
|
seattlerb/dstr_evstr.txt
|
||||||
seattlerb/heredoc_squiggly_interp.txt
|
seattlerb/heredoc_squiggly_interp.txt
|
||||||
|
|
50
test/prism/snapshots/regex_char_width.txt
Normal file
50
test/prism/snapshots/regex_char_width.txt
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
@ ProgramNode (location: (2,0)-(3,6))
|
||||||
|
├── locals: [:a, :b]
|
||||||
|
└── statements:
|
||||||
|
@ StatementsNode (location: (2,0)-(3,6))
|
||||||
|
└── body: (length: 2)
|
||||||
|
├── @ MatchWriteNode (location: (2,0)-(2,36))
|
||||||
|
│ ├── call:
|
||||||
|
│ │ @ CallNode (location: (2,0)-(2,36))
|
||||||
|
│ │ ├── flags: ∅
|
||||||
|
│ │ ├── receiver:
|
||||||
|
│ │ │ @ RegularExpressionNode (location: (2,0)-(2,22))
|
||||||
|
│ │ │ ├── flags: ∅
|
||||||
|
│ │ │ ├── opening_loc: (2,0)-(2,1) = "/"
|
||||||
|
│ │ │ ├── content_loc: (2,1)-(2,21) = "\x{E285}\xA7(?<a>.)\x{E285}\xA9(?<b>.)"
|
||||||
|
│ │ │ ├── closing_loc: (2,21)-(2,22) = "/"
|
||||||
|
│ │ │ └── unescaped: "\x{E285}\xA7(?<a>.)\x{E285}\xA9(?<b>.)"
|
||||||
|
│ │ ├── call_operator_loc: ∅
|
||||||
|
│ │ ├── name: :=~
|
||||||
|
│ │ ├── message_loc: (2,23)-(2,25) = "=~"
|
||||||
|
│ │ ├── opening_loc: ∅
|
||||||
|
│ │ ├── arguments:
|
||||||
|
│ │ │ @ ArgumentsNode (location: (2,26)-(2,36))
|
||||||
|
│ │ │ ├── flags: ∅
|
||||||
|
│ │ │ └── arguments: (length: 1)
|
||||||
|
│ │ │ └── @ StringNode (location: (2,26)-(2,36))
|
||||||
|
│ │ │ ├── flags: ∅
|
||||||
|
│ │ │ ├── opening_loc: (2,26)-(2,27) = "'"
|
||||||
|
│ │ │ ├── content_loc: (2,27)-(2,35) = "\x{E285}\xA7a\x{E285}\xA9b"
|
||||||
|
│ │ │ ├── closing_loc: (2,35)-(2,36) = "'"
|
||||||
|
│ │ │ └── unescaped: "\x{E285}\xA7a\x{E285}\xA9b"
|
||||||
|
│ │ ├── closing_loc: ∅
|
||||||
|
│ │ └── block: ∅
|
||||||
|
│ └── targets: (length: 2)
|
||||||
|
│ ├── @ LocalVariableTargetNode (location: (2,7)-(2,8))
|
||||||
|
│ │ ├── name: :a
|
||||||
|
│ │ └── depth: 0
|
||||||
|
│ └── @ LocalVariableTargetNode (location: (2,17)-(2,18))
|
||||||
|
│ ├── name: :b
|
||||||
|
│ └── depth: 0
|
||||||
|
└── @ ArrayNode (location: (3,0)-(3,6))
|
||||||
|
├── flags: ∅
|
||||||
|
├── elements: (length: 2)
|
||||||
|
│ ├── @ LocalVariableReadNode (location: (3,1)-(3,2))
|
||||||
|
│ │ ├── name: :a
|
||||||
|
│ │ └── depth: 0
|
||||||
|
│ └── @ LocalVariableReadNode (location: (3,4)-(3,5))
|
||||||
|
│ ├── name: :b
|
||||||
|
│ └── depth: 0
|
||||||
|
├── opening_loc: (3,0)-(3,1) = "["
|
||||||
|
└── closing_loc: (3,5)-(3,6) = "]"
|
Loading…
Add table
Add a link
Reference in a new issue