Changeset 2965


Ignore:
Timestamp:
2002-02-13T11:46:47+13:00 (22 years ago)
Author:
jrm21
Message:

Allow nested _If_ macros. We now count '(' and ')' characters, so you can now
do _If_(_foo_, _If_(_bar_,FOOBAR,FOONOBAR), _If_(_bar_,NOFOOBAR,NOFOONOBAR) )
inside a macro file. If you want to display a bracket, you can escape it.
Previously we had assumed that a ',' marked the end of a toplevel argument.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/lib/display.cpp

    r1860 r2965  
    2828/*
    2929   $Log$
     30   Revision 1.25  2002/02/12 22:46:47  jrm21
     31   Allow nested _If_ macros. We now count '(' and ')' characters, so you can now
     32   do _If_(_foo_, _If_(_bar_,FOOBAR,FOONOBAR), _If_(_bar_,NOFOOBAR,NOFOONOBAR) )
     33   inside a macro file. If you want to display a bracket, you can escape it.
     34   Previously we had assumed that a ',' marked the end of a toplevel argument.
     35
    3036   Revision 1.24  2001/01/25 18:26:44  cs025
    3137   Included CORBA branch for first time
     
    10691075  text_t::const_iterator ttend = inputtext.end();
    10701076  unsigned short c = '\0';
     1077  int openbrackets=0;
    10711078
    10721079  if (package.empty()) package = "Global";
    10731080
    10741081  outputtext.clear();
    1075      
    10761082  // use one-character lookahead
    10771083  if (tthere != ttend) c = (*tthere);
     
    11381144        {
    11391145          // found a macro!!!! (maybe)
    1140    
    11411146          c = my_ttnextchar (tthere, ttend); // skip the '_'
    11421147   
     
    11451150        {
    11461151          c = my_ttnextchar (tthere, ttend); // skip '('
    1147      
     1152          openbrackets++;
    11481153          // have to be careful of quotes
    11491154          unsigned short quote = '\0';
     
    11611166            {
    11621167              // not in a quote at the moment
    1163               if (c == ')')
     1168              if (c == '(')
    11641169                {
    1165                   // found end of the arguments
    1166                   c = my_ttnextchar (tthere, ttend); // skip ')'
    1167                   break;
    1168        
     1170                  openbrackets++;
     1171////                  macroargs.push_back (c);
     1172////                  c = my_ttnextchar (tthere, ttend);
     1173                }
     1174              else if (c == ')')
     1175                {
     1176                  openbrackets--;
     1177                  if (openbrackets==0) {
     1178                // found end of the arguments
     1179                c = my_ttnextchar (tthere, ttend); // skip ')'
     1180                break;
     1181                  } else {
     1182                // nested brackets
     1183                    macroargs.push_back (c);
     1184                    c = my_ttnextchar (tthere, ttend);
     1185                  }
    11691186                }
    11701187              else if (c == '\'' || c == '\"')
     
    11841201              if (tthere != ttend) macroargs.push_back (c);
    11851202              c = my_ttnextchar (tthere, ttend);
    1186             }
     1203            } // while (tthere != ttend)
    11871204        }
    11881205   
     
    12251242      c = my_ttnextchar (tthere, ttend);
    12261243    }
    1227     }
     1244    } // end of while (tthere != ttend)
    12281245}
    12291246
     
    13971414
    13981415  //  cerr << "r: " << recursiondepth << "\n";
    1399 
    14001416  // check for deep recursion
    14011417  if (recursiondepth >= MAXRECURSIONDEPTH)
     
    14151431    endit = macroparam.end();
    14161432    if (hereit != endit) c = (*hereit);
    1417 
     1433    int openbrackets=0; // keep track of bracket level eg _If_(1, _macro_(arg))
     1434            // this allows commas inside brackets (as arguments)
    14181435    while (hereit != endit) {
    14191436      // get the next parameter
     
    14351452      // found a quoted section
    14361453      quote = c;
    1437       //      aparam.push_back(c);
     1454      if (openbrackets>0) aparam.push_back(c);
    14381455
    14391456    } else if (quote!='\0' && c==quote) {
    14401457      // found the end of a quote
    14411458      quote = '\0';
    1442       //      aparam.push_back(c);
    1443 
    1444     } else if (quote=='\0' && c==',') {
     1459      if (openbrackets<0) aparam.push_back(c);
     1460
     1461    } else if (quote=='\0' && (c==',' || c==')') && openbrackets==0) {
    14451462      // found the end of a parameter
    14461463      c = my_ttnextchar (hereit, endit);
    14471464      break;
    14481465
     1466    } else if (c=='(') {
     1467      aparam.push_back(c);
     1468      openbrackets++;
     1469    } else if (c==')') {
     1470      openbrackets--;
     1471      aparam.push_back(c);
    14491472    } else {
    14501473      // ordinary character
     
    14541477    c = my_ttnextchar (hereit, endit);
    14551478      }
     1479
    14561480
    14571481      // add this parameter to the list
     
    14781502    // will always output something
    14791503    outputtext.clear();
    1480    
     1504
     1505
    14811506    // expand out the first parameter
    14821507    if (paramcond != paramend) {
    1483       text_t tmpoutput;
    1484       expandstring (macropackage, *paramcond, tmpoutput, recursiondepth+1);
    1485       lc (tmpoutput);
    1486      
     1508      /// text_t tmpoutput;
     1509      /// expandstring (macropackage, *paramcond, tmpoutput, recursiondepth+1);
     1510      /// lc (tmpoutput);
    14871511      // test the expanded string
    14881512      if (boolexpr (macropackage, *paramcond, recursiondepth+1)) {
     
    14911515    if (paramthen != paramend)
    14921516      expandstring (macropackage, *paramthen, outputtext, recursiondepth+1);
    1493 
    14941517      } else {
    14951518    // false
Note: See TracChangeset for help on using the changeset viewer.