我正在为 PHP 中的脚本编程语言编写解析器。该脚本语言的语法如下所示:
ZOMFG
&This is a comment
(show "Hello, World\!");
这是用该语言编写的页面,显示 Hello, World!在浏览器中。但我也可以有这样的代码:
ZOMFG
&This is a comment !
on multiple !
lines.
(show !
"Hello, !
World\!!
");
现在,我使用explode("\n", $content)
将页面的内容分解为一个数组,该数组的每一行代码都位于一个单独的索引中。所以
ZOMFG
&This is a comment
(show "Hello, World\!");
变成:
array('ZOMFG', '&This is a comment', '(show "Hello, World\!");');
当一行以 ! (除非将 ! 转义为 \!),它应该将该行添加到数组中,包括以下行作为单个元素。所以
&This is a comment !
on multiple !
lines.
变成
&This is a comment on multiple lines.
有谁知道如何做到这一点?