Changeset 235

Show
Ignore:
Timestamp:
08/11/06 11:12:17 (2 years ago)
Author:
pragma
Message:

Huge changeset to push Enki towards v1.2.
This update includes the start of a D lexer/parser

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/enki/BaseParser.d

    r231 r235  
    4747    } 
    4848     
    49     private String data; 
    50     private uint pos; 
    51     private ErrorData[] errors; 
     49    protected String data; 
     50    protected uint pos; 
     51    protected ErrorData[] errors; 
    5252     
    5353    public this(){       
  • trunk/enki/Directive.d

    r231 r235  
    3131debug private import std.stdio; 
    3232 
     33/* 
     34    RootOnly: 
     35        .baseclass 
     36        .classname 
     37        .module 
     38        .typelib 
     39        .parsetype 
     40        .utf 
     41        .boilerplate 
     42         
     43    FirstPass: 
     44        .import 
     45        .define 
     46        .include 
     47        .header 
     48         
     49    SecondPass: 
     50        .alias 
     51        .code 
     52*/ 
     53 
     54 
    3355abstract class Directive : SyntaxLine, IRenderable{ 
     56    enum: uint{  
     57        RootOnly,    
     58        FirstPass, 
     59        SecondPass, 
     60    }        
     61     
     62    public uint type(){ 
     63        return Directive.SecondPass; 
     64    } 
     65     
    3466    public void semanticPass(BaseEnkiParser root){ 
    3567        //do nothing 
     
    4880    public void render(CodeGenerator generator,Statement passterm,Statement failterm){ 
    4981        // do nothing 
    50     }   
     82    } 
    5183} 
    5284 
     
    5486    String imp; 
    5587     
     88    public uint type(){ 
     89        return Directive.FirstPass; 
     90    }    
     91         
    5692    public this(String imp){ 
    5793        this.imp = imp; 
     
    69105        return "Import Directive"; 
    70106    } 
     107 
    71108} 
    72109 
     
    74111    String name; 
    75112     
     113    public uint type(){ 
     114        return Directive.RootOnly; 
     115    }    
     116     
    76117    public this(String name){ 
    77118        this.name = name; 
     
    93134class ClassnameDirective : Directive{ 
    94135    String name; 
     136     
     137    public uint type(){ 
     138        return Directive.RootOnly; 
     139    } 
    95140     
    96141    public this(String name){ 
     
    116161    String description; 
    117162    bool isTerminal; 
     163     
     164    public uint type(){ 
     165        return Directive.FirstPass; 
     166    } 
    118167     
    119168    public this(String returnType,String name,bool isTerminal,String description){ 
     
    153202class IncludeDirective : Directive{ 
    154203    String filename; 
     204     
     205    public uint type(){ 
     206        return Directive.FirstPass; 
     207    } 
    155208     
    156209    public this(String filename){ 
     
    195248    String rule; 
    196249    String ruleAlias; 
    197          
     250     
     251    public uint type(){ 
     252        return Directive.SecondPass; 
     253    } 
     254     
    198255    public this(String rule,String ruleAlias){ 
    199256        this.rule = rule; 
     
    216273class ModuleDirective : Directive{ 
    217274    String moduleName; 
    218          
     275     
     276    public uint type(){ 
     277        return Directive.RootOnly; 
     278    } 
     279     
    219280    public this(String moduleName){ 
    220281        this.moduleName = moduleName; 
     
    237298class CodeDirective : Directive{ 
    238299    String code; 
     300     
     301    public uint type(){ 
     302        return Directive.SecondPass; 
     303    } 
    239304         
    240305    public this(String code){ 
     
    261326class TypelibDirective : Directive{ 
    262327    String moduleName; 
    263          
     328     
     329    public uint type(){ 
     330        return Directive.RootOnly; 
     331    } 
     332     
    264333    public this(String moduleName){ 
    265334        this.moduleName = moduleName; 
     
    281350class ParseTypeDirective : Directive{ 
    282351    String typeName; 
    283          
     352     
     353    public uint type(){ 
     354        return Directive.RootOnly; 
     355    } 
     356     
    284357    public this(String typeName){ 
    285358        this.typeName = typeName; 
     
    298371    }    
    299372} 
     373 
     374 
     375class BoilerplateDirective : Directive{ 
     376    String code; 
     377     
     378    public uint type(){ 
     379        return Directive.RootOnly; 
     380    } 
     381         
     382    public this(String code){ 
     383        this.code = code; 
     384    } 
     385     
     386    public void semanticPass(BaseEnkiParser root){ 
     387        root.setBoilerplate(code); 
     388    } 
     389     
     390    public String toBNF(){ 
     391        return ".boilerplate{{{" ~ code ~ "}}}\n"; 
     392    } 
     393     
     394    public String toString(){ 
     395        return "Boilerplate Directive"; 
     396    }    
     397} 
     398 
     399class HeaderDirective : Directive{ 
     400    String code; 
     401     
     402    public uint type(){ 
     403        return Directive.FirstPass; 
     404    } 
     405         
     406    public this(String code){ 
     407        this.code = code; 
     408    } 
     409     
     410    public void semanticPass(BaseEnkiParser root){ 
     411        root.setHeader(code); 
     412    } 
     413     
     414    public String toBNF(){ 
     415        return ".header{{{" ~ code ~ "}}}\n"; 
     416    } 
     417     
     418    public String toString(){ 
     419        return "Header Directive"; 
     420    } 
     421} 
     422 
     423class UTFDirective : Directive{ 
     424    String value; 
     425     
     426    public uint type(){ 
     427        return Directive.RootOnly; 
     428    } 
     429         
     430    public this(String value){ 
     431        this.value = value; 
     432    } 
     433     
     434    public void semanticPass(BaseEnkiParser root){ 
     435        switch(value){ 
     436        case "8": 
     437        case "32": 
     438        case "16": 
     439            break; 
     440        default: 
     441            throw new Exception("The value '" ~ value ~ "' is not a valid UTF parameter.  Expected '8', '16' or '32'"); 
     442        } 
     443        root.setUTF(value);      
     444    } 
     445     
     446    public String toBNF(){ 
     447        return ".utf(\"" ~ value ~ "\");\n"; 
     448    }    
     449     
     450    public String toString(){ 
     451        return "UTF Directive"; 
     452    } 
     453} 
  • trunk/enki/EnkiBackend.d

    r203 r235  
    6464    String typelib; 
    6565    String parseType; 
     66    String boilerplate; 
     67    String header; 
     68    String utf; 
    6669    UserProduction[] userProductions; 
    6770 
     
    7174        this.typelib = "enki.types"; 
    7275        this.parseType = "String"; 
     76        this.utf = "8"; 
    7377    } 
    7478     
     
    7882     
    7983    public void add(BaseEnkiParser other){ 
    80         debug writefln("Aggregating included rules - %d total",other.rules.length); 
    81         foreach(name,rule; other.rules){ 
    82             debug writefln("\t%s included",name); 
    83             this.rules[name] = rule; 
    84         } 
    85          
    86         debug writefln("Aggregating included lines - %d total",other.lines.length); 
    87         this.lines ~= other.lines;       
     84        // aggregate and perform nested semantic pass on directives 
     85        debug writefln("Running Non-Root Semantic Pass on aggregated lines."); 
     86         
     87        foreach(line; other.lines){ 
     88            Directive directive = cast(Directive)line; 
     89            if(directive && directive.type == Directive.FirstPass){ 
     90                directive.semanticPass(this); 
     91            } 
     92            else{ 
     93                this.lines ~= line; 
     94            } 
     95        }        
    8896    } 
    8997     
     
    104112    } 
    105113     
     114    public void setBoilerplate(String value){ 
     115        boilerplate ~= value; 
     116    }    
     117     
     118    public void setHeader(String value){ 
     119        header ~= value; 
     120    } 
     121         
    106122    public void defineUserProduction(String returnType,String name,String description){ 
    107123        userProductions ~= UserProduction(returnType,name,description); 
     
    119135    public String getParseType(){ 
    120136        return parseType; 
     137    } 
     138     
     139    public void setUTF(String value){ 
     140        utf = value; 
    121141    } 
    122142     
     
    177197     
    178198    public void semanticPass(){ 
    179         // first pass - gather all production names 
     199        // first/root pass 
     200        debug writefln("-- Root/First Semantic Pass --"); 
     201        foreach(line; lines){        
     202            Directive directive = cast(Directive)line; 
     203            if(directive && (directive.type == Directive.FirstPass || directive.type == Directive.RootOnly)){ 
     204                directive.semanticPass(this); 
     205            } 
     206        } 
     207         
     208        // gather production names 
    180209        foreach(line; lines){ 
    181210            Rule rule = cast(Rule)line; 
    182211            if(rule){ 
    183                 this.rules[rule.name] = rule; 
    184             } 
    185         } 
    186          
    187         // resolve all lines 
    188         foreach(line; lines){        
    189             line.semanticPass(this); 
    190         } 
     212                rules[rule.name] = rule; 
     213            } 
     214        } 
     215 
     216        // second pass - realize all other directives 
     217        debug writefln("-- Second Semantic Pass --"); 
     218        foreach(line; lines){ 
     219            Directive directive = cast(Directive)line; 
     220            if(directive && (directive.type == Directive.SecondPass)){ 
     221                directive.semanticPass(this); 
     222            } 
     223        } 
     224                 
     225        // resolve all rules last 
     226        debug writefln("-- Final Semantic Pass --"); 
     227        foreach(name,rule; rules){ 
     228            debug writefln("-- Semantic Pass for rule %s --",name); 
     229            rule.semanticPass(this); 
     230        } 
     231         
    191232    } 
    192233         
     
    194235        auto CodeGenerator generator = new CodeGenerator(this.parseType); 
    195236        with(generator){ 
    196             emit("//auto-generated parser"); 
     237            // boilerplate section 
     238            emit("//Generated by Enki v1.2"); 
     239            emit(""); 
     240            emit(boilerplate); 
     241             
     242            // module and imports section 
     243            emit(""); 
    197244            if(moduleName){ 
    198245                emit("module " ~ moduleName ~ ";"); 
    199246            } 
     247            emit("version(build) pragma(export_version,EnkiUTF" ~ utf ~ ");"); 
     248            emit(""); 
    200249            emit("debug private import std.stdio;"); 
    201250             
     
    207256            } 
    208257            emit(""); 
     258             
     259            // header section 
     260            emit(header); 
     261            emit("");            
     262             
     263            // parser class definition 
    209264            if(baseclass){ 
    210265                emit("class " ~ classname ~ " : " ~ baseclass ~ "{"); 
  • trunk/enki/EnkiParser.d

    r231 r235  
    1 //auto-generated parser 
    2 module enki.EnkiParser; 
    3 debug private import std.stdio; 
    4 private import enki.types; 
    5 private import enki.EnkiBackend; 
    6 private import enki.Rule; 
    7 private import enki.Expression; 
    8 private import enki.Directive; 
    9  
    10 class EnkiParser : BaseEnkiParser{ 
     1//Generated by Enki v1.2 
    112 
    123/+ 
    13     Copyright (c) 2006 Eric Anderton, BCS 
     4    Copyright (c) 2006 Eric Anderton 
    145 
    156    Permission is hereby granted, free of charge, to any person 
     
    3425    OTHER DEALINGS IN THE SOFTWARE. 
    3526+/ 
     27 
     28module enki.EnkiParser; 
     29version(build) pragma(export_version,EnkiUTF8); 
     30 
     31debug private import std.stdio; 
     32private import enki.types; 
     33private import enki.EnkiBackend; 
     34private import enki.Rule; 
     35private import enki.Expression; 
     36private import enki.Directive; 
     37 
     38 
     39 
     40class EnkiParser : BaseEnkiParser{ 
     41 
    3642    /* 
    3743     
     
    21242130Directive 
    21252131    = Directive dir 
    2126     ::=  "." ( ImportDirective:~dir | BaseClassDirective:~dir | ClassnameDirective:~dir | DefineDirective:~dir | IncludeDirective:~dir | AliasDirective:~dir | ModuleDirective:~dir | CodeDirective:~dir | TypelibDirective:~dir | ParseTypeDirective:~dir ) ; 
     2132    ::=  "." ( ImportDirective:~dir | BaseClassDirective:~dir | ClassnameDirective:~dir | DefineDirective:~dir | IncludeDirective:~dir | AliasDirective:~dir | ModuleDirective:~dir | CodeDirective:~dir | TypelibDirective:~dir | ParseTypeDirective:~dir | BoilerplateDirective:~dir | HeaderDirective:~dir | UTFDirective:~dir ) ; 
    21272133 
    21282134    */ 
     
    21402146            {//Expression 
    21412147                uint start158 = position; 
    2142                 if((parse_ImportDirective().assignCat!(Directive)(bind_dir)) || (parse_BaseClassDirective().assignCat!(Directive)(bind_dir)) || (parse_ClassnameDirective().assignCat!(Directive)(bind_dir)) || (parse_DefineDirective().assignCat!(Directive)(bind_dir)) || (parse_IncludeDirective().assignCat!(Directive)(bind_dir)) || (parse_AliasDirective().assignCat!(Directive)(bind_dir)) || (parse_ModuleDirective().assignCat!(Directive)(bind_dir)) || (parse_CodeDirective().assignCat!(Directive)(bind_dir)) || (parse_TypelibDirective().assignCat!(Directive)(bind_dir)) || (parse_ParseTypeDirective().assignCat!(Directive)(bind_dir))){ 
     2148                if((parse_ImportDirective().assignCat!(Directive)(bind_dir)) || (parse_BaseClassDirective().assignCat!(Directive)(bind_dir)) || (parse_ClassnameDirective().assignCat!(Directive)(bind_dir)) || (parse_DefineDirective().assignCat!(Directive)(bind_dir)) || (parse_IncludeDirective().assignCat!(Directive)(bind_dir)) || (parse_AliasDirective().assignCat!(Directive)(bind_dir)) || (parse_ModuleDirective().assignCat!(Directive)(bind_dir)) || (parse_CodeDirective().assignCat!(Directive)(bind_dir)) || (parse_TypelibDirective().assignCat!(Directive)(bind_dir)) || (parse_ParseTypeDirective().assignCat!(Directive)(bind_dir)) || (parse_BoilerplateDirective().assignCat!(Directive)(bind_dir)) || (parse_HeaderDirective().assignCat!(Directive)(bind_dir)) || (parse_UTFDirective().assignCat!(Directive)(bind_dir))){ 
    21432149                    clearErrors(); 
    21442150                }else{ 
    2145                     setError("Expected ImportDirective, BaseClassDirective, ClassnameDirective, DefineDirective, IncludeDirective, AliasDirective, ModuleDirective, CodeDirective, TypelibDirective or ParseTypeDirective."); 
     2151                    setError("Expected ImportDirective, BaseClassDirective, ClassnameDirective, DefineDirective, IncludeDirective, AliasDirective, ModuleDirective, CodeDirective, TypelibDirective, ParseTypeDirective, BoilerplateDirective, HeaderDirective or UTFDirective."); 
    21462152                    position = start158; 
    21472153                    goto mismatch170; 
     
    25962602    /* 
    25972603     
     2604BoilerplateDirective 
     2605    = new BoilerplateDirective(String code) 
     2606    ::=  "boilerplate" ws "{{{" { any}:code "}}}"; 
     2607 
     2608    */ 
     2609    public ResultT!(BoilerplateDirective) parse_BoilerplateDirective(){ 
     2610        debug writefln("parse_BoilerplateDirective()"); 
     2611        uint start183 = position; 
     2612        String bind_code; 
     2613         
     2614         
     2615        {//Expression 
     2616            uint start184 = position; 
     2617            if(!(terminal("boilerplate").success)){ 
     2618                goto mismatch200; 
     2619            } 
     2620            if(!(parse_ws().success)){ 
     2621                goto mismatch200; 
     2622            } 
     2623            if(!(terminal("{{{").success)){ 
     2624                goto mismatch200; 
     2625            } 
     2626            {//ZeroOrMoreExpr 
     2627                uint start185 = position; 
     2628                uint termPos; 
     2629            loop201: 
     2630                termPos = position; 
     2631                if(terminal("}}}").success){ 
     2632                    goto loopend202; 
     2633                } 
     2634                {//Expression 
     2635                    uint start186 = position; 
     2636                    if((parse_any().success)){ 
     2637                        clearErrors(); 
     2638                        goto loop201; 
     2639                    }else{ 
     2640                        setError("Expected any."); 
     2641                        position = start186; 
     2642                        goto mismatch200; 
     2643                    } 
     2644                } 
     2645            loopend202: 
     2646                smartAssign!(String,String)(bind_code,sliceData(start185,termPos)); 
     2647                {/*do nothing*/} 
     2648            } 
     2649            goto match199; 
     2650        mismatch200: 
     2651            {/*do nothing*/} 
     2652            position = start184; 
     2653            goto mismatch198; 
     2654        match199: 
     2655            clearErrors(); 
     2656            goto match197; 
     2657        } 
     2658    match197: 
     2659        debug writefln("parse_BoilerplateDirective() PASS"); 
     2660        ResultT!(BoilerplateDirective) passed = ResultT!(BoilerplateDirective)(new BoilerplateDirective(bind_code)); 
     2661        return passed; 
     2662    mismatch198: 
     2663        position = start183; 
     2664        ResultT!(BoilerplateDirective) failed = ResultT!(BoilerplateDirective)(); 
     2665        return failed; 
     2666    } 
     2667 
     2668    /* 
     2669     
     2670HeaderDirective 
     2671    = new HeaderDirective(String code) 
     2672    ::=  "header" ws "{{{" { any}:code "}}}"; 
     2673 
     2674    */ 
     2675    public ResultT!(HeaderDirective) parse_HeaderDirective(){ 
     2676        debug writefln("parse_HeaderDirective()"); 
     2677        uint start187 = position; 
     2678        String bind_code; 
     2679         
     2680         
     2681        {//Expression 
     2682            uint start188 = position; 
     2683            if(!(terminal("header").success)){ 
     2684                goto mismatch206; 
     2685            } 
     2686            if(!(parse_ws().success)){ 
     2687                goto mismatch206; 
     2688            } 
     2689            if(!(terminal("{{{").success)){ 
     2690                goto mismatch206; 
     2691            } 
     2692            {//ZeroOrMoreExpr 
     2693                uint start189 = position; 
     2694                uint termPos; 
     2695            loop207: 
     2696                termPos = position; 
     2697                if(terminal("}}}").success){ 
     2698                    goto loopend208; 
     2699                } 
     2700                {//Expression 
     2701                    uint start190 = position; 
     2702                    if((parse_any().success)){ 
     2703                        clearErrors(); 
     2704                        goto loop207; 
     2705                    }else{ 
     2706                        setError("Expected any."); 
     2707                        position = start190; 
     2708                        goto mismatch206; 
     2709                    } 
     2710                } 
     2711            loopend208: 
     2712                smartAssign!(String,String)(bind_code,sliceData(start189,termPos)); 
     2713                {/*do nothing*/} 
     2714            } 
     2715            goto match205; 
     2716        mismatch206: 
     2717            {/*do nothing*/} 
     2718            position = start188; 
     2719            goto mismatch204; 
     2720        match205: 
     2721            clearErrors(); 
     2722            goto match203; 
     2723        } 
     2724    match203: 
     2725        debug writefln("parse_HeaderDirective() PASS"); 
     2726        ResultT!(HeaderDirective) passed = ResultT!(HeaderDirective)(new HeaderDirective(bind_code)); 
     2727        return passed; 
     2728    mismatch204: 
     2729        position = start187; 
     2730        ResultT!(HeaderDirective) failed = ResultT!(HeaderDirective)(); 
     2731        return failed; 
     2732    } 
     2733 
     2734    /* 
     2735     
     2736UTFDirective 
     2737    = new UTFDirective(String value) 
     2738    ::=  "utf" ws "(" ws DirectiveArg:value  ws ")" ws ";"; 
     2739 
     2740    */ 
     2741    public ResultT!(UTFDirective) parse_UTFDirective(){ 
     2742        debug writefln("parse_UTFDirective()"); 
     2743        uint start191 = position; 
     2744        String bind_value; 
     2745         
     2746         
     2747        {//Expression 
     2748            uint start192 = position; 
     2749            if((terminal("utf").success && parse_ws().success && terminal("(").success && parse_ws().success && parse_DirectiveArg().assign!(String)(bind_value) && parse_ws().success && terminal(")").success && parse_ws().success && terminal(";").success)){ 
     2750                clearErrors(); 
     2751                goto match209; 
     2752            }else{ 
     2753                position = start192; 
     2754                goto mismatch210; 
     2755            } 
     2756        } 
     2757    match209: 
     2758        debug writefln("parse_UTFDirective() PASS"); 
     2759        ResultT!(UTFDirective) passed = ResultT!(UTFDirective)(new UTFDirective(bind_value)); 
     2760        return passed; 
     2761    mismatch210: 
     2762        position = start191; 
     2763        ResultT!(UTFDirective) failed = ResultT!(UTFDirective)(); 
     2764        return failed; 
     2765    } 
     2766 
     2767    /* 
     2768     
    25982769DirectiveArg 
    25992770    = String arg 
     
    26032774    public ResultT!(String) parse_DirectiveArg(){ 
    26042775        debug writefln("parse_DirectiveArg()"); 
    2605         uint start183 = position; 
     2776        uint start193 = position; 
    26062777        String bind_arg; 
    26072778         
    26082779         
    26092780        {//Expression 
    2610             uint start184 = position; 
     2781            uint start194 = position; 
    26112782            if((parse_Identifier().assign!(String)(bind_arg)) || (parse_String().assign!(String)(bind_arg))){ 
    26122783                clearErrors(); 
    2613                 goto match197
     2784                goto match211
    26142785            }else{ 
    26152786                setError("Expected Identifier or String."); 
    2616                 position = start184; 
    2617                 goto mismatch198
    2618             } 
    2619         } 
    2620     match197
     2787                position = start194; 
     2788                goto mismatch212
     2789            } 
     2790        } 
     2791    match211
    26212792        debug writefln("parse_DirectiveArg() PASS"); 
    26222793        return ResultT!(String)(bind_arg); 
    2623     mismatch198
    2624         position = start183; 
     2794    mismatch212
     2795        position = start193; 
    26252796        return ResultT!(String)(); 
    26262797    } 
  • trunk/enki/Expression.d

    r231 r235  
    169169        } 
    170170        else{ 
     171            debug writefln("isShort.length %d terms.length",isShort.length,terms.length); 
    171172            assert(isShort.length == terms.length); 
    172173            with(generator){ 
  • trunk/enki/IParser.d

    r231 r235  
    4040    public void clearErrors(); 
    4141    public String getErrorReport(); 
     42    public bool hasErrors(); 
    4243     
    4344    protected ResultString regexp(String str); 
     
    4647    protected void position(uint newPos); 
    4748    protected String sliceData(uint start,uint end); 
     49    public ResultString terminal(uint ch); 
     50    public ResultString range(uint start,uint end); 
    4851} 
  • trunk/enki/bootstrap.d

    r231 r235  
    7171    SyntaxLine[] lines; 
    7272             
    73     lines ~= new CodeDirective(`/+ 
     73    lines ~= new BoilerplateDirective(`/+ 
    7474    Copyright (c) 2006 Eric Anderton 
    7575 
     
    116116    lines ~= new DefineDirective("String","sp",true,"Space(s)"); 
    117117    lines ~= new DefineDirective("String","ws",false,"Whitespace"); 
     118     
     119    lines ~= empty;              
     120    lines ~= new ParseTypeDirective("String"); 
     121    lines ~= new UTFDirective("8"); 
    118122     
    119123    lines ~= empty;              
     
    877881                        makeTerm(new Production("CodeDirective",new Binding(true,"dir"))), 
    878882                        makeTerm(new Production("TypelibDirective",new Binding(true,"dir"))), 
    879                         makeTerm(new Production("ParseTypeDirective",new Binding(true,"dir"))) 
     883                        makeTerm(new Production("ParseTypeDirective",new Binding(true,"dir"))), 
     884                        makeTerm(new Production("BoilerplateDirective",new Binding(true,"dir"))), 
     885                        makeTerm(new Production("HeaderDirective",new Binding(true,"dir"))), 
     886                        makeTerm(new Production("UTFDirective",new Binding(true,"dir"))) 
    880887                    ) 
    881888                ), 
     
    10671074        ) 
    10681075    );   
     1076         
     1077    lines ~= new Rule("BoilerplateDirective", 
     1078        new ClassPredicate("BoilerplateDirective", new Param("code")), 
     1079        new Expression( 
     1080            new Terminal("boilerplate",null), 
     1081            new Production("ws",null), 
     1082            new Terminal("{{{",null), 
     1083            new ZeroOrMoreExpr( 
     1084                new Expression( 
     1085                    new Production("any",null) 
     1086                ), 
     1087                new Binding(false,"code"), 
     1088                new Terminal("}}}",null) 
     1089            ) 
     1090        ) 
     1091    );   
     1092         
     1093    lines ~= new Rule("HeaderDirective", 
     1094        new ClassPredicate("HeaderDirective", new Param("code")), 
     1095        new Expression( 
     1096            new Terminal("header",null), 
     1097            new Production("ws",null), 
     1098            new Terminal("{{{",null), 
     1099            new ZeroOrMoreExpr( 
     1100                new Expression( 
     1101                    new Production("any",null) 
     1102                ), 
     1103                new Binding(false,"code"), 
     1104                new Terminal("}}}",null) 
     1105            ) 
     1106        ) 
     1107    ); 
     1108     
     1109    lines ~= new Rule("UTFDirective", 
     1110        new ClassPredicate("UTFDirective", new Param("value")), 
     1111        new Expression( 
     1112            new Terminal("utf",null), 
     1113            new Production("ws",null), 
     1114            new Terminal("(",null), 
     1115            new Production("ws",null), 
     1116            new Production("DirectiveArg",new Binding(false,"value")), 
     1117            new Production("ws",null), 
     1118            new Terminal(")",null), 
     1119            new Production("ws",null), 
     1120            new Terminal(";",null)           
     1121        ) 
     1122    ); 
    10691123     
    10701124    lines ~= new Rule("DirectiveArg", 
  • trunk/enki/enki.bnf

    r231 r235  
    1 .code{{{/+ 
    2     Copyright (c) 2006 Eric Anderton, BCS 
     1.boilerplate{{{/+ 
     2    Copyright (c) 2006 Eric Anderton 
    33 
    44    Permission is hereby granted, free of charge, to any person 
     
    4343.define("String","ws","false","Whitespace"); 
    4444 
     45.parsetype("String"); 
     46.utf("8"); 
     47 
    4548.baseclass("BaseEnkiParser"); 
    4649.classname("EnkiParser"); 
     
    215218Directive 
    216219    = Directive dir 
    217     ::=  "." ( ImportDirective:~dir | BaseClassDirective:~dir | ClassnameDirective:~dir | DefineDirective:~dir | IncludeDirective:~dir | AliasDirective:~dir | ModuleDirective:~dir | CodeDirective:~dir | TypelibDirective:~dir | ParseTypeDirective:~dir ) ; 
     220    ::=  "." ( ImportDirective:~dir | BaseClassDirective:~dir | ClassnameDirective:~dir | DefineDirective:~dir | IncludeDirective:~dir | AliasDirective:~dir | ModuleDirective:~dir | CodeDirective:~dir | TypelibDirective:~dir | ParseTypeDirective:~dir | BoilerplateDirective:~dir | HeaderDirective:~dir | UTFDirective:~dir ) ; 
    218221 
    219222ImportDirective 
     
    257260    ::=  "parsetype" ws "(" ws DirectiveArg:typeName  ws ")" ws ";"; 
    258261 
     262BoilerplateDirective 
     263    = new BoilerplateDirective(String code) 
     264    ::=  "boilerplate" ws "{{{" { any}:code "}}}"; 
     265 
     266HeaderDirective 
     267    = new HeaderDirective(String code) 
     268    ::=  "header" ws "{{{" { any}:code "}}}"; 
     269 
     270UTFDirective 
     271    = new UTFDirective(String value) 
     272    ::=  "utf" ws "(" ws DirectiveArg:value  ws ")" ws ";"; 
     273 
    259274DirectiveArg 
    260275    = String arg 
  • trunk/enki/enki.d

    r202 r235  
    3535 
    3636char[] helpText =  
    37 `Enki - Frontend Parser Generator - V1.0 Build %d 
     37`Enki - Frontend Parser Generator - V1.2 Build %d 
    3838Copyright(c) 2006 Eric Anderton 
    3939 
     
    4646  -f<file>  Specify output filename  
    4747  -b<file>  Specify output ebnf filename 
    48   -t        Test Mode 
     48  -t        Test Mode (output everything to console) 
    4949   
    5050The -b option is used primarily as a sanity check of 
  • trunk/enki/enki_bn.d

    r233 r235  
    22// This file is automatically maintained by the BUILD utility, 
    33// Please refrain from manually editing it. 
    4 long auto_build_number = 156
     4long auto_build_number = 177
  • trunk/enki/library/d/CharEntity.bnf

    r234 r235  
     1.boilerplate{{{/+ 
     2    Copyright (c) 2006 Eric Anderton 
     3 
     4    Permission is hereby granted, free of charge, to any person 
     5    obtaining a copy of this software and associated documentation 
     6    files (the "Software"), to deal in the Software without 
     7    restriction, including without limitation the rights to use, 
     8    copy, modify, merge, publish, distribute, sublicense, and/or 
     9    sell copies of the Software, and to permit persons to whom the 
     10    Software is furnished to do so, subject to the following 
     11    conditions: 
     12 
     13    The above copyright notice and this permission notice shall be 
     14    included in all copies or substantial portions of the Software. 
     15 
     16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     17