"Fossies" - the Fresh Open Source Software Archive

Member "erltools/pub/chunkc/chunk.met" (5 Jun 2004, 7254 Bytes) of package /linux/misc/old/erltools-4.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 language chunk;
    2 
    3 global begin
    4   {{ extern int firstLine,lastLine,refLine,find_parenthesis,nb_parenthesis,comment_start,yErr,lexcommentCallLex,oldLastLine;}}
    5 end;
    6 
    7 use "cplus.met";
    8 
    9 lexdefine LexComment;
   10     
   11     /* dont skip \n for ifdef */
   12     if not in context keepCarriage and not in context keepAll
   13         or in context takeCarriageComment then
   14         begin
   15         skip '\t',' ','\r','\n';
   16         end
   17     else
   18         if not in context keepAll then
   19             begin
   20             skip '\t',' ';
   21             end
   22         else
   23             forgetl;
   24     case
   25         takel in ['/'] :
   26             
   27             /* definition of comment */
   28             case
   29                 seel in ['/'] :
   30                     begin
   31                     
   32                     /* take into account this comment only if not on
   33                       same line than the last } */
   34                     {{
   35                         if(!lexcommentCallLex && line > oldLastLine)
   36                                                      comment_start=line;
   37                     }};
   38                     begin_comment();
   39                     storel takel ;
   40                     while seel do
   41                         case
   42                             seel in ['\r','\n'] :
   43                                 begin
   44                                 store_comment_line();
   45   {{
   46     if (comment_start)
   47                                                lexcommentCallLex = 1;
   48   }}                            ;
   49                                 return take LexComment;
   50                                 end
   51                             default :
   52                                 begin
   53                                 storel takel ;
   54                                 end
   55                         end;
   56                     end
   57                 takel in ['*'] :
   58                     begin
   59                     {{ {int level = 0; }};
   60                     
   61                     /* take into account this comment only if not on
   62                       same line than the last } */
   63                     {{
   64                         if(!lexcommentCallLex && line > oldLastLine)
   65                                                      comment_start=line;
   66                     }};
   67                     begin_comment();
   68                     while seel do
   69                         case
   70                             takel "/*" :
   71                                 begin
   72                                 {{ level ++; }};
   73                                 storel "/*";
   74                                 end
   75                             takel "*/" :
   76                                 begin
   77                                 if {{!level }} then
   78                                     begin
   79                                     store_comment_line();
   80   {{
   81     if (comment_start)
   82                                                lexcommentCallLex = 1;
   83   }}                                ;
   84                                     return take LexComment;
   85                                     end
   86                                 else
   87                                     begin
   88                                     {{ level --;}};
   89                                     storel "*/";
   90                                     end;
   91                                 end
   92                             takel in ['\n'] : store_comment_line()
   93                             takel in ['\r'] : 
   94                             default :
   95                                 begin
   96                                 storel takel ;
   97                                 end
   98                         end;
   99                     {{} }};
  100                     end
  101                 default :
  102                     begin
  103                     recoverl;
  104                     end
  105             end
  106     end;
  107 end;
  108 
  109 define chunk_piece;
  110     declare retTree;
  111     {{
  112         if ( comment_start && comment_start < line)
  113                            firstLine=comment_start ; else firstLine = line ;
  114     }};
  115     without context takeCarriageComment do
  116         begin
  117         while seel and {{ ( !find_parenthesis || nb_parenthesis > 0) }} do
  118             begin
  119             if takel in ['\\'] then
  120                 ;
  121             case
  122                 take "(" :
  123                     begin
  124                     {{ find_parenthesis = 1; nb_parenthesis += 1;}};
  125                     end
  126                 take ")" :
  127                     begin
  128                     {{ nb_parenthesis -= 1;}};
  129                     end
  130                 see !CARRIAGE_RETURN :
  131                     begin
  132                     {{ comment_start = 0;}};
  133                     
  134                     /* don't take more than one CR here : wait until
  135                       we get out of the out of context takeCarriageComment */
  136                     take !CARRIAGE_RETURN;
  137                     
  138                     /* a little patch */
  139                     {{ takeCarriageComment=1;}};
  140                     if not find_parenthesis then
  141                         begin
  142                         {{ lexcommentCallLex=0;}};
  143                         return maketree(IDENT,());
  144                         end;
  145                     end
  146                 default :
  147                     begin
  148                     takel ;
  149                     forgetl;
  150                     end
  151             end;
  152             end;
  153         end;
  154     if not retTree = take quick_compound then
  155         begin
  156         {{ comment_start = 0;}};
  157         take !END_LINE;
  158         {{ lexcommentCallLex=0;}};
  159         return maketree(IDENT,());
  160         end
  161     else
  162         begin
  163         {{ FreeTree(retTree);_lastTree = (PTREE) 0;}};
  164         end;
  165     
  166     /* we have found what we are looking for so abort 
  167       and parse it again in a well behaved way */
  168     if {{
  169         line >= refLine
  170                      && (!comment_start || comment_start > refLine)
  171        }} then
  172         begin
  173         break;
  174         end;
  175     return maketree(IDENT,());
  176 end;
  177 
  178 define quick_compound;
  179     
  180     /* we suppose that we are in ansi c or c++ */
  181     while take !CARRIAGE_RETURN do
  182         ;
  183     take "{";
  184     {{ nb_parenthesis = 1;comment_start=0;}};
  185     while seel and {{ ( nb_parenthesis > 0) }} do
  186         begin
  187         if takel in ['\\'] then
  188             ;
  189         case
  190             take "{" :
  191                 begin
  192                 {{ nb_parenthesis += 1;}};
  193                 end
  194             take "}" :
  195                 begin
  196                 {{ oldLastLine = lastLine = line ; nb_parenthesis -= 1;}};
  197                 end
  198             default :
  199                 begin
  200                 takel ;
  201                 forgetl;
  202                 end
  203         end;
  204         end;
  205     {{ lexcommentCallLex=0;}};
  206     return maketree(IDENT,());
  207 end;
  208 
  209 define main_entry;
  210     return take find_func;
  211 end;
  212 
  213 define find_func;
  214     declare retTree;
  215     {{ comment_start=0;oldLastLine = -1;}};
  216     with context takeCarriageComment do
  217         with context keepCarriage do
  218             while seel and retTree = take chunk_piece do
  219                 begin
  220                 {{ FreeTree(retTree);_lastTree = (PTREE) 0;}};
  221                 {{ find_parenthesis = 0; nb_parenthesis=0;}};
  222                 end;
  223     
  224     /* enable errors */
  225     {{ yErr = 0;}};
  226     
  227     /* don't want to take comment at the begining of prog*/
  228     return maketree(TOP,take func_declaration);
  229 end;
  230 
  231 define nothing;
  232     declare node;
  233     return node;
  234 end.
  235