Changeset 241

Show
Ignore:
Timestamp:
08/13/06 22:08:47 (2 years ago)
Author:
pragma
Message:

Fixes to the D Tokenizer.

Files:

Legend:

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

    r239 r241  
    5454    } 
    5555     
     56    //NOTE: oops. :( 
     57    alias initalize initialize; 
     58     
    5659    public void initalize(String input){ 
    5760        data = input; 
  • trunk/enki/library/d/Token.d

    r239 r241  
    3131private import enki.library.d.Operator; 
    3232 
     33//TODO: get rid of std.string and std.utf 
     34private import std.string; // used for conversion 
     35private import std.utf; // used for conversion 
    3336alias ulong IntegerValue; //TODO: turn into a more advanced type 
    3437 
     
    4750        _this.exponentSign = exponentSign; 
    4851        return _this; 
     52    } 
     53     
     54    public String render(){ 
     55        char[] sign = exponentSign ? "+" : "-"; 
     56        char[] img = imaginary ? "i" : ""; 
     57         
     58        return toUTF32(std.string.toString(whole) ~ "." ~   std.string.toString(fraction) ~ sign ~ "e" ~ img); 
    4959    } 
    5060} 
     
    252262        Special, 
    253263        LineDirective, 
    254     }   
     264    } 
    255265     
    256266    union ValueUnion{ 
     
    293303    public static Token comment(String id){ 
    294304        Token _this; 
    295         _this.type = Operator
     305        _this.type = Comment
    296306        _this.value.strValue = id; 
    297307        return _this; 
     
    343353        return _this; 
    344354    } 
    345      
     355        
    346356    String render(){ 
    347         if(type == Token.Identifier){ 
     357        switch(type){ 
     358        case Identifier: 
    348359            return value.strValue; 
     360        case Keyword: 
     361            return keywordXref[value.token]; 
     362        case Operator: 
     363            return operatorXref[value.token]; 
     364        case Comment: 
     365        case StringLiteral: 
     366        case CharLiteral: 
     367            return value.strValue;       
     368            return value.strValue; 
     369        case FloatingPoint: 
     370            return value.floatingValue.render(); 
     371        case Integer: 
     372            return toUTF32(std.string.toString(value.integerValue)); 
     373        case Special: 
     374            //TODO: fix me 
     375            return value.strValue; 
     376        case LineDirective: 
     377        default: 
     378            return ""; 
    349379        } 
    350         else if(type == Token.Keyword){ 
    351             return keywordXref[value.token]; 
    352         } 
    353         else if(type == Token.Operator){ 
    354             return operatorXref[value.token]; 
    355         } 
    356         return ""; 
    357     } 
    358 
     380    } 
     381
  • trunk/enki/library/d/Tokenizer.bnf

    r240 r241  
    4242.classname(Tokenizer); 
    4343 
     44.define("String","any","true","any"); 
    4445.define(bool,eoi,false,"End of Input"); 
    4546.define("String","letter","true","letter"); 
     
    6869 
    6970Space 
    70     = Token tok 
    71     ::= #20 | #09 | #0B | #0C | EndOfLine | Comment:tok; 
    72      
     71    ::= #20 | #09 | #0B | #0C | EndOfLine; 
     72         
    7373Comment 
    7474    = Token Token.comment(String comment) 
    75     ::= ("\x2F\x2A" {Character}:comment "\x2A\x2F") |  
    76         ("\x2F\x2F" {Character}:comment EndOfLine) |  
     75    ::= ("\x2F\x2A" {any}:comment "\x2A\x2F") |  
     76        ("\x2F\x2F" {any}:comment EndOfLine) |  
    7777        ("\x2F\x2B" SlashPlusContent:comment); 
    7878 
    7979SlashPlusContent 
    8080    = String comment 
    81     ::= {Character}:comment ("\x2B\x2F" | ("\x2F\x2B" SlashPlusContent:~comment)); 
     81    ::= {any}:comment ("\x2B\x2F" | ("\x2F\x2B" SlashPlusContent:~comment)); 
    8282     
    8383##### Tokens ##### 
     
    8686    = Token[] tokens 
    8787    ::= { 
    88         Space:~tokens |  
     88        Space |  
     89        Comment:~tokens | 
    8990        StringLiteral:~tokens |  
     91        SpecialToken:~tokens |  
     92        SpecialTokenSequence:~tokens |       
     93        Identifier:~tokens | 
    9094        CharacterLiteral:~tokens |  
    91         IntegerLiteral:~tokens |  
     95        Keyword:~tokens | 
     96        Operator:~tokens | 
    9297        FloatLiteral:~tokens |  
    93         Keyword:~tokens |  
    94         Operator:~tokens | 
    95         SpecialToken:~tokens |  
    96         SpecialTokenSequence:~tokens 
     98        IntegerLiteral:~tokens               
    9799    } RealEndOfFile;     
    98100 
     
    141143 
    142144DoubleQuotedCharacter 
    143     ::= Character | EscapeSequence | EndOfLine
     145    ::= EscapeSequence | EndOfLine | any
    144146 
    145147EscapeSequence 
     
    149151        "\"":value | 
    150152        "?":value | 
    151         "\\" EndOfFile | 
    152         "\\":value | 
     153        "\x5C" EndOfFile | 
     154        "\x5C":value | 
    153155        "a" #07:value | 
    154156        "b" #08:value | 
     
    260262     
    261263NonZeroDigit 
    262     ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; 
     264    = String value 
     265    ::= ("1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"):value; 
    263266     
    264267DecimalDigit 
    265     ::= "0" | NonZeroDigit; 
     268    = String value 
     269    ::= ("0" | NonZeroDigit):value; 
    266270 
    267271BinaryDigit 
    268     ::= "0" | "1"; 
     272    = String value 
     273    ::= ("0" | "1"):value; 
    269274 
    270275OctalDigit 
    271     ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"; 
     276    = String value 
     277    ::= ("0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"):value; 
    272278 
    273279HexDigit 
    274     ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" |  
     280    = String value 
     281    ::= ("0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" |  
    275282        "a" | "b" | "c" | "d" | "e" | "f" |  
    276         "A" | "B" | "C" | "D" | "E" | "F"
     283        "A" | "B" | "C" | "D" | "E" | "F"):value
    277284 
    278285                 
  • trunk/enki/library/d/TokenizerBase.d

    r239 r241  
    8686        return result; 
    8787    } 
     88    import std.stdio; 
    8889     
    8990    IntegerValue convertToDecimal(String value){ 
    9091        IntegerValue result = 0; 
    91          
     92                
    9293        foreach(ch; value){ 
    9394            result = (result * 10) + (ch - '0');