-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simpla Templating Language #1
Comments
Here's a first draft:
So for example:
In the above example, we have some whitespace issues:
|
Second draft without alternative syntax, and optional placeholders use a similar syntax to the required ones:
PhpSpec uses templates without optional placeholders, so it should work perfectly:
Pretty Printer should rely on templates that mirror PHP Parser's nodes:
With deeper templates:
But once again optional placeholders are problematic regarding surrounding whitespaces when they shouldn't print anything:
|
Third draft adding up a collection placeholder:
Collection placeholders should received an array:
So for example the
And
If there are no
If there's one constant:
If there's more than one constants:
|
Simpla Templating Language
We need a simple templating language that allows us to describe how the code generated from the AST should look like.
Why not Twig?
PHP-Printer will define an interface for the Templating Engine, allowing us to implement an adapter for any existing third party Templating Engine.
In Memio, we've done the same thing and provided by default a Twig implementation, since it is the most popular Templating Engine. However this choice made us miss the opportunity to work with Puli as they were reluctant to pull Twig dependency in all projects that'd use it, and it made phpspec core template incompatible, which is a shame since spec-gen is the main use case for Memio.
Also as it happens, Twig isn't as fantastic with generating PHP code as it is with generating HTML...
Requirements
℅parameter%
with value associated toparameter
key)Of course the tricky part is on how to make the syntax "succinct" especially in regards to the following challenges:
Usage examples
Here's an example of generated code we'd like to be able to handle:
The text was updated successfully, but these errors were encountered: