summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-compiler/core/parse.y
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-08-28 22:42:06 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-08-28 22:42:06 +0900
commit1260d3b68a2b7ed3398804c89a9c5933b259ef7c (patch)
tree131dfed106b33f61315a5bcd5519aeac1921b948 /mrbgems/mruby-compiler/core/parse.y
parentf1fa5bf1c6e353c7d18f2ca57cf2808ec46dd301 (diff)
downloadmruby-1260d3b68a2b7ed3398804c89a9c5933b259ef7c.tar.gz
mruby-1260d3b68a2b7ed3398804c89a9c5933b259ef7c.zip
Add `__ENCODING__' support.
`__ENCODING__' returns the current encoding name (string), unlike CRuby that returns the encoding object.
Diffstat (limited to 'mrbgems/mruby-compiler/core/parse.y')
-rw-r--r--mrbgems/mruby-compiler/core/parse.y9
1 files changed, 9 insertions, 0 deletions
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