aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-30 13:09:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-30 13:09:51 +0000
commitca1be3aa301dd76e8407b3630683248740ede7f9 (patch)
tree56101924ea19f2369ae950a612dd8832daf9e927 /parse.y
parentd99099928801314a4c15c998c93b8d6ee29d1724 (diff)
downloadruby-ca1be3aa301dd76e8407b3630683248740ede7f9.tar.gz
parse.y: parser_tokadd_codepoint
* parse.y (parser_tokadd_codepoint): extract from parser_tokadd_utf8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y44
1 files changed, 22 insertions, 22 deletions
diff --git a/parse.y b/parse.y
index a06f061388..3c1e88d4e7 100644
--- a/parse.y
+++ b/parse.y
@@ -5757,6 +5757,24 @@ parser_tok_hex(struct parser_params *parser, size_t *numlen)
#define tokcopy(n) memcpy(tokspace(n), lex_p - (n), (n))
+static void
+parser_tokadd_codepoint(struct parser_params *parser, rb_encoding **encp,
+ int string_literal, int regexp_literal,
+ int codepoint, int numlen)
+{
+ lex_p += numlen;
+ if (regexp_literal) {
+ tokcopy(numlen);
+ }
+ else if (codepoint >= 0x80) {
+ *encp = rb_utf8_encoding();
+ if (string_literal) tokaddmbc(codepoint, *encp);
+ }
+ else if (string_literal) {
+ tokadd(codepoint);
+ }
+}
+
/* return value is for ?\u3042 */
static int
parser_tokadd_utf8(struct parser_params *parser, rb_encoding **encp,
@@ -5788,17 +5806,8 @@ parser_tokadd_utf8(struct parser_params *parser, rb_encoding **encp,
yyerror("invalid Unicode codepoint (too large)");
return 0;
}
- lex_p += numlen;
- if (regexp_literal) {
- tokcopy((int)numlen);
- }
- else if (codepoint >= 0x80) {
- *encp = rb_utf8_encoding();
- if (string_literal) tokaddmbc(codepoint, *encp);
- }
- else if (string_literal) {
- tokadd(codepoint);
- }
+ parser_tokadd_codepoint(parser, encp,string_literal, regexp_literal,
+ codepoint, (int)numlen);
} while (string_literal && (peek(' ') || peek('\t')));
if (!peek(close_brace)) {
@@ -5815,17 +5824,8 @@ parser_tokadd_utf8(struct parser_params *parser, rb_encoding **encp,
yyerror("invalid Unicode escape");
return 0;
}
- lex_p += 4;
- if (regexp_literal) {
- tokcopy(4);
- }
- else if (codepoint >= 0x80) {
- *encp = rb_utf8_encoding();
- if (string_literal) tokaddmbc(codepoint, *encp);
- }
- else if (string_literal) {
- tokadd(codepoint);
- }
+ parser_tokadd_codepoint(parser, encp, string_literal, regexp_literal,
+ codepoint, 4);
}
return codepoint;