Changeset 49

Show
Ignore:
Timestamp:
04/23/05 09:34:52 (4 years ago)
Author:
pragma
Message:

- Added dspruntime library support
- Enhanced servlet compilation
- Added servlet registry

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dsp/DSPGrammar.d

    r48 r49  
    3737    public static char[] preamble = "dsp:"; 
    3838    public static char[] expressionToken = "__expression"; 
     39    public static char[] expressionTokenDecl = "private static char[] __expression"; 
    3940    public static char[] newline = "\n"; 
     41 
     42    public static char[] standardInclude = "import dsp.servlet.ServletRegistry,dsp.servlet.IDSPResponse,dsp.servlet.IDSPRequest,std.string";     
     43    public static char[] servletPrefix = "__servlet_"; 
     44    public static char[] servletDecl = "(IDSPRequest request, IDSPResponse response)"; 
     45    public static char[] outputVarDecl = "HttpWriter __writer = response.getWriter()"; 
    4046     
    41     public static char[] servletPrefix = "__servlet_"; 
    42     public static char[] servletDecl = "(IDSPResponse response,IDSPRequest request)"; 
     47    public static char[] outputFunc = "__writer.put"; 
     48    public static char[] replaceFunc = "std.string.replace"; 
     49    public static char[] toStringFunc = "std.string.toString"; 
    4350 
    44     public static char[] outputFunc = "response.put"; 
    45     public static char[] replaceFunc = "std.string.replace"; 
    46      
     51 
     52    public static char[] pathToNamespace(char[] path){ 
     53        return replace(path,"\\","."); 
     54    } 
    4755 
    4856    private static char[] literalString(char[] text){ 
    4957        return replace(text,"`","\x60"); 
    5058    } 
    51  
     59     
    5260    public static char[] outputString(char[] text){ 
    5361        return outputFunc ~ "(`" ~ literalString(text) ~ "`);" ~ newline; 
     
    5563     
    5664    public static char[] outputExpression(char[] expr){ 
    57         return outputFunc ~ "(" ~ expr ~ ");"  ~ newline; 
     65        return outputFunc ~ "(" ~ toStringFunc ~ "(" ~ expr ~ "));"  ~ newline; 
    5866    } 
    5967     
     
    6270    } 
    6371     
     72    public static char[] servletFunctionName(char[] name){ 
     73        return servletPrefix ~ name; 
     74    } 
    6475     
    6576    public static char[] servletFunction(char[] name,char[] cpIn, char[] cpBody, char[] cpOut){ 
    66         return "void " ~ servletPrefix ~ name ~ servletDecl ~ newline ~ 
    67             "in{" ~ cpIn ~ "}" ~ newline ~ "body{" ~ cpBody ~ "}" ~ newline ~ "out{" ~ cpOut ~ "}" ~ newline; 
     77        return  
     78            "void " ~ servletFunctionName(name) ~ servletDecl ~ newline ~ 
     79            "in{" ~ outputVarDecl ~ ";" ~ newline ~ cpIn ~ "}" ~ newline ~  
     80            "out{" ~ outputVarDecl ~ ";" ~ newline ~ cpOut ~ "}" ~ newline ~  
     81            "body{" ~ outputVarDecl ~ ";" ~ newline ~ cpBody ~ "}"  ~ newline 
     82            ; 
     83    } 
     84 
     85    public static char[] servletHeader(char[] name,char[] modulePath){ 
     86        return  
     87            "module " ~ pathToNamespace(modulePath) ~ ";" ~ newline ~    
     88            expressionTokenDecl ~ ";" ~ newline  ~  
     89            standardInclude ~ ";" ~ newline ~ 
     90            `alias void function` ~ servletDecl ~ ` ServletHandle; 
     91             
     92            static this(){ 
     93                dsp.servlet.ServletRegistry.registerServletHandle(&` ~ servletFunctionName(name) ~ `,` ~ "`" ~ modulePath ~ "`" ~ `); 
     94            }` ~ newline 
     95            ; 
    6896    } 
    6997     
    70     public static char[] servletFile(char[] name,char[] cpIn, char[] cpBody, char[] cpOut){ 
    71         return servletFunction(name,cpIn,cpBody,cpOut); 
    72     } 
    7398} 
    7499 
  • trunk/dsp/DSPProcessor.d

    r48 r49  
    4848    } 
    4949     
    50     public char[] getServletFile(){ 
    51         return generator.getServletFile(); 
     50    public char[] getServletSource(char[] modulePath){ 
     51        return generator.getServletSource(modulePath); 
    5252    } 
    5353 
  • trunk/dsp/ServletGenerator.d

    r48 r49  
    147147    } 
    148148     
    149     public char[] getServletFile(){ 
    150         return DSPGrammar.servletFile(servletName,servletCPIn,servletBody,servletCPOut); 
     149    public char[] getServletSource(char[] modulePath){ 
     150        return  
     151            DSPGrammar.servletHeader(servletName,modulePath) ~  
     152            DSPGrammar.servletFunction(servletName,servletCPIn,servletBody,servletCPOut) 
     153            ; 
    151154    } 
    152155} 
  • trunk/dspconf/dsp01.dsp

    r48 r49  
    33<?dsp:out assert(response); ?> 
    44<?dsp:xml version="1.0" ?> 
    5  
     5<?dsp 
     6    char[] expr(){ 
     7        return "hi there"; 
     8    } 
     9?> 
    610<html foo="'bar'" bar='"foo"'> 
    711<body something="32#expr()#"> 
     
    1418    <dsp:code> 
    1519        } 
    16         else response.put("hello world"); 
     20        else response.getWriter.put("hello world"); 
    1721    </dsp:code> 
    1822</body> 
  • trunk/dsptest.d

    r48 r49  
    2626import xml.all; 
    2727 
    28 import dsp.DSPProcessor; 
    29 import dsp.StandardTagLibrary; 
     28import dsp.ServletCompiler; 
     29import dsp.RequestConfig; 
     30 
     31import misc.Library; 
    3032 
    3133import std.stdio; 
     
    3739} 
    3840 
    39 void main(char[][] args){ 
    40     char[] pwd = getPath(args[0])
    41     char[] testfile = `dspconf\dsp01.dsp`; 
    42     XMLParser parser = new XMLParser; 
    43     OfflineProvider provider = new OfflineProvider(); 
    44     DSPProcessor consumer = new DSPProcessor(new StandardTagLibrary())
    45          
    46     // run through with a bogus consumer 
    47     provider.setCurrentPath(pwd ~ getPath(testfile)); 
    48     SimpleStream stream = new SimpleStream(testfile,strip(toUTF8(cast(char[])std.file.read(testfile))))
     41char[] getFilename(char[] filename){ 
     42    return filename[rfind(filename,"\\")+1 .. rfind(filename,".")]
     43
     44 
     45char[] getExtension(char[] filename){ 
     46    return filename[rfind(filename,".")+1..$]
     47
     48 
     49void main(char[][] args){    
     50    RequestConfig cfg
    4951     
    50     try{ 
    51         parser.parse(consumer, provider, stream); 
    52         writefln("%s",consumer.getServletFile()); 
    53     } 
    54     catch(XMLException e){ 
    55         writefln("%s",e.toString()); 
    56     } 
     52    // configuration 
     53    char[] filename = `dspconf\dsp01.dsp`; 
     54     
     55    cfg.pwd = getPath(args[0]); 
     56    cfg.ext = getExtension(filename); 
     57    cfg.name = getFilename(filename); 
     58     
     59    cfg.modulePath = getPath(filename); 
     60    cfg.requestModule = cfg.modulePath ~ cfg.name; 
     61    cfg.dspSourceFilename = cfg.pwd ~ filename; 
     62     
     63    cfg.tempDirectory = cfg.pwd ~ `dspconf\_temp\`; 
     64    cfg.cacheDirectory = cfg.pwd ~ `dspconf\_cache\`; 
     65     
     66    cfg.dSourceFilename = cfg.tempDirectory ~ cfg.name ~ ".d"; 
     67    cfg.destServletFilename = cfg.cacheDirectory ~ cfg.name ~ ".dll"; 
     68     
     69     
     70    // build the servlet 
     71    writefln("%s",cfg.toString()); 
     72     
     73    ServletCompiler compiler = new ServletCompiler(); 
     74     
     75    compiler.CompileServlet(cfg); 
    5776}