bug-global
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] add support of multi-line string to htags


From: Shigio Yamaguchi
Subject: Re: [PATCH] add support of multi-line string to htags
Date: Thu, 20 Mar 2003 21:07:50 +0900

Committed.
Hypertext generated by htags is much improved.

Thank you!

> This is the version improved so that quotation marks and the backslash
> in a comment can be treated correctly.
> 
> The following things are assumed in order to simplify protect_line.
>  o The comment which starts in // is not divided into two or more lines by ba
ckslash-newline.
>  o An escape sequence is not divided into two or more lines by backslash-newl
ine.
>  o /* and // which are the start of a comment, and */ which is the end of a c
omment 
>    are not divided into two lines by backslash-newline.
> 
> 
> Index: htags/htags.in
> ===================================================================
> RCS file: /cvsroot/global/global/htags/htags.in,v
> retrieving revision 1.99
> diff -u -r1.99 htags.in
> --- htags/htags.in    6 Mar 2003 15:09:13 -0000       1.99
> +++ htags/htags.in    8 Mar 2003 16:10:26 -0000
> @@ -2052,6 +2052,7 @@
>               #
>               print "<PRE>\n";
>               $INCOMMENT = 0;                 # initial status is out of comm
ent
> +             $quote = '';
>               local($LNO, $TAG, $TYPE) = &anchor'first();
>               while (<SRC>) {
>                       local($converted);
> @@ -2257,54 +2258,61 @@
>  #
>  #    io)     $_      source line
>  #
> -#    \001    quoted(\) char
> -#    \002    quoted('') char
>  #    \003    quoted string
>  #    \004    comment
> -#    \005    line comment
> -#    \032    temporary mark
>  #
>  sub protect_line {
> -     @quoted_char1 = ();
> -     while (s/(\\.)/\001/) {
> -             push(@quoted_char1, $1);
> -     }
> -     @quoted_char2 = ();
> -     while (s/('[^']*')/\002/) {
> -             push(@quoted_char2, $1);
> -     }
>       @quoted_strings = ();
> -     while (s/("[^"]*")/\003/) {
> -             push(@quoted_strings, $1);
> -     }
>       @comments = ();
> -     s/^/\032/ if ($INCOMMENT);
> -     while (1) {
> -             if ($INCOMMENT == 0) {
> -                     if (s/\/\*/\032\/\*/) {         # start comment
> -                             $INCOMMENT = 1;
> -                     } else {
> -                             last;
> -                     }
> -             } else {
> +     if ($INCOMMENT) {
> +             # This regular expression was drived from
> +             # perl FAQ 4.27 (ftp://ftp.cis.ufl.edu/pub/perl/faq/FAQ)
> +             if (s!^([^*]*\*+([^/*][^*]*\*+)*/)!\004!) {
> +                     push(@comments, $1);
> +                     $INCOMMENT = 0;
> +             }
> +             else {
> +                     s/^(.*)$/\004/;
> +                     push(@comments, $1);
> +             }
> +     } elsif ($quote) {
> +             if (s/^(([^$quote\\]|\\.)*$quote)/\003/) {
> +                     push(@quoted_strings, $1);
> +                     $quote = '';
> +             }
> +             else {
> +                     s/^(.*)$/\003/;
> +                     push(@quoted_strings, $1);
> +             }
> +     }
> +     while (/(\/\/|\/\*|'|")/) {
> +             if ($1 eq '//') {
> +                     s/(\/\/.*$)/\004/;
> +                     push(@comments, $1);
> +             }
> +             elsif ($1 eq '/*') {
>                       # This regular expression was drived from
>                       # perl FAQ 4.27 (ftp://ftp.cis.ufl.edu/pub/perl/faq/FAQ
)
> -                     if (s!\032((/\*)?[^*]*\*+([^/*][^*]*\*+)*/)!\004!) {
> +                     if (s!(/\*[^*]*\*+([^/*][^*]*\*+)*/)!\004!) {
>                               push(@comments, $1);
> -                             $INCOMMENT = 0;
> -                     } else {
> -                             s/\032(.*)$/\004/;      # mark comment
> +                     }
> +                     else {
> +                             s/(\/\*.*)$/\004/;
>                               push(@comments, $1);
> +                             $INCOMMENT = 1;
> +                     }
> +             }
> +             else {
> +                     $quote = $1;
> +                     if (s/($quote([^$quote\\]|\\.)*$quote)/\003/) {
> +                             push(@quoted_strings, $1);
> +                             $quote = '';
> +                     }
> +                     else {
> +                             push(@quoted_strings, $1);
> +                             s/($quote.*)$/\003/;
>                       }
> -                     last if ($INCOMMENT);
>               }
> -     }
> -     $line_comment = '';
> -     if (s!(//.*)$!\005! || s!(/\004.*)$!\005!) {
> -             $line_comment = $1;
> -             # ^     //   /*   $     ... '//' invalidate '/*'.
> -             # ^     //*       $     ... Assumed '//' + '*', not '/' + '/*'.
> -             $INCOMMENT = 0;
>       }
>  }
>  #
> @@ -2315,9 +2323,6 @@
>  sub unprotect_line {
>       local($s);
>  
> -     if ($line_comment) {
> -             s/\005/$'comment_begin$line_comment$'comment_end/;
> -     }
>       while (@comments) {
>               $s = shift @comments;
>               # nested tag can be occured but no problem.
> @@ -2326,14 +2331,6 @@
>       while (@quoted_strings) {
>               $s = shift @quoted_strings;
>               s/\003/$s/;
> -     }
> -     while (@quoted_char2) {
> -             $s = shift @quoted_char2;
> -             s/\002/$s/;
> -     }
> -     while (@quoted_char1) {
> -             $s = shift @quoted_char1;
> -             s/\001/$s/;
>       }
>  }
>  #
> 
> ----
> Hideki IWAMOTO  address@hidden
> 
> 
> _______________________________________________
> Bug-global mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-global
> 
> 
--
Shigio Yamaguchi <address@hidden> - Tama Communications Corporation
PGP fingerprint: D1CB 0B89 B346 4AB6 5663  C4B6 3CA5 BBB3 57BE DDA3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]