www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - DHP - web scripting in D?

reply Sam McCall <tunah.d tunah.net> writes:
After hacking on some bad PHP code, I've come to the conclusion that 
being able to do
<?php echo("Hello world!"); ?>
is a good thing, and the instant gratification is a good thing, but the 
language itself isn't great - not terrible, there's just something(s) 
missing IMO.
So naturally, I started working on something that used D ;-)
My goal was/is something that allowed a stream of mixed raw output and 
code like PHP, but was otherwise regular D. It would be run through a 
lexically analysing preprocessor and then compiled with DMD.

What I've done:
I wrote an Apache module[1] called mod_compile that will let you put a D 
(or C, or lisp...) source file in your web directory, and use it like a 
CGI script. It's compiled into a secure cache that's updated if the 
source has been modified since last access. The program sees an 
interface very similar to CGI[2].
I've written the very early beginnings of a library providing some 
useful stuff for these scripts and a script entry point (see example.d).
I've written a wrapper for DMD that takes command line arguments in the 
form expected by mod_compile and links in the library.
The code and binaries that work for me(tm) are here:
http://tunah.net/~tunah/mod_compile

What I plan to do, but I need help on the details:
I want to write a preprocessor that turns some HTML-embedded-D language 
into D (specifically, into a module tunah.dhp.script that provides void 
script_main()). I'm thinking something like
<html>
  <body>
   <?script foo(); ?>
  </body>
</html>
<?script
	void foo() {
		print("Hello world!");
	}
?>
but I'm not entirely sure.
The thing I'm most unsure about is where to put the code at the "top 
level" that this adds. The call to foo() clearly goes in script_main(). 
What about variable declarations, how do we distinguish between globals 
and script_main locals? I'm tending towards <?script ?> for inline stuff 
and <?code ?> or something for global stuff, but this looks messy to me.

So what I'm really looking for are thoughts/criticisms/general interest 
in something like this, does it seem worthwhile?

Ergh, posting from the wrong side of 6am ;-)
Sam

[1] For 1.3. I'm not sure how easy it'd be to port.
[2] Differences: Doesn't do ISINDEX command line parameters - read the 
QUERY_STRING instead. Doesn't support NPH - all responses go through apache.
Jul 06 2004
next sibling parent reply Charlie <Charlie_member pathlink.com> writes:
<?php echo("Hello world!"); ?>

Or even <?="Hello World!"?> :D.
 but the 
language itself isn't great - not terrible, there's just something(s) 
missing IMO.

Ive actually grown to like the language, but its lack of error detection is a pain, sometimes it doesnt even catch errors, just silently doesnt work.
So what I'm really looking for are thoughts/criticisms/general interest 
in something like this, does it seem worthwhile?

Defintly worth while! Looking over the code now. Charlie In article <ccep74$obo$1 digitaldaemon.com>, Sam McCall says...
After hacking on some bad PHP code, I've come to the conclusion that 
being able to do
<?php echo("Hello world!"); ?>
is a good thing, and the instant gratification is a good thing, but the 
language itself isn't great - not terrible, there's just something(s) 
missing IMO.
So naturally, I started working on something that used D ;-)
My goal was/is something that allowed a stream of mixed raw output and 
code like PHP, but was otherwise regular D. It would be run through a 
lexically analysing preprocessor and then compiled with DMD.

What I've done:
I wrote an Apache module[1] called mod_compile that will let you put a D 
(or C, or lisp...) source file in your web directory, and use it like a 
CGI script. It's compiled into a secure cache that's updated if the 
source has been modified since last access. The program sees an 
interface very similar to CGI[2].
I've written the very early beginnings of a library providing some 
useful stuff for these scripts and a script entry point (see example.d).
I've written a wrapper for DMD that takes command line arguments in the 
form expected by mod_compile and links in the library.
The code and binaries that work for me(tm) are here:
http://tunah.net/~tunah/mod_compile

