Dear monks:

I'm making a perl module to wrap a library. Everything goes well, until I added typemap for this enum. This is the enum:

namespace geno_eye { typedef enum { LABEL_BIND_TOP = 1, LABEL_BIND_BOTTOM = 1 << 1, LABEL_BIND_LEFT = 1 << 2, LABEL_BIND_RIGHT = 1 << 3 } LabelBind; }
and this is the typemap. I attempt to convert it from/to string for perl SV:
geno_eye::LabelBind GENO_EYE_LABEL_BIND_T INPUT GENO_EYE_LABEL_BIND_T char* sv_text = SvPV_nolen($arg); $var = 0; if (strstr(sv_text, "top") || strstr(sv_text, "TOP")) $var |= geno_eye::LABEL_BIND_TOP; else if (strstr(sv_text, "bottom") || strstr(sv_text, "BOTTOM")) $var |= geno_eye::LABEL_BIND_BOTTOM; if (strstr(sv_text, "left") || strstr(sv_text, "LEFT")) $var |= geno_eye::LABEL_BIND_LEFT; else if (strstr(sv_text, "right") || strstr(sv_text, "RIGHT")) $var |= geno_eye::LABEL_BIND_RIGHT; OUTPUT GENO_EYE_LABEL_BIND_T if ($var|geno_eye::LABEL_BIND_TOP) sv_setpv($arg, "top"); else if ($var|geno_eye::LABEL_BIND_BOTTOM) sv_setpv($arg, "bottom"); if ($var|geno_eye::LABEL_BIND_LEFT) sv_catpv($arg, "left"); else if ($var|geno_eye::LABEL_BIND_RIGHT) sv_catpv($arg, "right");

I wrote a minimum test XS file:

#ifdef __cplusplus extern "C" { #endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #undef do_open #undef do_close #ifdef __cplusplus } #endif #include "geno_eye_perl.h" #include <exception> #include <iostream> #undef xsp_constructor_class #define xsp_constructor_class(c) (c) #include <geno_eye/common.h> MODULE=Test PACKAGE=Test void test(geno_eye::LabelBind value) CODE: std::cout << "binary value: " << value << std::endl;
When I run perlxs, it cries at the first code line of the INPUT section:
$ xsubpp -typemap test_typemap test.xs >test.cpp Bareword found where operator expected at (eval 2) line 3, near ""\n + char* sv_text = SvPV_nolen($arg); $var = 0; if (strstr(sv_text, "top" (Might be a runaway multi-line "" string starting on line 1) (Missing operator before top?) String found where operator expected at (eval 2) line 3, near "top") | +| strstr(sv_text, "" Bareword found where operator expected at (eval 2) line 3, near "") || + strstr(sv_text, "TOP" (Missing operator before TOP?) String found where operator expected at (eval 2) line 5, near "TOP")) $var |= geno_eye::LABEL_BIND_TOP; else if (strstr(sv_text, "" (Might be a runaway multi-line "" string starting on line 3) String found where operator expected at (eval 2) line 5, near "bottom" +) || strstr(sv_text, "" Bareword found where operator expected at (eval 2) line 5, near "") || + strstr(sv_text, "BOTTOM" (Missing operator before BOTTOM?) String found where operator expected at (eval 2) line 7, near "BOTTOM" +)) $var |= geno_eye::LABEL_BIND_BOTTOM; if (strstr(sv_text, "" (Might be a runaway multi-line "" string starting on line 5) String found where operator expected at (eval 2) line 7, near "left") +|| strstr(sv_text, "" Bareword found where operator expected at (eval 2) line 7, near "") || + strstr(sv_text, "LEFT" (Missing operator before LEFT?) String found where operator expected at (eval 2) line 9, near "LEFT")) $var |= geno_eye::LABEL_BIND_LEFT; else if (strstr(sv_text, "" (Might be a runaway multi-line "" string starting on line 7) String found where operator expected at (eval 2) line 9, near "right") + || strstr(sv_text, "" Bareword found where operator expected at (eval 2) line 9, near "") || + strstr(sv_text, "RIGHT" (Missing operator before RIGHT?) String found where operator expected at (eval 2) line 11, near "RIGHT" +)) $var |= geno_eye::LABEL_BIND_RIGHT ;\n"" (Might be a runaway multi-line "" string starting on line 9) syntax error at (eval 2) line 3, near ""\n char* sv_text = SvPV_nol +en($arg); $var = 0; if (strstr(sv_text, "top"

In reply to perlxs failed to parse my typemap by llancet

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.