From 8c074420f71b35b89fac560bac79620135a846de Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com> Date: Wed, 11 Dec 2013 06:49:52 +0100 Subject: [PATCH] redefine in() and not_in() in terms of action with 'chr' --- src/bindings/php/Tests/InTest.php | 2 +- src/bindings/php/Tests/NotInTest.php | 2 +- src/bindings/swig/hammer.i | 34 +++++++++++++++++++++------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/bindings/php/Tests/InTest.php b/src/bindings/php/Tests/InTest.php index 6d1c5623..cdc1e930 100644 --- a/src/bindings/php/Tests/InTest.php +++ b/src/bindings/php/Tests/InTest.php @@ -7,7 +7,7 @@ class InTest extends PHPUnit_Framework_TestCase protected function setUp() { - $this->parser = h_in("abc"); + $this->parser = in("abc"); } public function testSuccess() { diff --git a/src/bindings/php/Tests/NotInTest.php b/src/bindings/php/Tests/NotInTest.php index 4a220d38..f06e53f7 100644 --- a/src/bindings/php/Tests/NotInTest.php +++ b/src/bindings/php/Tests/NotInTest.php @@ -7,7 +7,7 @@ class NotInTest extends PHPUnit_Framework_TestCase protected function setUp() { - $this->parser = h_not_in("abc"); + $this->parser = not_in("abc"); } public function testSuccess() { diff --git a/src/bindings/swig/hammer.i b/src/bindings/swig/hammer.i index 49dec23b..d7cf3a06 100644 --- a/src/bindings/swig/hammer.i +++ b/src/bindings/swig/hammer.i @@ -204,11 +204,19 @@ RETVAL_STRINGL((char*)$1->token, $1->len, 1); } -/* TODO do we need this anymore? -%typemap(out) struct HCountedArray_* { - +%typemap(in) HAction* { + if (IS_CALLABLE == Z_TYPE_PP($input)) { + if (!zend_make_callable($1, *$input TSRMLS_CC)) { + // FIXME some error + $1 = NULL; + } + // don't need an else here, $1 gets populated + } else { + // FIXME some error + $1 = NULL; + } } -*/ + %typemap(out) struct HParseResult_* { if ($1 == NULL) { // TODO: raise parse failure @@ -255,10 +263,6 @@ } */ -%typemap(in) (const HAction a, void* user_data) { - $2 = $input; - $1 = call_action; - } #else #warning no Hammer typemaps defined #endif @@ -565,5 +569,19 @@ function sequence() return h_sequence__a($arg_list); } +function action($p, $act) +{ + return h_action($p, $act); +} + +function in($charset) +{ + return action(h_in($charset), 'chr'); +} + +function not_in($charset) +{ + return action(h_not_in($charset), 'chr'); +} " #endif -- GitLab