# Creating a JSX-like DSL that compiles into PHP?

**URL:** https://community.haxe.org/t/creating-a-jsx-like-dsl-that-compiles-into-php/2354
**Category:** Haxe
**Tags:** haxe-php, jsx
**Created:** [April 10, 2020, 8:49am UTC](https://community.haxe.org/t/creating-a-jsx-like-dsl-that-compiles-into-php/2354 "2020-04-10T08:49:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Prim](https://avatars.discourse-cdn.com/v2/letter/p/45deac/32.png) [@Prim](https://community.haxe.org/u/Prim)
#### Post date: [April 10, 2020, 8:49am UTC](https://community.haxe.org/t/creating-a-jsx-like-dsl-that-compiles-into-php/2354/1 "2020-04-10T08:49:48Z")

</div>

TL;DR: Third paragraph onwards.

Hello everyone,

I have recently found a job where they use PHP. They fortunately use the newest versions of it, but unfortunately they use it in a very old-school way - the templates are just HTML mixed with PHP code. I find it really painful working with code like that, so I have started looking for a way to improve it going forward.

Lately, I have been using React in my free time and I really enjoy how function components and the JSX syntax work. My first attempt at improvement was just cutting up the template I’m working on into separate functions, but I have quickly found the limitations of this approach - many of the “function components” require unwieldy arrays of parameters (which I need to manually document for each function) and passing in child components is extremely clunky too.

By chance, I was reminded of Haxe by a video and I realised that since it can compile into PHP and has metaprogramming, maybe it could be used to create a JSX-like DSL that would compile into PHP function calls similar to React.createElement() (which is what JSX is under the hood).

Well, in the previous paragraph I have used a lot of big words and short acronyms, but I am actually a junior programmer at best, and I don’t have any experience with metaprogramming, I have merely read about it. I would appreciate if someone could tell me if my thoughts have merit or if I’m completely off the mark, whether or not Haxe would be a good language to implement it, and maybe even point me towards some resources I could use.

Thanks!

---

<div class="post-metadata">

### Author: ![diddledan](https://community.haxe.org/user_avatar/community.haxe.org/diddledan/32/1708_2.png) [@diddledan](https://community.haxe.org/u/diddledan)
#### Post date: [April 10, 2020, 11:50am UTC](https://community.haxe.org/t/creating-a-jsx-like-dsl-that-compiles-into-php/2354/2 "2020-04-10T11:50:20Z")

</div>

I’m very new, too… just signed-into the forum for the very first time 🙂

I wonder if [MassiveInteractive’s React JS project](https://github.com/massiveinteractive/haxe-react) could be helpful in working towards a JSX-like system… It would be really nice for a portable JSX-style thing that supports many/all of the Haxe targets.

---

<div class="post-metadata">

### Author: ![RealyUniqueName](https://community.haxe.org/user_avatar/community.haxe.org/realyuniquename/32/10_2.png) [@RealyUniqueName](https://community.haxe.org/u/RealyUniqueName)
#### Post date: [April 10, 2020, 2:19pm UTC](https://community.haxe.org/t/creating-a-jsx-like-dsl-that-compiles-into-php/2354/3 "2020-04-10T14:19:21Z")

</div>

There’s [coconut.ui](https://github.com/MVCoconut/coconut.ui/) by @back2dos, but I’m not sure it supports PHP target.

---

<div class="post-metadata">

### Author: ![alex\_dja](https://community.haxe.org/user_avatar/community.haxe.org/alex_dja/32/294_2.png) [@alex\_dja](https://community.haxe.org/u/alex_dja)
#### Post date: [April 10, 2020, 3:01pm UTC](https://community.haxe.org/t/creating-a-jsx-like-dsl-that-compiles-into-php/2354/4 "2020-04-10T15:01:43Z")

</div>

Please take a look at [GitHub - haxetink/tink\_hxx: JSX - JS + HX](https://github.com/haxetink/tink_hxx). As I know jsx-generated expression can be customized.

---

<div class="post-metadata">

### Author: ![Prim](https://avatars.discourse-cdn.com/v2/letter/p/45deac/32.png) [@Prim](https://community.haxe.org/u/Prim)
#### Post date: [April 10, 2020, 3:43pm UTC](https://community.haxe.org/t/creating-a-jsx-like-dsl-that-compiles-into-php/2354/5 "2020-04-10T15:43:53Z")

</div>

Thanks for the responses!

At a glance the libs diddledan and RealyUniqueName have recommended don’t seem to be what I’m looking for - the ReactJS project seems to provide interop with React for Haxe and coconut seems to be a React-style SPA library. I don’t want to actually use React or create an SPA, I just want to use the JSX syntax to make writing “plain” PHP templates more pleasant and I thought Haxe had the correct feature set to implement something like that.

Haxetink seems to have elements of what I had in mind, I’ll need to investigate it further. Thanks for linking it, alex\_dja.

---

<div class="post-metadata">

### Author: ![alex\_dja](https://community.haxe.org/user_avatar/community.haxe.org/alex_dja/32/294_2.png) [@alex\_dja](https://community.haxe.org/u/alex_dja)
#### Post date: [April 10, 2020, 8:30pm UTC](https://community.haxe.org/t/creating-a-jsx-like-dsl-that-compiles-into-php/2354/6 "2020-04-10T20:30:25Z")

</div>

You are welcome. Here you can also see the usage of tink.hxx.Parser in haxe-react-next lib but take in mind macros aren’t trivial thing;)

> <https://github.com/kLabz/haxe-react/blob/next/src/lib/react/ReactMacro.hx>
