Changeset 310

Show
Ignore:
Timestamp:
05/27/08 22:11:52 (6 months ago)
Author:
pragma
Message:

Restructuring Enki2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/enki2/enki/bootstrap/Lexer.d

    r308 r310  
    1414        setAttribute("bootstrap","filename","./enki/bootstrap/Lexer.d"); 
    1515        setAttribute("bootstrap","classname","Lexer"); 
    16         setAttribute("bnf","filename","enki/bootstrap/EnkiLexer.bnf"); 
     16        setAttribute("bnf","filename","enki/frontend/EnkiLexer.bnf"); 
    1717        setAttribute("all","copyright"," 
    1818    Copyright (c) 2008 Eric Anderton 
  • trunk/enki2/enki/bootstrap/bootstrap.d

    r303 r310  
    3131*/ 
    3232 
    33 public import enki.Backend; 
     33public import enki.frontend.Frontend; 
    3434public import Integer = tango.text.convert.Integer; 
    3535 
     
    4141private import enki.bootstrap.Parser; 
    4242 
    43 class BootstrapT(CharT) : BackendT!(CharT){        
     43class BootstrapT(CharT) : FrontendT!(CharT){       
    4444    uint commentCount; 
    4545 
     
    4848    } 
    4949         
    50     public void includeFile(String name){ 
    51         throw new Exception("Cannot include from bootstrap."); 
    52     } 
    53  
    5450    public void addComment(String comment){ 
    5551        String name = "comment_" ~ Integer.toString(commentCount); 
  • trunk/enki2/enki/frontend/Enki2Parser.bnf

    r307 r310  
    4242    OTHER DEALINGS IN THE SOFTWARE. 
    4343"; 
    44  
    45 nop = bool; 
    46  
    47 any = String; 
    48  
    49 eoi = bool; 
    50  
    5144Syntax 
    5245    ::= (Prototype | Alias | Rule | Directive | Attribute)* eoi; 
  • trunk/enki2/enki/frontend/Enki2Parser.d

    r308 r310  
    2727module enki.frontend.Enki2Parser; 
    2828 
    29 private import enki.frontend.Enki2ParserBase
     29private import enki.frontend.Frontend
    3030private import enki.EnkiToken; 
    3131private import enki.Binding; 
     
    3838debug import tango.io.Stdout; 
    3939 
    40 class Enki2ParserT(CharT):Enki2ParserBaseT!(CharT){ 
     40class Enki2ParserT(CharT):FrontendT!(CharT){ 
     41    static char[] getHelp(){ 
     42        return "Frontend that supports the Enki2 variant of EBNF."; 
     43    } 
     44         
    4145    /* 
    4246    Syntax 
  • trunk/enki2/enki/frontend/EnkiLexer.d

    r308 r310  
    2424 
    2525+/ 
    26  
    27 module enki.EnkiLexer; 
     26module enki.frontend.EnkiLexer; 
     27 
    2828import enki.EnkiToken; 
    29 import enki.EnkiLexerBase; 
     29import enki.frontend.EnkiLexerBase; 
    3030 
    3131debug import tango.io.Stdout; 
    3232 
    3333class EnkiLexerT(CharT):EnkiLexerBase!(CharT){ 
    34  
    35  
    36  
    37  
    3834    /* 
    3935    Tokens 
  • trunk/enki2/enki/frontend/EnkiLexerBase.d

    r309 r310  
    2323    OTHER DEALINGS IN THE SOFTWARE. 
    2424+/ 
    25 module enki.EnkiLexerBase; 
     25module enki.frontend.EnkiLexerBase; 
    2626 
    2727import enki.EnkiToken; 
  • trunk/enki2/enki/frontend/Frontend.d

    r309 r310  
    2323    OTHER DEALINGS IN THE SOFTWARE. 
    2424+/ 
    25 module enki.Frontend; 
     25module enki.frontend.Frontend; 
    2626 
    27 public import enki.types; 
     27private import enki.types; 
     28private import enki.EnkiToken; 
     29private import enki.frontend.EnkiLexer; 
    2830 
    29 abstract class FrontendT(CharT,BaseClass = Object) : BaseClass{ 
     31private import enkilib.d.TokenParser; 
     32private import enkilib.d.ParserException; 
     33 
     34private import tango.io.File; 
     35private import tango.io.FilePath; 
     36 
     37debug import tango.io.Stdout; 
     38 
     39public abstract class FrontendT(CharT) : TokenParserT!(CharT,EnkiTokenT!(CharT)){ 
    3040    mixin AllTypesMixin!(CharT); 
     41    alias EnkiTokenT!(CharT) EnkiToken; 
     42    alias EnkiLexerT!(CharT) EnkiLexer; 
    3143     
    3244    public AttributeSet attributes; 
     
    3648        ruleSet = new RuleSet(); 
    3749         
     50        // add implicitly defined productions from the parser 
    3851        ruleSet.addRule(new RulePrototype("nop","bool")); 
    3952        ruleSet.addRule(new RulePrototype("any","String")); 
    4053        ruleSet.addRule(new RulePrototype("eoi","bool")); 
    4154    } 
    42      
    43     abstract void includeFile(String filename); 
    44      
     55         
    4556    public void addRule(Rule rule){ 
    4657        ruleSet.addRule(rule); 
     
    7889        } 
    7990    } 
    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    } 
    81127} 
  • trunk/enki2/enki/frontend/all.d

    r308 r310  
    3030//public import enki.frontend.ABNFParser; 
    3131 
    32 private import enki.EnkiParserBase
     32private import enki.frontend.Frontend
    3333 
    3434alias char CharT; 
    3535 
    3636interface FrontendRef{ 
    37     public EnkiParserBase!(CharT) create(); 
     37    public FrontendT!(CharT) create(); 
    3838    public char[] getHelp(); 
    3939} 
    4040 
    41 class FrontendRefT(T : EnkiParserBase!(CharT)) : FrontendRef{ 
    42     public EnkiParserBase!(CharT) create(){ 
     41class FrontendRefT(T : FrontendT!(CharT)) : FrontendRef{ 
     42    public FrontendT!(CharT) create(){ 
    4343        return new T(); 
    4444    } 
  • trunk/enki2/enki/generator/DGenerator.d

    r308 r310  
    6060    public this(IBuffer buf){ 
    6161        super(buf); 
     62        attrs.set("all","help",""); 
     63        attrs.set("all","copyright",""); 
    6264        attrs.set("d","header","import enkilib.d.CharParser;"); 
    6365        attrs.set("d","baseclass","CharParser!(char)"); 
     
    197199 
    198200        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         
    199209            // class body 
    200210            foreach(rule;ruleSet.getRules()){ 
  • trunk/enki2/enki/generator/TextGenerator.d

    r309 r310  
    2727import enki.AttributeSet; 
    2828import enki.RuleSet; 
    29 import enki.Frontend; 
     29import enki.frontend.Frontend; 
    3030 
    3131import tango.io.Print; 
     
    106106    public void toCode(FrontendT!(CharT) frontend,bool test=false){ 
    107107        visit(frontend.attributes); 
    108         visit(frontend.attributes); 
     108        visit(frontend.ruleSet); 
    109109 
    110110        if(test){