What I plan to do, but I need help on the details:
I want to write a preprocessor that turns some HTML-embedded-D language 
into D (specifically, into a module tunah.dhp.script that provides void 
script_main()). I'm thinking something like
<html>
  <body>
   <?script foo(); ?>
  </body>
</html>
<?script
	void foo() {
		print("Hello world!");
	}
?>
but I'm not entirely sure.
The thing I'm most unsure about is where to put the code at the "top 
level" that this adds. The call to foo() clearly goes in script_main(). 
What about variable declarations, how do we distinguish between globals 
and script_main locals? I'm tending towards <?script ?> for inline stuff 
and <?code ?> or something for global stuff, but this looks messy to me.

So what I'm really looking for are thoughts/criticisms/general interest 
in something like this, does it seem worthwhile?

Ergh, posting from the wrong side of 6am ;-)
Sam

[1] For 1.3. I'm not sure how easy it'd be to port.
[2] Differences: Doesn't do ISINDEX command line parameters - read the 
QUERY_STRING instead. Doesn't support NPH - all responses go through apache.

Jul 06 2004
parent Charlie <Charlie_member pathlink.com> writes:
PHP is also too slow for some applications, I think this would fill a great
need!

Charlie

In article <cceq54$ppf$1 digitaldaemon.com>, Charlie says...
<?php echo("Hello world!"); ?>

Or even <?="Hello World!"?> :D.
 but the 
language itself isn't great - not terrible, there's just something(s) 
missing IMO.

Ive actually grown to like the language, but its lack of error detection is a pain, sometimes it doesnt even catch errors, just silently doesnt work.
So what I'm really looking for are thoughts/criticisms/general interest 
in something like this, does it seem worthwhile?

Defintly worth while! Looking over the code now. Charlie In article <ccep74$obo$1 digitaldaemon.com>, Sam McCall says...
After hacking on some bad PHP code, I've come to the conclusion that 
being able to do
<?php echo("Hello world!"); ?>
is a good thing, and the instant gratification is a good thing, but the 
language itself isn't great - not terrible, there's just something(s) 
missing IMO.
So naturally, I started working on something that used D ;-)
My goal was/is something that allowed a stream of mixed raw output and 
code like PHP, but was otherwise regular D. It would be run through a 
lexically analysing preprocessor and then compiled with DMD.

What I've done:
I wrote an Apache module[1] called mod_compile that will let you put a D 
(or C, or lisp...) source file in your web directory, and use it like a 
CGI script. It's compiled into a secure cache that's updated if the 
source has been modified since last access. The program sees an 
interface very similar to CGI[2].
I've written the very early beginnings of a library providing some 
useful stuff for these scripts and a script entry point (see example.d).
I've written a wrapper for DMD that takes command line arguments in the 
form expected by mod_compile and links in the library.
The code and binaries that work for me(tm) are here:
http://tunah.net/~tunah/mod_compile

What I plan to do, but I need help on the details:
I want to write a preprocessor that turns some HTML-embedded-D language 
into D (specifically, into a module tunah.dhp.script that provides void 
script_main()). I'm thinking something like
<html>
  <body>
   <?script foo(); ?>
  </body>
</html>
<?script
	void foo() {
		print("Hello world!");
	}
?>
but I'm not entirely sure.
The thing I'm most unsure about is where to put the code at the "top 
level" that this adds. The call to foo() clearly goes in script_main(). 
What about variable declarations, how do we distinguish between globals 
and script_main locals? I'm tending towards <?script ?> for inline stuff 
and <?code ?> or something for global stuff, but this looks messy to me.

So what I'm really looking for are thoughts/criticisms/general interest 
in something like this, does it seem worthwhile?

Ergh, posting from the wrong side of 6am ;-)
Sam

[1] For 1.3. I'm not sure how easy it'd be to port.
[2] Differences: Doesn't do ISINDEX command line parameters - read the 
QUERY_STRING instead. Doesn't support NPH - all responses go through apache.


Jul 06 2004
prev sibling parent reply pragma <EricAnderton at yahoo dot com> <pragma_member pathlink.com> writes:
I find this concept extremely worthwhile, but then again I'm a bit biased. I
already have a very similar project called DSP:

(web) http://www.dsource.org/projects/dsp/
(subversion) http://svn.dsource.org/svn/projects/dsp/

It does just what you propose: it takes D code direcives and writes a servlet on
the fly using that code plus code generated for the raw HTML output.  The
servlet is compiled, loaded as a dll and then serviced.

Right now it's at an early-alpha/tech-demo.  I'm undergoing another round of
design and revision to get the entire DSP grammar into scope before I start
setting milestones for Beta 1 on.  If you, or anyone else for that matter, would
like to contribute, feel free to let me know.  

The user guide is the only major documentation artifact so far.  This includes
the current DSP grammar proposal and more:

http://svn.dsource.org/svn/projects/dsp/trunk/doc/DSPUserGuide.doc

DSP features a JSP-like syntax tree with some basic apache module support.  Also
in the mix is servlet library caching, on-demand compilation (regeneration).
The present grammar reccomendation also features a set of fully XML-compliant
tags that co-exist with the typical shorthand syntax (e.g. <% ... %>).  

Beta 1 will feature a completely redesigned core that directly takes advantage
of Mango.  I also plan to write adapters to allow DSP to function as something
like mod_mango for Apache and (possibly) ASAPI.

If you go into the subvesion tree, you can take a look at the current
documentation as well as the existing code.  It's open source, so feel free to
browse around.

- Pragma

In article <ccep74$obo$1 digitaldaemon.com>, Sam McCall says...
After hacking on some bad PHP code, I've come to the conclusion that 
being able to do
<?php echo("Hello world!"); ?>
is a good thing, and the instant gratification is a good thing, but the 
language itself isn't great - not terrible, there's just something(s) 
missing IMO.
So naturally, I started working on something that used D ;-)
My goal was/is something that allowed a stream of mixed raw output and 
code like PHP, but was otherwise regular D. It would be run through a 
lexically analysing preprocessor and then compiled with DMD.

What I've done:
I wrote an Apache module[1] called mod_compile that will let you put a D 
(or C, or lisp...) source file in your web directory, and use it like a 
CGI script. It's compiled into a secure cache that's updated if the 
source has been modified since last access. The program sees an 
interface very similar to CGI[2].
I've written the very early beginnings of a library providing some 
useful stuff for these scripts and a script entry point (see example.d).
I've written a wrapper for DMD that takes command line arguments in the 
form expected by mod_compile and links in the library.
The code and binaries that work for me(tm) are here:
http://tunah.net/~tunah/mod_compile

What I plan to do, but I need help on the details:
I want to write a preprocessor that turns some HTML-embedded-D language 
into D (specifically, into a module tunah.dhp.script that provides void 
script_main()). I'm thinking something like
<html>
  <body>
   <?script foo(); ?>
  </body>
</html>
<?script
	void foo() {
		print("Hello world!");
	}
?>
but I'm not entirely sure.
The thing I'm most unsure about is where to put the code at the "top 
level" that this adds. The call to foo() clearly goes in script_main(). 
What about variable declarations, how do we distinguish between globals 
and script_main locals? I'm tending towards <?script ?> for inline stuff 
and <?code ?> or something for global stuff, but this looks messy to me.

So what I'm really looking for are thoughts/criticisms/general interest 
in something like this, does it seem worthwhile?

Ergh, posting from the wrong side of 6am ;-)
Sam

[1] For 1.3. I'm not sure how easy it'd be to port.
[2] Differences: Doesn't do ISINDEX command line parameters - read the 
QUERY_STRING instead. Doesn't support NPH - all responses go through apache.

Jul 06 2004
parent Sam McCall <tunah.d tunah.net> writes:
pragma <EricAnderton at yahoo dot com> wrote:

 I find this concept extremely worthwhile, but then again I'm a bit biased. I
 already have a very similar project called DSP:
 
 (web) http://www.dsource.org/projects/dsp/
 (subversion) http://svn.dsource.org/svn/projects/dsp/

along, I'll check it out. Sam
Jul 06 2004