Hi all!
I'm writing a parser for a scripting programming language in PHP. The syntax of that scripting language looks like this:
ZOMFG
&This is a comment
(show "Hello, World\!");
This is a page written in that language, that displays Hello, World! in the browser. But I could also have code like this:
ZOMFG
&This is a comment !
on multiple !
lines.
(show !
"Hello, !
World\!!
");
For now I use explode("\n", $content)
to explode the page's content to an array which has each line of code in a separate index.
So
ZOMFG
&This is a comment
(show "Hello, World\!");
becomes:
array('ZOMFG', '&This is a comment', '(show "Hello, World\!");');
When a line ends with a ! (except when the ! is escaped as \!), it should add that line, including the following line to the array as one single element. So
&This is a comment !
on multiple !
lines.
becomes
&This is a comment on multiple lines.
Does anyone know how to do this? Thanks in advance.