Embedded JavaScript [design discussuion]

new topic     » topic index » view thread      » older message » newer message

I am struggling to decide how best to implement embedded JavaScript in Phix code, for syntax colouring and skip/transpile handling.
[aside: all of this is at the planning stage, I'm not claiming any of it actually works as yet.]

My Html.syn, which is a config file for my editor, contains:

NestedSyntax 
PHP <?php ?> 
js <script[_type="text/javascript"]> </script> 
css <style> </style> 
**end NestedSyntax 

Obviously those work well because < is the standard delimiter in html, none of the prefixes are valid html, and none of the suffixes are valid php/js/css.

Liekwse my Phix.syn contains:

NestedSyntax 
FASM #ilASM{ } 
**end NestedSyntax 

Which works well because a leading # introduces a hex number, so "#i" only needs checking for in one place, and } is not valid assembly code.

There is also this in FASM.syn:

NestedSyntax 
ARM [ARM] [[PE|ELF][32|64]] 
**end NestedSyntax 

However that is effectively ignored and in fact meaningless drivel, there are at least eight different prefixes, none of which are valid assembly, and instead of any suffix the next prefix terminates each block, with [] being the general "no prefix applies any longer" thing. All sufficiently bespoke that section of FASM.syn is in practice effectively ignored and hand-coded instead.

I also want to embed JavaScript in Phix code: #ilJS{ is an acceptable prefix, however } is [potentially] valid JavaScript and therefore an unsuitable suffix, and something like #ilJS} is just simply downright ugly. Can you think of anything better?

I cannot think of any other nested syntaxes/language embeddings it might ever need to cope with, can you? Mind you, Lua and Wren might fall into that category, I've just never run into any actual use like that?

PS: ChatGPT went with #javascript{ .. #} as the latter is invalid js, before settling on #endjs in column 1, but personally I don't like the column-1 thing.

Update: I've gone with #ilJS{ .. #}ilJS.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu