Question

I am interested in model an develop a new object pascal interpreter for web site scripting. We have PHP, Pearl, Java, Javabeans... But not Pascal as a option for web developers.

Since Delphi only works in Windows based servers...

I would like to do things like:

<input name="ClientName" value="<?pas write(ClintObj.Name); ?>">

or

<input name="ClientName" value="<?pas @ClintObj.GetName; ?>">

not just as a template, but just like PHP, something I could use with a MVC framework, or even create one:

<?pas
    System.Writeln('<html><head>...');
?>

Where should I start?

Or is it already done and I fail to find it? (for linux)

Was it helpful?

Solution 2

You are mixing embedding a scripting version of a language in templates with general web development in that language.

While Pascal isn't really used much as templating language, doing webdevelopment is perfectly possible, e.g. with http://brookframework.org/ and several Delphi component suites.

Some of the Delphi options also support Apache, and have supported Kylix in the past. I used webhub from http://www.href.com for a while.

OTHER TIPS

Two existing products:

Oxygene

You can check out Oxygene, formerly known as Delphi Prism, formerly known as RemObjects Chrome.

They have found a way to compile a Pascal style language to Java. Not convert Pascal code to Java code, but actually compile it to the bytecode that runs in the Java runtime engine. Apart from that, they can also compile to the .NET runtime.

I don't know if you can use Oxygene for your purpose, but at least their product may give you some inspiration and some insight of the possibilities and difficulties of building something like that yourself.

PascalScript

Maybe you can use PascalScript, also by RemObjects. It is a script interpreter. So you can embed it in a server application. For instance, if you create an ISAPI application that embeds PascalScript, all you need to do is expose some 'write' method to the script to allow it to write output. All the application needs to do is output that output to ISS, and your basis server side Pascal scripting is done. After that, you can expose more convenience functions to the script to make it more useful.

PascalScript can be used in Delphi as well as FreePascal, so maybe you can make it work in Linux as well.

Writing such a interpreter is not a piece of cake:

  • your script files would need have be parsed, the contained Pascal code compiled / checked for syntax errors
  • as this compilation phase would be a CPU consuming task, the resulting object code would have to be cached for better performance
  • maybe you do not want to use / install the FPC or Delphi compiler on the server, then your language will be limited to what your compiler can suppport
  • the generated code needs access to "shared data" if different script parts need to interchange information or access global data, like a database

Also a critical functional requirement unless your application is stateless:

  • different users of the web site need their separate data (state), so your code needs to be session-aware (stateful)

Oh, one minor issue:

  • the application should not expose any vulnerabilites for malicious clients, see OWASP

So I guess this will be a long weekend ;-)

Don't forget about the free DelphiWebScript (DWS).

Though started as a Delphi-like WebScript language, it is a general purpose Delphi like language that can be used as a script, and also has a JIT compiler (though without it, the performance already is very good).

The main project compiles in Delphi (so it is Windows-only) but there is a FreePascal DelphiWebScript initiative to make it run on Linux too.

There are multiple demo web server projects to choose from so you can host your own DWS scripts, for instance the WebServer project which is based on http.sys version 2, then there are Indy based and Synopse based ones.

The development tool Smart Mobile Studio is using DWS to compile the forms and Pascal based source code into HTML5 and JavaScript then serve it from a web server to run in any HTML5/JavaScript compatible browser (including the mobile ones).

So there is a lot of power in DWS, demos and the eco system around it (:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top