I have a language that supports a heredoc syntax similar to Perl's:
var = [[END . "other stuff"; heredoc data END
I'm trying to find a way to parse this without rolling my own tokenizer, but I'm running into problems with the standard tools (The newline changes its meaning and the expression between the heredoc content and the heredoc term). Has someone tackled this problem before?

Edit -- found a solution using Eyapp. The language I'm using doesn't have a << operator so munging the lexer works:

sub _Lexer { for( $input ) { if( @heredoc ) { /\A(.*?)\n$heredoc[0][0]/s or die "Unterminated heredoc"; $strings[ $heredoc[0][1] ] = $1; shift @heredoc; } s/^\s*//; return ($1,$1) if s/^([;.])//; return ('IDENT',$1) if s/^(\w+)//; if( s/^<<(\w+)// ) { push @heredoc, [ $1, $id ]; return ( 'HEREDOC', $id++ ); } } return ('',undef); }
(there should be a flag in the white space eater in the above code that switches on the heredoc parsing. upload the correct code later)

In reply to Parsing HereDocs by JStrom

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.