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); }
In reply to Parsing HereDocs by JStrom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |