Larry Garfield wrote on 05/05/2016 15:24:
<<Push($foo >> Translator)>>
<<Pipe($foo|lower|escape)>>
<<Query($foo ?? '//item[id=42]')>>
I could easily see, for instance, Doctrine annotations building the
first, PHPUnit the second, and Zend the 3rd. Those would all be
legal-ish, but semantically very different. And there's also then no
guarantee that $foo >> Translator actually means a bit-shift (I don't
even know what a bitshift in that case would mean)
To add some context to these examples: the first is borrowing the
overload of ">>" from C++ (meaning "pass to stream") or similar uses in
Ruby; the second the use of "|" as a pipe in templating languages like
Smarty and Twig (meaning "pass expression to modifier function") or good
old Unix shell tradition; and the third is inspired by PostgreSQL and
imagines the operator overloaded to mean something like "matches the
XPath-like expression given".
I'm not sure any of those interpretations would actually be useful in
the realm of annotations, but operator overloading is the first thing
that sprung to mind when I wondered what a domain-specific language
would look like if it were constrained only to producing a valid PHP
AST. Another trick could be to abuse brackets, e.g.
"something(anything)" will parse as a function call, but needn't be
interpreted as one.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php