Changeset 310
- Timestamp:
- 05/27/08 22:11:52 (6 months ago)
- Files:
-
- trunk/enki2/enki/bootstrap/Lexer.d (modified) (1 diff)
- trunk/enki2/enki/bootstrap/bootstrap.d (modified) (3 diffs)
- trunk/enki2/enki/frontend/Enki2Parser.bnf (modified) (1 diff)
- trunk/enki2/enki/frontend/Enki2Parser.d (modified) (2 diffs)
- trunk/enki2/enki/frontend/EnkiLexer.d (modified) (1 diff)
- trunk/enki2/enki/frontend/EnkiLexerBase.d (modified) (1 diff)
- trunk/enki2/enki/frontend/Frontend.d (moved) (moved from trunk/enki2/enki/Frontend.d) (3 diffs)
- trunk/enki2/enki/frontend/all.d (modified) (1 diff)
- trunk/enki2/enki/generator/DGenerator.d (modified) (2 diffs)
- trunk/enki2/enki/generator/TextGenerator.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/enki2/enki/bootstrap/Lexer.d
r308 r310 14 14 setAttribute("bootstrap","filename","./enki/bootstrap/Lexer.d"); 15 15 setAttribute("bootstrap","classname","Lexer"); 16 setAttribute("bnf","filename","enki/ bootstrap/EnkiLexer.bnf");16 setAttribute("bnf","filename","enki/frontend/EnkiLexer.bnf"); 17 17 setAttribute("all","copyright"," 18 18 Copyright (c) 2008 Eric Anderton trunk/enki2/enki/bootstrap/bootstrap.d
r303 r310 31 31 */ 32 32 33 public import enki. Backend;33 public import enki.frontend.Frontend; 34 34 public import Integer = tango.text.convert.Integer; 35 35 … … 41 41 private import enki.bootstrap.Parser; 42 42 43 class BootstrapT(CharT) : BackendT!(CharT){43 class BootstrapT(CharT) : FrontendT!(CharT){ 44 44 uint commentCount; 45 45 … … 48 48 } 49 49 50 public void includeFile(String name){51 throw new Exception("Cannot include from bootstrap.");52 }53 54 50 public void addComment(String comment){ 55 51 String name = "comment_" ~ Integer.toString(commentCount); trunk/enki2/enki/frontend/Enki2Parser.bnf
r307 r310 42 42 OTHER DEALINGS IN THE SOFTWARE. 43 43 "; 44 45 nop = bool;46 47 any = String;48 49 eoi = bool;50 51 44 Syntax 52 45 ::= (Prototype | Alias | Rule | Directive | Attribute)* eoi; trunk/enki2/enki/frontend/Enki2Parser.d
r308 r310 27 27 module enki.frontend.Enki2Parser; 28 28 29 private import enki.frontend. Enki2ParserBase;29 private import enki.frontend.Frontend; 30 30 private import enki.EnkiToken; 31 31 private import enki.Binding; … … 38 38 debug import tango.io.Stdout; 39 39 40 class Enki2ParserT(CharT):Enki2ParserBaseT!(CharT){ 40 class Enki2ParserT(CharT):FrontendT!(CharT){ 41 static char[] getHelp(){ 42 return "Frontend that supports the Enki2 variant of EBNF."; 43 } 44 41 45 /* 42 46 Syntax trunk/enki2/enki/frontend/EnkiLexer.d
r308 r310 24 24 25 25 +/ 26 27 module enki.EnkiLexer; 26 module enki.frontend.EnkiLexer; 27 28 28 import enki.EnkiToken; 29 import enki. EnkiLexerBase;29 import enki.frontend.EnkiLexerBase; 30 30 31 31 debug import tango.io.Stdout; 32 32 33 33 class EnkiLexerT(CharT):EnkiLexerBase!(CharT){ 34 35 36 37 38 34 /* 39 35 Tokens trunk/enki2/enki/frontend/EnkiLexerBase.d
r309 r310 23 23 OTHER DEALINGS IN THE SOFTWARE. 24 24 +/ 25 module enki. EnkiLexerBase;25 module enki.frontend.EnkiLexerBase; 26 26 27 27 import enki.EnkiToken; trunk/enki2/enki/frontend/Frontend.d
r309 r310 23 23 OTHER DEALINGS IN THE SOFTWARE. 24 24 +/ 25 module enki. Frontend;25 module enki.frontend.Frontend; 26 26 27 public import enki.types; 27 private import enki.types; 28 private import enki.EnkiToken; 29 private import enki.frontend.EnkiLexer; 28 30 29 abstract class FrontendT(CharT,BaseClass = Object) : BaseClass{ 31 private import enkilib.d.TokenParser; 32 private import enkilib.d.ParserException; 33 34 private import tango.io.File; 35 private import tango.io.FilePath; 36 37 debug import tango.io.Stdout; 38 39 public abstract class FrontendT(CharT) : TokenParserT!(CharT,EnkiTokenT!(CharT)){ 30 40 mixin AllTypesMixin!(CharT); 41 alias EnkiTokenT!(CharT) EnkiToken; 42 alias EnkiLexerT!(CharT) EnkiLexer; 31 43 32 44 public AttributeSet attributes; … … 36 48 ruleSet = new RuleSet(); 37 49 50 // add implicitly defined productions from the parser 38 51 ruleSet.addRule(new RulePrototype("nop","bool")); 39 52 ruleSet.addRule(new RulePrototype("any","String")); 40 53 ruleSet.addRule(new RulePrototype("eoi","bool")); 41 54 } 42 43 abstract void includeFile(String filename); 44 55 45 56 public void addRule(Rule rule){ 46 57 ruleSet.addRule(rule); … … 78 89 } 79 90 } 80 91 92 protected EnkiToken[] getTokensFromFile(FilePath path){ 93 auto inFile = new File(path); 94 auto lexer = new EnkiLexer(); 95 lexer.initialize(cast(char[])inFile.read(),path.toString()); 96 97 if(!lexer.parse_Tokens()){ 98 throw ParserException("Lexer Fail"); 99 } 100 return lexer.getMatchValue!(EnkiToken[])(); 101 } 102 103 /** 104 Performs the lexer pass. 105 */ 106 void initialize(FilePath path){ 107 super.initialize(getTokensFromFile(path)); 108 } 109 110 /** 111 Provides support for the include directive. 112 113 Implementation launches another lexer instance and inserts the lexed tokens into the stream, 114 at the current position. 115 */ 116 void includeFile(String filename){ 117 debug Stdout.format("including {0}",filename).newline; 118 data = data[0..pos] ~ getTokensFromFile(new FilePath(filename)) ~ data[pos..$]; 119 debug Stdout.format("include done").newline; 120 } 121 122 bool parse_Syntax(); 123 124 bool parse(){ 125 return this.parse_Syntax(); 126 } 81 127 } trunk/enki2/enki/frontend/all.d
r308 r310 30 30 //public import enki.frontend.ABNFParser; 31 31 32 private import enki. EnkiParserBase;32 private import enki.frontend.Frontend; 33 33 34 34 alias char CharT; 35 35 36 36 interface FrontendRef{ 37 public EnkiParserBase!(CharT) create();37 public FrontendT!(CharT) create(); 38 38 public char[] getHelp(); 39 39 } 40 40 41 class FrontendRefT(T : EnkiParserBase!(CharT)) : FrontendRef{42 public EnkiParserBase!(CharT) create(){41 class FrontendRefT(T : FrontendT!(CharT)) : FrontendRef{ 42 public FrontendT!(CharT) create(){ 43 43 return new T(); 44 44 } trunk/enki2/enki/generator/DGenerator.d
r308 r310 60 60 public this(IBuffer buf){ 61 61 super(buf); 62 attrs.set("all","help",""); 63 attrs.set("all","copyright",""); 62 64 attrs.set("d","header","import enkilib.d.CharParser;"); 63 65 attrs.set("d","baseclass","CharParser!(char)"); … … 197 199 198 200 indent; 201 // help stub 202 auto help = attrs.get("all","help"); 203 emitln("static char[] getHelp(){{"); 204 indent; 205 emitln("return \"{0}\";",safeString(help)); 206 unindent; 207 emitln("}}"); 208 199 209 // class body 200 210 foreach(rule;ruleSet.getRules()){ trunk/enki2/enki/generator/TextGenerator.d
r309 r310 27 27 import enki.AttributeSet; 28 28 import enki.RuleSet; 29 import enki. Frontend;29 import enki.frontend.Frontend; 30 30 31 31 import tango.io.Print; … … 106 106 public void toCode(FrontendT!(CharT) frontend,bool test=false){ 107 107 visit(frontend.attributes); 108 visit(frontend. attributes);108 visit(frontend.ruleSet); 109 109 110 110 if(test){
