diff options
author | Zefram <zefram@fysh.org> | 2010-10-24 03:13:39 +0100 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2010-10-25 12:29:47 -0700 |
commit | 8359b381d0e4b7d1489abafb919f3c2a465401a4 (patch) | |
tree | 50b3187c01fbea29c0ffe65bda449ef0419a690d /ext/XS-APItest | |
parent | 94bf0465170f13a4a3114b27d564dc2287d466b2 (diff) | |
download | perl-8359b381d0e4b7d1489abafb919f3c2a465401a4.tar.gz |
function to parse unlabelled statement
New API function parse_barestmt() parses a pure statement, with no label,
and returns just the statement's core ops, not attaching a state op.
Diffstat (limited to 'ext/XS-APItest')
-rw-r--r-- | ext/XS-APItest/APItest.xs | 2 | ||||
-rw-r--r-- | ext/XS-APItest/t/stmtasexpr.t | 12 | ||||
-rw-r--r-- | ext/XS-APItest/t/swaptwostmts.t | 46 |
3 files changed, 57 insertions, 3 deletions
diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index 99c96d96bd..5be2c36f12 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -763,7 +763,7 @@ static OP *THX_parse_keyword_scopelessblock(pTHX) #define parse_keyword_stmtasexpr() THX_parse_keyword_stmtasexpr(aTHX) static OP *THX_parse_keyword_stmtasexpr(pTHX) { - OP *o = parse_fullstmt(0); + OP *o = parse_barestmt(0); o = op_prepend_elem(OP_LINESEQ, newOP(OP_ENTER, 0), o); o->op_type = OP_LEAVE; o->op_ppaddr = PL_ppaddr[OP_LEAVE]; diff --git a/ext/XS-APItest/t/stmtasexpr.t b/ext/XS-APItest/t/stmtasexpr.t index 44aae8a271..ebd9d07cfb 100644 --- a/ext/XS-APItest/t/stmtasexpr.t +++ b/ext/XS-APItest/t/stmtasexpr.t @@ -1,7 +1,7 @@ use warnings; use strict; -use Test::More tests => 8; +use Test::More tests => 10; BEGIN { $^H |= 0x20000; } @@ -48,4 +48,14 @@ eval q{ is $@, ""; is $t, "abcde"; +$t = ""; +eval q{ + use XS::APItest qw(stmtasexpr); + $t .= "a"; + $t .= "b" . stmtasexpr x: "c"; . "d"; + $t .= "e"; +}; +isnt $@, ""; +is $t, ""; + 1; diff --git a/ext/XS-APItest/t/swaptwostmts.t b/ext/XS-APItest/t/swaptwostmts.t index 155ff62577..c726fccf74 100644 --- a/ext/XS-APItest/t/swaptwostmts.t +++ b/ext/XS-APItest/t/swaptwostmts.t @@ -1,7 +1,7 @@ use warnings; use strict; -use Test::More tests => 26; +use Test::More tests => 32; BEGIN { $^H |= 0x20000; } @@ -181,4 +181,48 @@ eval q{ is $@, ""; is $t, "acbd"; +$t = ""; +eval q{ + use XS::APItest qw(swaptwostmts); + $t .= "a"; + swaptwostmts + x: + $t .= "b"; + z: + $t .= "c"; + $t .= "d"; +}; +is $@, ""; +is $t, "acbd"; + +$t = ""; +eval q{ + use XS::APItest qw(swaptwostmts); + $t .= "a"; + goto x; + $t .= "b"; + swaptwostmts + x: + $t .= "c"; + $t .= "d"; + $t .= "e"; +}; +is $@, ""; +is $t, "ace"; + +$t = ""; +eval q{ + use XS::APItest qw(swaptwostmts); + $t .= "a"; + goto x; + $t .= "b"; + swaptwostmts + $t .= "c"; + x: + $t .= "d"; + $t .= "e"; +}; +is $@, ""; +is $t, "adce"; + 1; |