summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-19 01:58:31 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-19 01:58:31 -0400
commit69a69ae8b9c173c201939dd699de4f0cd9cda6df (patch)
tree7c51def4861aef72a911df40808056cabaef4cb5
parent976ee2bf78788b6b130ce79601cb259ec6746478 (diff)
downloadparse-keyword-69a69ae8b9c173c201939dd699de4f0cd9cda6df.tar.gz
parse-keyword-69a69ae8b9c173c201939dd699de4f0cd9cda6df.zip
allow parsing as expressions or statements
-rw-r--r--Keyword.xs11
1 files changed, 10 insertions, 1 deletions
diff --git a/Keyword.xs b/Keyword.xs
index 4531169..f38c8cd 100644
--- a/Keyword.xs
+++ b/Keyword.xs
@@ -7,6 +7,8 @@ static OP *parser_callback(pTHX_ GV *namegv, SV *psobj, U32 *flagsp)
{
dSP;
SV *args_generator;
+ SV *statement = NULL;
+ I32 count;
// call the parser callback
// it should take no arguments and return a coderef which, when called,
@@ -16,8 +18,11 @@ static OP *parser_callback(pTHX_ GV *namegv, SV *psobj, U32 *flagsp)
// where $code is the thing returned by the parser function
PUSHMARK(SP);
- call_sv(psobj, G_SCALAR);
+ count = call_sv(psobj, G_ARRAY);
SPAGAIN;
+ if (count > 1) {
+ statement = POPs;
+ }
args_generator = SvREFCNT_inc(POPs);
PUTBACK;
@@ -26,6 +31,10 @@ static OP *parser_callback(pTHX_ GV *namegv, SV *psobj, U32 *flagsp)
GvNAME(namegv), args_generator);
}
+ if (SvTRUE(statement)) {
+ *flagsp |= CALLPARSER_STATEMENT;
+ }
+
return newUNOP(OP_ENTERSUB, OPf_STACKED,
newCVREF(0,
Perl_scalar(newSVOP(OP_CONST, 0,