Changeset 96

Show
Ignore:
Timestamp:
03/19/06 16:15:13 (3 years ago)
Author:
krobillard
Message:

Implemented mold/only refinement.
Added save (as function).

Location:
trunk/orca
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/orca/boot.c

    r82 r96  
    7171  "mold: native [\n" 
    7272  "    value\n" 
     73  "    /only\n" 
    7374  "]\n" 
    7475  "not: native [value]\n" 
     
    517518  "    [insert tail series reduce :value]\n" 
    518519  "]\n" 
     520  "save: func [\n" 
     521  "    file [file!]\n" 
     522  "    data\n" 
     523  "] [\n" 
     524  "    write file mold/only data\n" 
     525  "]\n" 
    519526  "dirize: func [path [file! string!] /local end]\n" 
    520527  "[\n" 
  • trunk/orca/boot.r

    r82 r96  
    9898    mold: native [ 
    9999        value 
    100         ;/only "Omit outer braces of a block value" 
    101         ;/all  "Mold in serialized format" 
    102         ;/flat "Don't indent" 
     100        /only 
     101        ;/all 
     102        ;/flat 
    103103    ] 
    104104 
     
    695695    ] 
    696696 
     697    save: func [ 
     698        file [file!] 
     699        data 
     700    ][ 
     701        write file mold/only data 
     702    ] 
     703 
    697704    dirize: func [path [file! string!] /local end] 
    698705    [ 
  • trunk/orca/print.c

    r94 r96  
    2323#include "ovalue.h" 
    2424#include "internal.h" 
     25 
     26 
     27#define MOLD_NO_BRACES      1 
     28 
     29 
     30static void form( OString* out, const OValue* val, int depth ); 
     31static void mold( OString* out, const OValue* val, int depth, int flags ); 
     32 
    2533 
    2634 
     
    6068static void indent( OString* str, int depth ) 
    6169{ 
    62     while( depth-- ) 
     70    while( depth > 0 ) 
     71    { 
    6372        append(str,"    ",4); 
    64 } 
    65  
    66  
    67 static void form( OString* out, const OValue* val, int depth ); 
    68 static void mold( OString* out, const OValue* val, int depth ); 
     73        --depth; 
     74    } 
     75} 
    6976 
    7077 
     
    248255            else 
    249256                append1( ' ', out ); 
    250             mold( out, it + 1, 0 ); 
     257            mold( out, it + 1, 0, 0 ); 
    251258 
    252259            orListNextNode( blk, it ); 
     
    398405        // Mold gives us quotes around empty strings. 
    399406        // Need to check correct behavior of nested objects. 
    400         mold( out, it, depth ); 
     407        mold( out, it, depth, 0 ); 
    401408 
    402409        append1( '\n', out ); 
     
    429436            { 
    430437                append1( ' ', out ); 
    431                 mold( out, it, 0 ); 
     438                mold( out, it, 0, 0 ); 
    432439                ++it; 
    433440                if( it == end ) 
     
    674681 
    675682 
    676 static void mold( OString* out, const OValue* val, int depth ) 
     683static void mold( OString* out, const OValue* val, int depth, int mflags ) 
    677684{ 
    678685    /* 
     
    928935                if( vp != path->values ) 
    929936                    append1( '/', out ); 
    930                 mold( out, vp, 0 ); 
     937                mold( out, vp, 0, 0 ); 
    931938            } 
    932939            if( val->type == OT_SETPATH ) 
     
    947954            bval.index = val->func.specBlk; 
    948955            bval.series.it = 0; 
    949             mold( out, &bval, depth ); 
     956            mold( out, &bval, depth, 0 ); 
    950957        } 
    951958            break; 
     
    964971            { 
    965972                bval.series.n = val->func.specBlk; 
    966                 mold( out, &bval, depth ); 
     973                mold( out, &bval, depth, 0 ); 
    967974            } 
    968975            else 
     
    972979 
    973980            bval.index = val->func.bodyBlk; 
    974             mold( out, &bval, depth ); 
     981            mold( out, &bval, depth, 0 ); 
    975982        } 
    976983            break; 
     
    987994            //    append1( '\n', out ); 
    988995 
    989             append1( (val->type == OT_BLOCK) ? '[' : '(', out ); 
     996            if( ! (mflags & MOLD_NO_BRACES) ) 
     997            { 
     998                append1( (val->type == OT_BLOCK) ? '[' : '(', out ); 
     999                ++depth; 
     1000            } 
    9901001 
    9911002            if( vp != end ) 
    9921003            { 
    993                 ++depth; 
    9941004                for( ; vp != end; ++vp ) 
    9951005                { 
     
    10031013                        append1( ' ', out ); 
    10041014                    } 
    1005                     mold( out, vp, depth ); 
     1015                    mold( out, vp, depth, 0 ); 
    10061016                } 
     1017            } 
     1018 
     1019            if( ! (mflags & MOLD_NO_BRACES) ) 
     1020            { 
    10071021                --depth; 
    1008             } 
    1009  
    1010             if( val->flags & OR_FLAG_BEOL ) 
    1011             { 
    1012                 append1( '\n', out ); 
    1013                 indent(out, depth); 
    1014             } 
    1015  
    1016             append1( (val->type == OT_BLOCK) ? ']' : ')', out ); 
     1022                if( val->flags & OR_FLAG_BEOL ) 
     1023                { 
     1024                    append1( '\n', out ); 
     1025                    indent(out, depth); 
     1026                } 
     1027                append1( (val->type == OT_BLOCK) ? ']' : ')', out ); 
     1028            } 
    10171029        } 
    10181030            break; 
     
    10511063                    orAtomStr( orAtom(it), out ); 
    10521064                    append( out, ": ", 2 ); 
    1053                     mold( out, vit, depth + 1 ); 
     1065                    mold( out, vit, depth + 1, 0 ); 
    10541066                    append1( '\n', out ); 
    10551067                } 
     
    11101122void orMold( OString* out, const OValue* val ) 
    11111123{ 
    1112     mold( out, val, 0 ); 
     1124    mold( out, val, 0, 0 ); 
    11131125    if( out->used ) 
    11141126    { 
     
    11341146OR_NATIVE_PUB( orMoldNative ) 
    11351147{ 
     1148#define REF_MOLD_ONLY    a1+1 
    11361149    OString* str = orMakeString( 0 ); 
    1137     orMold( str, a1 ); 
     1150    mold( str, a1, 0, orRefineSet(REF_MOLD_ONLY) ? MOLD_NO_BRACES : 0 ); 
     1151    if( str->used ) 
     1152    { 
     1153        orTermCStr( str ); 
     1154    } 
    11381155    orResultSTRING( orStringN(str) ); 
    11391156}