From 1260d3b68a2b7ed3398804c89a9c5933b259ef7c Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 28 Aug 2017 22:42:06 +0900 Subject: Add `__ENCODING__' support. `__ENCODING__' returns the current encoding name (string), unlike CRuby that returns the encoding object. --- mrbgems/mruby-compiler/core/parse.y | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 5cecfc06b..0e425b189 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -2968,6 +2968,15 @@ var_ref : variable snprintf(buf, sizeof(buf), "%d", p->lineno); $$ = new_int(p, buf, 10); } + | keyword__ENCODING__ + { +#ifdef MRB_UTF8_STRING + const char *enc = "UTF-8"; +#else + const char *enc = "ASCII-8BIT"; +#endif + $$ = new_str(p, enc, strlen(enc)); + } ; backref : tNTH_REF -- cgit v1.2.3