moonscript icon indicating copy to clipboard operation
moonscript copied to clipboard

Failing to parse: calling a callable table that was composed with a non-parenthesis table constructor argument

Open strait opened this issue 6 years ago • 3 comments

I have a small HTLM generation library and my preferred syntax for creating HTML elements is like: H = require 'html'
H'table'{border: 1} rows a simpler version also fails to parse: H{name: 'table', border: 1} rows but this will parse: H'table''border = 1' rows and so will this: H'table'({border: 1}) rows Edit: This also works, and would be an okay, though potentially confusing solution, if the original cannot be parsed. H'table'(border: 1) rows

This is all valid code, as the table returned at each call leading up to last has a metatable with a __call metamethod.

strait avatar Jun 03 '19 01:06 strait

I was thinking it might be reasonable to get something like H 'table', border: 1, rows but that's a lot more syntax than you originally had, so you might not prefer that option. I think the original version would be difficult to parse and, in my opinion, isn't really that readable from a human perspective either.

RyanSquared avatar Jun 03 '19 15:06 RyanSquared

The idea is for the element name string and optional attribute table to appear together as a unit before the children HTML elements would be passed as arguments or as an array of HTML elements. That's the ultimate in brevity and readability in my subjective opinion.

Lua provides this flexibility, so it would be nice if Moonscript could allow it.

strait avatar Jun 03 '19 18:06 strait

Lua provides this flexibility, so it would be nice if Moonscript could allow it.

MoonScript has significance in whitespace, and - purely my own opinion - I feel that this would be pushing the boundary on that.

Also, have you looked at Lapis's HTML building setup, and considered using that or something related to that?

RyanSquared avatar Jun 04 '19 16:06 RyanSquared