Changeset 86f384b


Ignore:
Timestamp:
Jul 2, 2017, 10:49:41 AM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
307a732
Parents:
d395012
Message:

make tuple separator a separator rather than terminator

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rd395012 r86f384b  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sat Jul  1 17:19:42 2017
    14 %% Update Count     : 2495
     13%% Last Modified On : Sun Jul  2 09:49:56 2017
     14%% Update Count     : 2503
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    24332433
    24342434The goal of \CFA I/O is to simplify the common cases\index{I/O!common case}, while fully supporting polymorphism and user defined types in a consistent way.
     2435The approach combines ideas from \CC and Python.
    24352436The \CFA header file for the I/O library is \Indexc{fstream}.
    24362437
     
    24582459\end{tabular}
    24592460\end{quote2}
    2460 The \CFA form has half as many characters as the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators.
    2461 Similar simplification occurs for \Index{tuple} I/O, which prints all a tuple's values, each separated by ``\lstinline[showspaces=true]@, @''.
     2461The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators.
     2462Similar simplification occurs for \Index{tuple} I/O, which prints all tuple values separated by ``\lstinline[showspaces=true]@, @''.
    24622463\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    2463 [int, int] t1 = [1, 2], t2 = [3, 4];
     2464[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ];
    24642465sout | t1 | t2 | endl;                                  §\C{// print tuples}§
    24652466\end{cfa}
    24662467\begin{cfa}[mathescape=off,showspaces=true,belowskip=0pt]
    2467 1®, ®2®, ®3®, ®4
    2468 \end{cfa}
    2469 Finally, \CFA uses the logical-or operator for I/O because it is the lowest-priority overloadable operator, other than assignment.
     24681®, ®2®, ®3 3®, ®4®, ®5
     2469\end{cfa}
     2470Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority overloadable operator, other than assignment.
    24702471Therefore, fewer output expressions require parenthesis.
    24712472\begin{quote2}
     
    26602661        int x = 1, y = 2, z = 3;
    26612662        sout | x | y | z | endl;
    2662         [int, int] t1 = [1, 2], t2 = [3, 4];
    2663         sout | t1 | t2 | endl;                                          // print tuple
     2663        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ];
     2664        sout | t1 | t2 | endl;                                          // print tuples
    26642665        sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
    26652666        sout | 1 | 2 | 3 | endl;
  • src/libcfa/iostream

    rd395012 r86f384b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul  1 16:37:52 2017
    13 // Update Count     : 108
     12// Last Modified On : Sun Jul  2 08:42:56 2017
     13// Update Count     : 110
    1414//
    1515
     
    2626        const char * sepGetCur( ostype * );                                     // get current separator string
    2727        void sepSetCur( ostype *, const char * );                       // set current separator string
     28        _Bool lastSepOn( ostype * );                                            // last manipulator is setOn (context sensitive)
    2829        // public
    2930        void sepOn( ostype * );                                                         // turn separator state on
     
    3132        _Bool sepDisable( ostype * );                                           // set default state to off, and return previous state
    3233        _Bool sepEnable( ostype * );                                            // set default state to on, and return previous state
    33         _Bool lastSepOn( ostype * );                                            // last manipulator is setOn (context sensitive)
    3434
    3535        const char * sepGet( ostype * );                                        // get separator string
     
    4444        ostype * write( ostype *, const char *, unsigned long int );
    4545        int fmt( ostype *, const char fmt[], ... );
    46 };
     46}; // ostream
    4747
    4848trait writeable( otype T ) {
    4949        forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
    50 };
     50}; // writeable
    5151
    5252// implement writable for intrinsic types
     
    104104        istype * ungetc( istype *, char );
    105105        int fmt( istype *, const char fmt[], ... );
    106 };
     106}; // istream
    107107
    108108trait readable( otype T ) {
    109109        forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T );
    110 };
     110}; // readable
    111111
    112112forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, char * );
  • src/libcfa/iostream.c

    rd395012 r86f384b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul  1 16:37:51 2017
    13 // Update Count     : 374
     12// Last Modified On : Sun Jul  2 08:54:02 2017
     13// Update Count     : 375
    1414//
    1515
     
    201201forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } )
    202202ostype * ?|?( ostype * os, T arg, Params rest ) {
     203        os | arg;                                                                                       // print first argument
    203204        sepSetCur( os, sepGetTuple( os ) );                                     // switch to tuple separator
    204         os | arg;                                                                                       // print first argument
    205205        os | rest;                                                                                      // print remaining arguments
    206206        sepSetCur( os, sepGet( os ) );                                          // switch to regular separator
  • src/tests/.expect/io.txt

    rd395012 r86f384b  
    44123
    55
     6opening delimiters
    67x (1 x [2 x {3 x =4 x $5 x £6 x ¥7 x ¡8 x ¿9 x «10
     8
     9closing delimiters
    7101, x 2. x 3; x 4! x 5? x 6% x 7¢ x 8» x 9) x 10] x 11} x
     11
     12opening/closing delimiters
    813x`1`x'2'x"3"x:4:x 5 x   6       x
    9147
     
    152010
    1621x
     22
     23override opening/closing delimiters
    1724x ( 1 ) x 2 , x 3 :x: 4
     25
     26input bacis types
     27
     28output basic types
    1829A
    19301 2 3 4 5 6 7 8
     
    21321.1+2.3i 1.1-2.3i 1.1-2.3i
    2233
     34tuples
     351, 2, 3 3, 4, 5
     36
     37toggle separator
    23381.11.21.3
    24391.1+2.3i1.1-2.3i1.1-2.3i
     
    2641abcxyz
    2742
     43change separator
     44from "  "to " , $"
    28451.1, $1.2, $1.3
    29461.1+2.3i, $1.1-2.3i, $1.1-2.3i
    3047abc, $xyz, $
     481, 2, 3, $3, 4, 5
    3149
    32 1, 2, 3, 4
    33 
    34 1, $2, $3 ", $"
    35 1 2 3 " "
     50from ", $"to " "
     511.1 1.2 1.3
     521.1+2.3i 1.1-2.3i 1.1-2.3i
     53abc xyz
     541, 2, 3 3, 4, 5
    3655
    3756 1 2 3
     
    49681 2 3
    5069
    51 1 2 3 4 " "
    52 1, 2, 3, 4 ", "
    53 1, 2, 3, 4
     701 2 3 3 4 5 " "
     711, 2, 3 3, 4, 5 ", "
     721, 2, 3 3, 4, 5
    5473
    55743, 4, a, 7.2
     
    57763 4 a 7.2
    5877 3 4 a 7.234a7.23 4 a 7.2
    59 3-4-a-7.2^3^4-3-4-a-7.2
     783-4-a-7.2^3^4^3-4-a-7.2
  • src/tests/io.c

    rd395012 r86f384b  
    1010// Created On       : Wed Mar  2 16:56:02 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul  1 16:21:07 2017
    13 // Update Count     : 58
     12// Last Modified On : Sun Jul  2 09:40:58 2017
     13// Update Count     : 68
    1414//
    1515
     
    4242        sout | endl;
    4343
     44        sout | "opening delimiters" | endl;
    4445        sout
    45                 // opening delimiters
    4646                | "x (" | 1
    4747                | "x [" | 2
     
    5454                | "x ¿" | 9
    5555                | "x «" | 10
    56                 | endl;
     56                | endl | endl;
     57
     58        sout | "closing delimiters" | endl;
    5759        sout
    58                 // closing delimiters
    5960                | 1 | ", x"
    6061                | 2 | ". x"
     
    6869                | 10 | "] x"
    6970                | 11 | "} x"
    70                 | endl;
     71                | endl | endl;
     72
     73        sout | "opening/closing delimiters" | endl;
    7174        sout
    72                 // opening-closing delimiters
    7375                | "x`" | 1 | "`x'" | 2
    7476                | "'x\"" | 3 | "\"x:" | 4
     
    7678                | "\tx\f" | 7 | "\fx\v" | 8
    7779                | "\vx\n" | 9 | "\nx\r" | 10
    78                 | "\rx" |
    79                 endl;
     80                | "\rx"
     81                | endl | endl;
     82
     83        sout | "override opening/closing delimiters" | endl;
    8084        sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl;
     85        sout | endl;
    8186
    8287        ifstream in;                                                                            // create / open file
    8388        open( &in, "io.data", "r" );
    8489
     90        sout | "input bacis types" | endl;
    8591        &in | &c                                                                                        // character
    8692                | &si | &usi | &i | &ui | &li | &uli | &lli | &ulli     // integral
     
    8894                | &fc | &dc | &ldc                                                              // floating-point complex
    8995                | cstr( s1 ) | cstr( s2, size );                                // C string, length unchecked and checked
     96        sout | endl;
    9097
     98        sout | "output basic types" | endl;
    9199        sout | c | ' ' | endl                                                           // character
    92100                | si | usi | i | ui | li | uli | lli | ulli | endl // integral
     
    94102                | fc | dc | ldc | endl;                                                 // complex
    95103        sout | endl;
     104
     105        sout | "tuples" | endl;
     106        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ];
     107        sout | t1 | t2 | endl;                                                          // print tuple
     108        sout | endl;
     109
     110        sout | "toggle separator" | endl;
    96111        sout | f | "" | d | "" | ld | endl                                      // floating point without separator
    97112                | sepDisable | fc | dc | ldc | sepEnable | endl // complex without separator
     
    100115        sout | endl;
    101116
     117        sout | "change separator" | endl;
     118        sout | "from \" " | sepGet( sout ) | "\"";
    102119        sepSet( sout, ", $" );                                                          // change separator, maximum of 15 characters
     120        sout | "to \" " | sepGet( sout ) | "\"" | endl;
    103121        sout | f | d | ld | endl
    104122                | fc | dc | ldc | endl
    105                 | s1 | s2 | endl;
     123                | s1 | s2 | endl
     124                | t1 | t2 | endl;                                                               // print tuple
    106125        sout | endl;
    107 
    108         [int, int] t1 = [1, 2], t2 = [3, 4];
    109         sout | t1 | t2 | endl;                                                          // print tuple
    110         sout | endl;
    111 
    112         sepSet( sout, " " );
    113         sepSet( sout, ", $" );                                                          // set separator from " " to ", $"
    114         sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
    115         sepSet( sout, " " );                                                            // reset separator to " "
    116         sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
     126        sout | "from \"" | sepGet( sout ) | "\"";
     127        sepSet( sout, " " );                                                            // restore separator
     128        sout | "to \"" | sepGet( sout ) | "\"" | endl;
     129        sout | f | d | ld | endl
     130                | fc | dc | ldc | endl
     131                | s1 | s2 | endl
     132                | t1 | t2 | endl;                                                               // print tuple
    117133        sout | endl;
    118134
Note: See TracChangeset for help on using the changeset viewer.