1 comments

  • jaen2 hours ago
    This is <i>roughly</i> the same problem as syntactical macros in non-Lisp syntax languages.<p>There needs to be a way to indicate a &quot;hole&quot; (metavariable&#x2F;unquote) in the syntax tree, and depending on the complexity of the language&#x27;s grammar, that might be somewhat difficult, eg. in C++ having a hole for a type declaration runs into the common ambiguity between declarations (constructor calls) and expressions (regular calls). This needs to be worked around by eg. having multiple types of holes to disambiguate...<p>For the article, the idea of using an &quot;any&quot; prefix on identifiers instead of eg. operators such as ` , ... (Lisp macros) is an interesting solution, as it does not require extending the grammar of the language... although it&#x27;s not applicable in all situations (eg. for matching grammar elements where identifiers are not allowed). For a very regular language like Smalltalk though, it&#x27;s pretty good.<p>Grammar-based rewriting has a long line of history and research, so there&#x27;s a deep well of knowledge to be mined if you feel like hitting up Google Scholar...<p>For modern implementations, there&#x27;s eg. ast-grep and semgrep: <a href="https:&#x2F;&#x2F;ast-grep.github.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ast-grep.github.io&#x2F;</a> <a href="https:&#x2F;&#x2F;semgrep.dev&#x2F;docs&#x2F;writing-rules&#x2F;pattern-syntax" rel="nofollow">https:&#x2F;&#x2F;semgrep.dev&#x2F;docs&#x2F;writing-rules&#x2F;pattern-syntax</a>