Embedded Code Blocks

3 views
Skip to first unread message

pikpik

unread,
Jul 21, 2010, 10:17:01 AM7/21/10
to CommonJS
Hi,

Is there any possibility in supporting an embedded code block
structure, if detected per script? This would be similar to the
delimiter functionality found in PHP: "<?php ?>".

In a JavaScript-oriented environment, I would imagine this as:

Begin counting:
<?js for (var i = 0; i < 100; i++) { ?>
I've counted to <?js print(i); ?>...<br />
<?js } ?>
Done counting.

An example preprocessor:

var script = readAsString("script.js");

if (script.match("<?js")) {

//Beginning
script = "print(\"" + script;

//Throughout
script = script.replace("<?js", "\");");

/* This might need to handle line breaks also. */

script = script.replace("?>", "print(\"");

//End
script = script + "\");";

}

eval(script);//...perhaps?

The resulting preprocessed JavaScript (from above) could be:

print("Begin counting:
"); for (var i = 0; i < 100; i++) { print("
I've counted to "); print(i); print("...<br />
"); } print("
Done counting.");

An idea,
pikpik

pikpik

unread,
Jul 21, 2010, 10:51:53 AM7/21/10
to CommonJS
Hi,

For an example of PHP's delimited code block functionality, please
see: http://us.php.net/manual/en/language.basic-syntax.phpmode.php

Thank you,
pikpik
Reply all
Reply to author
Forward
0 new messages