← 所有消息

Seven regular expressions are the whole grammar

The transpiler that turns .phlo into PHP has a grammar of seven regular expressions. One per keyword, tried in order: handle, function, route, method, prop, view, and the <script> or <style> block.

preg_match('/^prop ([A-z0-9_]+) ?({| => | : ) ?(.*)/', $line, $node)

That is the entire definition of a property in the language.

The useful part is what happens to a line that matches none of them: it falls through into the controller. That single fallback is why loose code at the top of a .phlo file simply runs, which turns out to be exactly where an app's entry logic wants to live. It is less a designed feature than a consequence with nowhere better to go.

Reading line by line rather than building a syntax tree is the decision the rest rests on. The parser stays short enough to read in one sitting, and because line N in maps to a known line out, pointing an error back at the source is arithmetic rather than a mechanism.

The cost is strictness, and it is real: no multiline strings, a blank line ends a view, CSS declarations stay on one line. The answer to that is better diagnostics rather than a more forgiving parser. A grammar would relax the rules at the price of the parser being readable, and that is not a trade worth making.

我们使用必要的cookie来使该网站正常工作。在您的许可下,我们还使用分析工具来改善网站。