Changeset 1:18491334a525

Show
Ignore:
Timestamp:
10/30/07 13:08:12 (1 year ago)
Author:
Diggory Hardy <diggory.hardy@gmail.com>
branch:
default
convert_revision:
6bd8a8414774c0420a72ec435bd61db7a866994d
Message:

Finished format.d and parse.d modules; moved to mde/text. Partway implementing mde.mergetag.write.TextWriter?.

committer: Diggory Hardy <diggory.hardy@gmail.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mde/init.d

    r0 r1  
    44 * This module controls most of the initialisation and deinitialisation of the program. 
    55 *************************************************************************************************/ 
     6module mde.init; 
    67 
    78// tango imports 
  • mde/mergetag/dataset.d

    r0 r1  
    2222    static const char[2] CurrentString = "01"; 
    2323     
    24     static VERS parseString (char[] str) { 
    25         in { 
     24    static VERS parseString (char[] str) 
     25    in { 
    2626            assert (str.length == 2); 
    27         } body { 
    28             if (str[0] == '0' && str[1] == '1') return VERS.MT01; 
    29             else return VERS.INVALID; 
    30         } 
     27    } body { 
     28        if (str[0] == '0' && str[1] == '1') return VERS.MT01; 
     29        else return VERS.INVALID; 
    3130    } 
    3231} 
     
    103102class DefaultData : DataSection 
    104103{ 
    105     /+ Could use this: 
    106     private template addTagTp(alias Var, T) (ID id, char[] dt) { 
    107         Var[id] = parse!(T) (dt); 
    108     } +/ 
    109     // Unfortunately, I think each case needs to be mentioned explicitly to tie it to the correct 
    110     // data member. 
    111     void addTag (char[] tp, ID id, char[] dt) { /// for adding tags 
    112         try { 
    113         switch(Util.trim(tp)) { 
    114             case "1": 
    115             case "bool": 
    116                 Bool[id] = parse!(bool) (dt); 
    117             break; 
    118             case "s8": 
    119             case "byte": 
    120                 Byte[id] = parse!(byte) (dt); 
    121             break; 
    122             case "s16": 
    123             case "short": 
    124                 Short[id] = parse!(short) (dt); 
    125             break; 
    126             case "s32": 
    127             case "int": 
    128                 Int[id] = parse!(int) (dt); 
    129             break; 
    130             case "s64": 
    131             case "long": 
    132                 Long[id] = parse!(long) (dt); 
    133             break; 
    134             case "u8": 
    135             case "ubyte": 
    136                 UByte[id] = parse!(ubyte) (dt); 
    137             break; 
    138             case "u16": 
    139             case "ushort": 
    140                 UShort[id] = parse!(ushort) (dt); 
    141             break; 
    142             case "u32": 
    143             case "uint": 
    144                 UInt[id] = parse!(uint) (dt); 
    145             break; 
    146             case "u64": 
    147             case "ulong": 
    148                 ULong[id] = parse!(ulong) (dt); 
    149             break; 
    150              
    151             case "1[]": 
    152             case "bool[]": 
    153                 BoolA[id] = parse!(bool[]) (dt); 
    154             break; 
    155             case "s8[]": 
    156             case "byte[]": 
    157                 ByteA[id] = parse!(byte[]) (dt); 
    158             break; 
    159             case "s16[]": 
    160             case "short[]": 
    161                 ShortA[id] = parse!(short[]) (dt); 
    162             break; 
    163             case "s32[]": 
    164             case "int[]": 
    165                 IntA[id] = parse!(int[]) (dt); 
    166             break; 
    167             case "s64[]": 
    168             case "long[]": 
    169                 LongA[id] = parse!(long[]) (dt); 
    170             break; 
    171             case "u8[]": 
    172             case "ubyte[]": 
    173             case "binary": 
    174                 UByteA[id] = parse!(ubyte[]) (dt); 
    175             break; 
    176             case "u16[]": 
    177             case "ushort[]": 
    178                 UShortA[id] = parse!(ushort[]) (dt); 
    179             break; 
    180             case "u32[]": 
    181             case "uint[]": 
    182                 UIntA[id] = parse!(uint[]) (dt); 
    183             break; 
    184             case "u64[]": 
    185             case "ulong[]": 
    186                 ULongA[id] = parse!(ulong[]) (dt); 
    187             break; 
    188              
    189             case "fp32": 
    190             case "float": 
    191                 Float[id] = parse!(float) (dt); 
    192             break; 
    193             case "fp64": 
    194             case "double": 
    195                 Double[id] = parse!(double) (dt); 
    196             break; 
    197             case "fp": 
    198             case "real": 
    199                 Real[id] = parse!(real) (dt); 
    200             break; 
    201             case "fp32[]": 
    202             case "float[]": 
    203                 FloatA[id] = parse!(float[]) (dt); 
    204             break; 
    205             case "fp64[]": 
    206             case "double[]": 
    207                 DoubleA[id] = parse!(double[]) (dt); 
    208             break; 
    209             case "fp[]": 
    210             case "real[]": 
    211                 RealA[id] = parse!(real[]) (dt); 
    212             break; 
    213              
    214             case "UTF8": 
    215             case "char": 
    216                 Char[id] = parse!(char) (dt); 
    217             break; 
    218             case "UTF8[]": 
    219             case "char[]": 
    220             case "string": 
    221                 CharA[id] = parse!(char[]) (dt); 
    222             break; 
    223              
    224             default: 
    225                 logger.warn ("Type not supported: " ~ tp); 
    226                 throw new MTUnknownTypeException (); 
    227         } 
    228         } catch (Exception e) { 
    229             // an error should have already been logged 
    230         } 
    231     } 
    232      
    233      
    234      
     104    //BEGIN DATA 
    235105    /** Data members for direct access. */ 
    236106    bool    [ID]    Bool; 
     
    267137    alias   CharA   String; 
    268138    alias   UByteA  Binary; /// ditto 
    269 
     139    //END DATA 
     140     
     141    /+ Could use this: 
     142    private template addTagTp(alias Var, T) (ID id, char[] dt) { 
     143        Var[id] = parse!(T) (dt); 
     144    } 
     145    or a mixin. 
     146    +/ 
     147    // Unfortunately, I think each case needs to be mentioned explicitly to tie it to the correct 
     148    // data member. 
     149    void addTag (char[] tp, ID id, char[] dt) { /// for adding tags 
     150        try { 
     151            postTrim (tp); 
     152            // parse tp, then use if statements to replace the following switch 
     153             
     154        switch(Util.trim(tp)) { 
     155            case "1": 
     156            case "bool": 
     157                Arg!(bool)[id] = parse!(bool) (dt); 
     158            break; 
     159            case "s8": 
     160            case "byte": 
     161                addTagTp!(byte) (id, dt); 
     162            break; 
     163            case "s16": 
     164            case "short": 
     165                Short[id] = parse!(short) (dt); 
     166            break; 
     167            case "s32": 
     168            case "int": 
     169                Arg!(int)[id] = parse!(int) (dt); 
     170            break; 
     171            case "s64": 
     172            case "long": 
     173                Long[id] = parse!(long) (dt); 
     174            break; 
     175            case "u8": 
     176            case "ubyte": 
     177                UByte[id] = parse!(ubyte) (dt); 
     178            break; 
     179            case "u16": 
     180            case "ushort": 
     181                UShort[id] = parse!(ushort) (dt); 
     182            break; 
     183            case "u32": 
     184            case "uint": 
     185                UInt[id] = parse!(uint) (dt); 
     186            break; 
     187            case "u64": 
     188            case "ulong": 
     189                ULong[id] = parse!(ulong) (dt); 
     190            break; 
     191             
     192            case "1[]": 
     193            case "bool[]": 
     194                BoolA[id] = parse!(bool[]) (dt); 
     195            break; 
     196            case "s8[]": 
     197            case "byte[]": 
     198                ByteA[id] = parse!(byte[]) (dt); 
     199            break; 
     200            case "s16[]": 
     201            case "short[]": 
     202                ShortA[id] = parse!(short[]) (dt); 
     203            break; 
     204            case "s32[]": 
     205            case "int[]": 
     206                IntA[id] = parse!(int[]) (dt); 
     207            break; 
     208            case "s64[]": 
     209            case "long[]": 
     210                LongA[id] = parse!(long[]) (dt); 
     211            break; 
     212            case "u8[]": 
     213            case "ubyte[]": 
     214            case "binary": 
     215                UByteA[id] = parse!(ubyte[]) (dt); 
     216            break; 
     217            case "u16[]": 
     218            case "ushort[]": 
     219                UShortA[id] = parse!(ushort[]) (dt); 
     220            break; 
     221            case "u32[]": 
     222            case "uint[]": 
     223                UIntA[id] = parse!(uint[]) (dt); 
     224            break; 
     225            case "u64[]": 
     226            case "ulong[]": 
     227                ULongA[id] = parse!(ulong[]) (dt); 
     228            break; 
     229             
     230            case "fp32": 
     231            case "float": 
     232                Float[id] = parse!(float) (dt); 
     233            break; 
     234            case "fp64": 
     235            case "double": 
     236                Double[id] = parse!(double) (dt); 
     237            break; 
     238            case "fp": 
     239            case "real": 
     240                Real[id] = parse!(real) (dt); 
     241            break; 
     242            case "fp32[]": 
     243            case "float[]": 
     244                FloatA[id] = parse!(float[]) (dt); 
     245            break; 
     246            case "fp64[]": 
     247            case "double[]": 
     248                DoubleA[id] = parse!(double[]) (dt); 
     249            break; 
     250            case "fp[]": 
     251            case "real[]": 
     252                RealA[id] = parse!(real[]) (dt); 
     253            break; 
     254             
     255            case "UTF8": 
     256            case "char": 
     257                Char[id] = parse!(char) (dt); 
     258            break; 
     259            case "UTF8[]": 
     260            case "char[]": 
     261            case "string": 
     262                CharA[id] = parse!(char[]) (dt); 
     263            break; 
     264             
     265            default: 
     266                logger.warn ("Type not supported: " ~ tp); 
     267                throw new MTUnknownTypeException (); 
     268        } 
     269        } catch (Exception e) { 
     270            // an error should have already been logged 
     271        } 
     272    } 
     273     
     274private: 
     275    void addTagTp(T) (ID id, char[] dt) { 
     276        Arg!(T)[id] = parse!(T) (dt); 
     277    } 
     278     
     279    // use as: mixin Arg!(type); or Arg!(type) 
     280    template Arg(T : bool) { 
     281        alias Bool Arg; 
     282    } 
     283    template Arg(T : byte) { 
     284        alias Byte Arg; 
     285    } 
     286    template Arg(T : short) { 
     287        alias Short Arg; 
     288    } 
     289    template Arg(T : int) { 
     290        alias Int Arg; 
     291    } 
     292    template Arg(T : long) { 
     293        alias Long Arg; 
     294    } 
     295    template Arg(T : ubyte) { 
     296        alias UByte Arg; 
     297    } 
     298    template Arg(T : ushort) { 
     299        alias UShort Arg; 
     300    } 
     301    template Arg(T : uint) { 
     302        alias UInt Arg; 
     303    } 
     304    template Arg(T : ulong) { 
     305        alias ULong Arg; 
     306    } 
     307    template Arg(T : bool[]) { 
     308        alias BoolA Arg; 
     309    } 
     310    template Arg(T : byte[]) { 
     311        alias ByteA Arg; 
     312    } 
     313    template Arg(T : short[]) { 
     314        alias ShortA Arg; 
     315    } 
     316    template Arg(T : int[]) { 
     317        alias IntA Arg; 
     318    } 
     319    template Arg(T : long[]) { 
     320        alias LongA Arg; 
     321    } 
     322    template Arg(T : ubyte[]) { 
     323        alias UByteA Arg; 
     324    } 
     325    template Arg(T : ushort[]) { 
     326        alias UShortA Arg; 
     327    } 
     328    template Arg(T : uint[]) { 
     329        alias UIntA Arg; 
     330    } 
     331    template Arg(T : ulong[]) { 
     332        alias ULongA Arg; 
     333    } 
     334    template Arg(T : float) { 
     335        alias Float Arg; 
     336    } 
     337    template Arg(T : double) { 
     338        alias Double Arg; 
     339    } 
     340    template Arg(T : real) { 
     341        alias Real Arg; 
     342    } 
     343    template Arg(T : float[]) { 
     344        alias FloatA Arg; 
     345    } 
     346    template Arg(T : double[]) { 
     347        alias DoubleA Arg; 
     348    } 
     349    template Arg(T : real[]) { 
     350        alias RealA Arg; 
     351    } 
     352    template Arg(T : char) { 
     353        alias Char Arg; 
     354    } 
     355    template Arg(T : char[]) { 
     356        alias CharA Arg; 
     357    } 
     358
     359 
     360/+ 
     361class TemplateData : DataSection 
     362
     363    void addTag (char[] tp, ID id, char[] dt) { 
     364        // runtime deduction of tp and aliasing? 
     365        // CANNOT add data at runtime though. 
     366    } 
     367    // will this work? no idea. 
     368    // templates can't be used to add non-static elements, so use a static array at index: this 
     369    template Data(T,TemplateData* p) { 
     370        static T[ID][TemplateData*] Data; 
     371    } 
     372
     373+/ 
  • mde/mergetag/doc/issues.txt

    r0 r1  
    1515parse.d: 
    1616    No support for escaped quotes in strings during tokenisation (by tango.text.Util.quotes). 
    17      
     17    Doesn't support cent/ucent. 
     18 
     19format.d: 
     20    No support for cent/ucent or ulong where val > long.max. 
  • mde/mergetag/exception.d

    r0 r1  
    3434} 
    3535 
    36 /** Thrown by the parse module on any error. 
    37  */ 
    38 class MTParseException : MTException { 
    39     this () {} 
    40 } 
    41  
    4236/** Thrown by classes implementing DataSection when addTag is called with an unrecognised type string. 
    4337 */ 
  • mde/mergetag/read.d

    r0 r1  
    8282     
    8383    final char[] fbuf;          // file is read into this 
    84     MT_VERS fileVer = MT_VERS.INVALID;    // Remains INVALID until set otherwise by CTOR. 
     84    MTFormatVersion.VERS fileVer = MTFormatVersion.VERS.INVALID;  // Remains INVALID until set otherwise by CTOR. 
    8585     
    8686    uint endOfHeader; 
  • mde/mergetag/write.d

    r0 r1  
    5353 */ 
    5454IWriter makeWriter (char[] path, DataSet dataset, WriterMethod method = WriterMethod.Unspecified) { 
    55     makeWriter (new FilePath (path), dataset, method); 
     55    return makeWriter (new FilePath (path), dataset, method); 
    5656} 
    5757/** ditto */ 
    5858IWriter makeWriter (PathView path, DataSet dataset, WriterMethod method = WriterMethod.Unspecified) { 
     59    void throwMTErr (char[] msg, Exception exc = new MTException) { 
     60        logger.error (msg); 
     61        throw exc; 
     62    } 
     63     
    5964    if (method == WriterMethod.Unspecified) { 
    6065        if (path.ext == "mtt") method = WriterMethod.Text; 
     
    6873 
    6974/// Interface for methods and data necessarily available in TextWriter and/or BinaryWriter. 
    70 scope interface IWriter { 
    71     char[][ID] indexTable; // only used by TextWriter, but available in both 
    72      
    73     this (char[] path, DataSet dataset_); 
    74     this (PathView path, DataSet dataset_); 
    75     ~this (); 
    76      
    77     void write (); 
     75interface IWriter { 
     76    /** Only used in a TextWriter; see TextWriter.indexTable(). 
     77    * 
     78    * Note that other implementors implement this as a blank function and will not throw an error. 
     79    */ 
     80    void indexTable (char[][ID]); 
     81     
     82    void write ();         /// Writing method. 
    7883} 
    7984 
     
    102107    * string is written instead. 
    103108    */ 
    104     char[][ID] indexTable;  // see setIndexLookupTable() doc for use. 
     109    void indexTable (char[][ID] iT) { 
     110        _indexTable = iT; 
     111    } 
    105112     
    106113private: 
     
    115122    bool writtenHeader = false; // The header MUST be written exactly once at the beginning of the file. 
    116123     
     124    char[][ID] _indexTable; // see indexTable() doc for use. 
     125         
    117126    FileConduit conduit;    // actual conduit; don't use directly when there's content in the buffer 
    118127    IBuffer buffer;     // write strings directly to this (use opCall(void[]) ) 
     
    180189    private void writeSectionIdentifier (ID id) { 
    181190        buffer ("{"); 
    182         char[]* p = id in indexTable; // look for a string ID 
     191        char[]* p = id in _indexTable;    // look for a string ID 
    183192        if (p) buffer ("\"")(*p)("\""); // write a string ID 
    184193        else format (cast(uint) id);    // write a numeric ID 
     
    187196     
    188197    private void writeSection (DataSection sec) { 
    189          
    190         buffer (Eol);           // blank line at end of file 
     198        //FIXME 
     199         
     200        buffer (Eol);           // blank line at end of each section 
    191201    } 
    192202     
  • test.mtt

    r0 r1  
    55<int|5=5> 
    66<int[]|5=[5, 4 , -3,-2 ,1]> 
    7 <ubyte|7=0> 
     7<byte|7=0> 
    88<ubyte|0=255> 
    99<byte[]|5= [ 2 , -1 , -127, 127, -127,127,0 ] >