Uscript Some months ago I developed a lightweight middle layer between MySql and the web. The purpose was experimentation with web programming without the complexity of a standard middleware layer. I will describe the system to you, and make the source available if anyone wants to experiment with the concept.
The syntax is based on URL grammar. My hello program is: http://address/U?print= Hello World& or if necessary http://address/U?print= Content-type: text/html\r\n\r\nHello World& Either of these copied into the web address of the browser prints a screen with Hello World. The system relies on built in URL scripts, URL scripts stored in MySQL, and the original URL script arriving from the browser. Language characters: = Macro assignment & Macro definition terminator $ Macro expansion _ External Macro expansion % escaping sequence Syntax: A Uscript is an arbitrary intermixing of the following: 1) plain text 2) $symbol _symbol 3) symbol= uscript& The system works as a run time macro language. The language is a recursive macro define and expand. Plain text is emitted, macros defined special character define symbols which are expanded. a macro definition is: name= arbitrary text& an expansion is: $name or if the macro is predefined in the MySQL data base. _name Similiar to M4, the U interpreter contains a formatter. The formatter is useful for filling in SQL and HTML templates for proper execution. Predefined macros are stored in the MySql as text in standard tables. The predefined macros are the special power of the macro language, and I have developed a collection of special- HTML and SQL templates which can be expanded as external macros. The parameters in the templates are substituted by macro expansion. Macro expansions follow expected recursive rules: $$name will expand $name then attempt to expand the result as a macro. When expansion is complete the resulting text is passed back to the browser. The macro processor has access to the web and to MySql. The input and output from the database is placed into a square buffer(s) which can be rotated, dot producted, and cross producted in various manners under a special ioctl macro that controls sql IO. Other special executive macros are built in. out , out_exec // Flush the buffer outb , outb_exec // Flush the buffer outf , outf_exec // Execute tha macro and flush form , format // Format the iop", iop_exec inner , inner_exec sqlio , sqlio_exec // Send expanded text to MySQL mode , mode_exec // Change the mode of the SQL square buffer parse , parse_exec // Execute the specified u script blob , blob_exec // Interpret a binary blob ioctl, ioctl_exec // Modify the operation of the square buffer Memory management. The system assumes text last for the life of the web page. Uscript output is kept in an output buffer until one of the output executives flush the system. Oldest symbols are garbaged when the symbol table fills. SQL input is flushes to a square buffers which are stacked. Special symbols are compiled into the U interpreter: There is no text manipulation, all symbols are managed with pointers to a text buffer. All 256 characters are valid, except U script special chars must be escaped to be treated as text. There are no NULL terminated strings, and zero is a valid text char. The Formatter: Aside from the Uscript parser, the system offers a separate formatter, similiar to the M4 formatter. This is used to fill in careful text strings needed for HTML and SQL templates. Some of the most frequent HTMS and SQL strings are stored in the parser itself at start up to speed the processing. These templates generally contain symbols that must be expanded. Example: HttpText= Content-type: text/html\r\n\r\n<html> <head> $css </head><body> In this pre-defined template a style pointer is required for expansion. This allows compact html pages, for example: $out=css=StandardStyle& $HttpText arbitary text $End& would be activated with: http://address/U?$out=css=StandardStyle& $HttpText arbitary text $End& Or if the desired page format is stored as the template css=StandardStyle& $HttpText arbitary text $End& in MySql then: http://address/U?$out=_css& works. Loading u script into sql tables The normal operation of sequences of html pages is activated by the user when an html tag issuse a valid Uscript. For example, the following template is stored in the SQL pre-defines. Its purpose is to provide the next and previous tags that appear at the bottom of a table of sql records. They can be utilized with the macro expansion _UpdateAnchor. The calling U script will predefine the appropiate symbols and the macro is emitted. For example, db defines the data base, tb the table, sql the query macro, html the output format. UpdateAnchor <p> <a href="U?next=PageAnchors&db=$db&tb=$tb&sql=$sql&html=$html&limit=$limit&offset=%0&GOTO=_$PREV">Next</a> <a href="U?next=PageAnchors&db=$db&tb=$tb&sql=$sql&html=$html&limit=$limit&offset=$1&GOTO=_$PREV">Prev</a> The templates are stored in a data base known to the interperter. The system has some advantages, for example, an arbitrary table can be displayed with column headers properly labeled without prior knowledge of the data base. Also the system can build update forms for changing records with no prior knowledge. I have informully created a pretty form of U script, called PU, or pretty uscript, and use a simple format converter with a built in loader for templates. The M4 macro handle comes in handy. The example of PU below loads a table of Gif images from MySQL and places them into an html table for display. Some of the text are M4 macros. Script wall be reformatted to U and loaded into the SQL as a template. Then can be activated with http://address/U? $Giftable& action GifTable { setup css=_SystemCss; $HttpText <h2> $userid </h2> <table> <caption align ="top">Table of Gif</caption> outb() ioctl(KEEP+DEFAULT+TEMP) call(_GifRow) ioctl(DEFAULT) ioctl(INNER+0x0004) iop( <tr> form($TableTdRow) </tr> ) </table> $End outb() } -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]