JStrom has asked for the wisdom of the Perl Monks concerning the following question:
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?var = [[END . "other stuff"; heredoc data END
Edit -- found a solution using Eyapp. The language I'm using doesn't have a << operator so munging the lexer works:
(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)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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing HereDocs
by GrandFather (Saint) on Jun 11, 2008 at 00:32 UTC | |
by JStrom (Pilgrim) on Jun 11, 2008 at 01:47 UTC | |
|
Re: Parsing HereDocs
by jethro (Monsignor) on Jun 11, 2008 at 00:24 UTC |