Changeset 49
- Timestamp:
- 04/23/05 09:34:52 (4 years ago)
- Files:
-
- trunk/dsp/DSPGrammar.d (modified) (3 diffs)
- trunk/dsp/DSPProcessor.d (modified) (1 diff)
- trunk/dsp/RequestConfig.d (added)
- trunk/dsp/ServletCompiler.d (added)
- trunk/dsp/ServletGenerator.d (modified) (1 diff)
- trunk/dsp/servlet (added)
- trunk/dsp/servlet/IDSPRequest.d (added)
- trunk/dsp/servlet/IDSPResponse.d (added)
- trunk/dsp/servlet/IDSPServletContext.d (added)
- trunk/dsp/servlet/ServletRegistry.bak (added)
- trunk/dsp/servlet/ServletRegistry.d (added)
- trunk/dspconf/_cache (added)
- trunk/dspconf/_temp (added)
- trunk/dspconf/dsp01.dsp (modified) (2 diffs)
- trunk/dspruntime.bat (added)
- trunk/dsptest.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dsp/DSPGrammar.d
r48 r49 37 37 public static char[] preamble = "dsp:"; 38 38 public static char[] expressionToken = "__expression"; 39 public static char[] expressionTokenDecl = "private static char[] __expression"; 39 40 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()"; 40 46 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"; 43 50 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 } 47 55 48 56 private static char[] literalString(char[] text){ 49 57 return replace(text,"`","\x60"); 50 58 } 51 59 52 60 public static char[] outputString(char[] text){ 53 61 return outputFunc ~ "(`" ~ literalString(text) ~ "`);" ~ newline; … … 55 63 56 64 public static char[] outputExpression(char[] expr){ 57 return outputFunc ~ "(" ~ expr ~ ");" ~ newline;65 return outputFunc ~ "(" ~ toStringFunc ~ "(" ~ expr ~ "));" ~ newline; 58 66 } 59 67 … … 62 70 } 63 71 72 public static char[] servletFunctionName(char[] name){ 73 return servletPrefix ~ name; 74 } 64 75 65 76 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 ; 68 96 } 69 97 70 public static char[] servletFile(char[] name,char[] cpIn, char[] cpBody, char[] cpOut){71 return servletFunction(name,cpIn,cpBody,cpOut);72 }73 98 } 74 99 trunk/dsp/DSPProcessor.d
r48 r49 48 48 } 49 49 50 public char[] getServlet File(){51 return generator.getServlet File();50 public char[] getServletSource(char[] modulePath){ 51 return generator.getServletSource(modulePath); 52 52 } 53 53 trunk/dsp/ServletGenerator.d
r48 r49 147 147 } 148 148 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 ; 151 154 } 152 155 } trunk/dspconf/dsp01.dsp
r48 r49 3 3 <?dsp:out assert(response); ?> 4 4 <?dsp:xml version="1.0" ?> 5 5 <?dsp 6 char[] expr(){ 7 return "hi there"; 8 } 9 ?> 6 10 <html foo="'bar'" bar='"foo"'> 7 11 <body something="32#expr()#"> … … 14 18 <dsp:code> 15 19 } 16 else response. put("hello world");20 else response.getWriter.put("hello world"); 17 21 </dsp:code> 18 22 </body> trunk/dsptest.d
r48 r49 26 26 import xml.all; 27 27 28 import dsp.DSPProcessor; 29 import dsp.StandardTagLibrary; 28 import dsp.ServletCompiler; 29 import dsp.RequestConfig; 30 31 import misc.Library; 30 32 31 33 import std.stdio; … … 37 39 } 38 40 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))));41 char[] getFilename(char[] filename){ 42 return filename[rfind(filename,"\\")+1 .. rfind(filename,".")]; 43 } 44 45 char[] getExtension(char[] filename){ 46 return filename[rfind(filename,".")+1..$]; 47 } 48 49 void main(char[][] args){ 50 RequestConfig cfg; 49 51 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); 57 76 }
