Changeset 311 for trunk

Show
Ignore:
Timestamp:
05/27/08 23:31:37 (6 months ago)
Author:
pragma
Message:

Finished restructuring Enki2.

  • Added support for a .d-help attribute that helps describe the parser's purpose
  • Added support for multiple frontends
Files:

Legend:

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

    r310 r311  
    77module enki.frontend.EnkiLexer; 
    88import enki.EnkiToken; 
    9 import enki.EnkiLexerBase; 
     9import enki.frontend.EnkiLexerBase; 
    1010"); 
    1111        setAttribute("d","filename","./enki/frontend/EnkiLexer.d"); 
  • trunk/enki2/enki/bootstrap/Parser.d

    r308 r311  
    33class Parser(CharT) : BootstrapT!(CharT){ 
    44    void runBootstrap(){ 
    5         setAttribute("d","baseclass","Enki2ParserBaseT!(CharT)"); 
     5        setAttribute("d","baseclass","FrontendT!(CharT)"); 
    66        setAttribute("d","header"," 
    77module enki.frontend.Enki2Parser; 
    88 
    9 private import enki.frontend.Enki2ParserBase
     9private import enki.frontend.Frontend
    1010private import enki.EnkiToken; 
    1111private import enki.Binding; 
  • trunk/enki2/enki/enki.d

    r308 r311  
    187187    } 
    188188    catch(Exception e){ 
    189         Stdout(e).newline; 
    190          
    191         debug{ 
    192             Stdout.format("Lexer data:").newline; 
    193             foreach(i,foo; parser.data){ 
    194                 Stdout.format("{3} {0} {1} '{2}'",i,foo.type,foo.value,foo.filename).newline; 
    195             } 
    196  
    197             Stdout.format("Parser data {0} rules:",parser.ruleSet.getRules.length).newline; 
    198             foreach(rule; parser.ruleSet.getRules){ 
    199                 Stdout.format("{0} {1}",rule.insertOrder,rule.getName).newline; 
    200             } 
    201         }        
     189        Stdout(e).newline;       
     190        debug parser.debugParser();  
    202191        return 1; 
    203192    } 
  • trunk/enki2/enki/frontend/Enki2Lexer.bnf

    r308 r311  
    11.d-baseclass = "EnkiLexerBase!(CharT)"; 
    22.d-header = " 
    3 module enki.EnkiLexer; 
     3module enki.frontend.EnkiLexer; 
    44import enki.EnkiToken; 
    5 import enki.EnkiLexerBase; 
     5import enki.frontend.EnkiLexerBase; 
    66"; 
    77.d-filename = "./enki/EnkiLexer.d"; 
  • trunk/enki2/enki/frontend/Enki2Lexer.d

    r310 r311  
    3131debug import tango.io.Stdout; 
    3232 
    33 class EnkiLexerT(CharT):EnkiLexerBase!(CharT){ 
     33class Enki2LexerT(CharT):EnkiLexerBaseT!(CharT){ 
    3434    /* 
    3535    Tokens 
  • trunk/enki2/enki/frontend/Enki2Parser.d

    r310 r311  
    2828 
    2929private import enki.frontend.Frontend; 
     30private import enki.frontend.Enki2Lexer; 
    3031private import enki.EnkiToken; 
    3132private import enki.Binding; 
     
    3839debug import tango.io.Stdout; 
    3940 
    40 class Enki2ParserT(CharT):FrontendT!(CharT){ 
     41class Enki2ParserT(CharT):FrontendBaseT!(CharT,Enki2LexerT!(CharT)){ 
    4142    static char[] getHelp(){ 
    4243        return "Frontend that supports the Enki2 variant of EBNF."; 
  • trunk/enki2/enki/frontend/EnkiLexerBase.d

    r310 r311  
    2929import tango.util.Convert; 
    3030 
    31 abstract class EnkiLexerBase(CharT) : PositionalCharParserT!(CharT){   
     31abstract class EnkiLexerBaseT(CharT) : PositionalCharParserT!(CharT){  
    3232    alias CharT[] String; 
    3333    alias EnkiTokenT!(CharT) EnkiToken; 
  • trunk/enki2/enki/frontend/Frontend.d

    r310 r311  
    11/+ 
    2     Copyright (c) 2006-2008 Eric Anderton 
     2    Copyright (c) 2008 Eric Anderton 
    33 
    44    Permission is hereby granted, free of charge, to any person 
     
    2727private import enki.types; 
    2828private import enki.EnkiToken; 
    29 private import enki.frontend.EnkiLexer; 
    3029 
    3130private import enkilib.d.TokenParser; 
     
    3736debug import tango.io.Stdout; 
    3837 
    39 public abstract class FrontendT(CharT) : TokenParserT!(CharT,EnkiTokenT!(CharT)){ 
     38interface FrontendT(CharT){ 
     39    public void initialize(FilePath path); 
     40    public bool parse(); 
     41    public void semanticPass(); 
     42    public AttributeSetT!(CharT) getAttributes(); 
     43    public RuleSetT!(CharT) getRules(); 
     44    public void debugParser(); 
     45
     46 
     47public abstract class FrontendBaseT(CharT,EnkiLexer) : TokenParserT!(CharT,EnkiTokenT!(CharT)), FrontendT!(CharT){ 
    4048    mixin AllTypesMixin!(CharT); 
    4149    alias EnkiTokenT!(CharT) EnkiToken; 
    42     alias EnkiLexerT!(CharT) EnkiLexer; 
    4350     
    44     public AttributeSet attributes; 
    45     public RuleSet ruleSet; 
     51    protected AttributeSet attributes; 
     52    protected RuleSet ruleSet; 
    4653 
    4754    public this(){ 
     
    5360        ruleSet.addRule(new RulePrototype("eoi","bool")); 
    5461    } 
    55          
     62    public AttributeSet getAttributes(){ 
     63        return attributes; 
     64    } 
     65     
     66    public RuleSet getRules(){ 
     67        return ruleSet; 
     68    } 
     69     
    5670    public void addRule(Rule rule){ 
    5771        ruleSet.addRule(rule); 
     
    125139        return this.parse_Syntax(); 
    126140    } 
     141     
     142    public void debugParser(){ 
     143        debug{ 
     144            Stdout.format("Lexer data:").newline; 
     145            foreach(i,foo; data){ 
     146                Stdout.format("{3} {0} {1} '{2}'",i,foo.type,foo.value,foo.filename).newline; 
     147            } 
     148 
     149            Stdout.format("Parser data {0} rules:",ruleSet.getRules().length).newline; 
     150            foreach(rule; ruleSet.getRules()){ 
     151                Stdout.format("{0} {1}",rule.insertOrder,rule.getName).newline; 
     152            } 
     153        }                
     154    } 
    127155} 
  • trunk/enki2/enki/generator/BNFGenerator.d

    r308 r311  
    4444Copyright (c) 2008 Eric Anderton 
    4545 
    46 Generates an EBNF script that is  
    47 equivalent to the input EBNF script.  
     46Generates an Enki2 EBNF script that is  
     47equivalent to the input BNF script. 
    4848Is used primarily for verification and 
    49 validation of Enki itself, and is not  
    50 used for general development. 
     49validation of Enki itself, but can also 
     50be used with the alternative frontends 
     51to translate to the Enki2 EBNF syntax. 
    5152`; 
    5253    } 
  • trunk/enki2/enki/generator/TextGenerator.d

    r310 r311  
    105105         
    106106    public void toCode(FrontendT!(CharT) frontend,bool test=false){ 
    107         visit(frontend.attributes); 
    108         visit(frontend.ruleSet); 
     107        visit(frontend.getAttributes()); 
     108        visit(frontend.getRules()); 
    109109 
    110110        if(test){ 
  • trunk/enki2/enkilib/d/Parser.d

    r305 r311  
    109109    bool match(int start,int end); 
    110110    bool match(dchar value); 
    111          
     111            
    112112    private template isArray(T) 
    113113    {