gawk-diffs
[Top][All Lists]
Advanced

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

[gawk-diffs] [SCM] gawk branch, comment, updated. gawk-4.1.0-730-g8006ef


From: Stephen Davies
Subject: [gawk-diffs] [SCM] gawk branch, comment, updated. gawk-4.1.0-730-g8006ef4
Date: Sun, 24 Aug 2014 00:57:50 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, comment has been updated
       via  8006ef4ca16fa8264dcc1e849783e1f4ce4978a1 (commit)
       via  9a7e5828f29d3f5daba5dc5ef1f6b9cd87f596b8 (commit)
      from  8f2c2755573b81c1e2c9ef1c42c529d13396d4d2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=8006ef4ca16fa8264dcc1e849783e1f4ce4978a1

commit 8006ef4ca16fa8264dcc1e849783e1f4ce4978a1
Merge: 9a7e582 8f2c275
Author: Stephen Davies <address@hidden>
Date:   Sun Aug 24 10:26:36 2014 +0930

    Merge branch 'comment' of ssh://git.sv.gnu.org/srv/git/gawk into comment
    
    Remote changes?


http://git.sv.gnu.org/cgit/gawk.git/commit/?id=9a7e5828f29d3f5daba5dc5ef1f6b9cd87f596b8

commit 9a7e5828f29d3f5daba5dc5ef1f6b9cd87f596b8
Author: Stephen Davies <address@hidden>
Date:   Sun Aug 24 10:24:05 2014 +0930

    Progress in collecting comments and with comments within a block.
    No joy with comments before BEGIN or END and, before { or after }.
    
    Changed my email

diff --git a/awkgram.y b/awkgram.y
index d23dfd1..664b0c8 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -209,6 +209,7 @@ program
        | program nls
        | program LEX_EOF
          {
+/* add any outstanding comments to end. But how?  */
                next_sourcefile();
                if (sourcefile == srcfiles)
                        process_deferred();
@@ -451,22 +452,27 @@ statements
                if ($2 == NULL) {
                        if (comment == NULL)
                                $$ = $1;
-                       else
+                       else {
                                $$ = list_prepend($1, comment);
+                               comment = NULL;
+                       }
                } else {
                        add_lint($2, LINT_no_effect);
                        if ($1 == NULL) {
                                if (comment == NULL)
                                        $$ = $2;
-                               else
+                               else {
                                        $$ = list_prepend($2, comment);
+                                       comment = NULL;
+                               }
                        } else {
-                               if (comment != NULL)
-                                       list_append($1, comment);
+                               if (comment != NULL){
+                                       list_append($2, comment);
+                                       comment = NULL;
+                               }
                                $$ = list_merge($1, $2);
                        }
                }
-               comment = NULL;
                yyerrok;
          }
        | statements error
@@ -2939,6 +2945,53 @@ pushback(void)
 }
 
 
+/* get_comment --- collect comment text */
+
+int get_comment(void)
+{
+       int c;
+       tok = tokstart;
+       tokadd('#');
+
+       while (true){
+               while ((c = nextc(false)) != '\n' && c != END_FILE){
+                       tokadd(c);
+               }
+               if (c == '\n'){
+                       tokadd(c);
+                       sourceline++;
+                       do {
+                               c = nextc(false);
+                               if (c == '\n') {
+                                       sourceline++;
+                                       tokadd(c);
+                               }
+                       } while (isspace(c) && c != END_FILE) ;
+                       if ( c == END_FILE)
+                               break;
+                       else if (c != '\#'){
+                               pushback();
+                               break;
+                       } else
+                               tokadd(c);
+               } else
+                       break;
+       }
+       if (comment != NULL) {
+               size_t new = comment->memory->stlen + (tok - tokstart) + 2;
+               erealloc(comment->memory->stptr, char *, new, "yylex");
+               memcpy(comment->memory->stptr + comment->memory->stlen, 
tokstart, (tok - tokstart));
+               comment->memory->stlen += (tok - tokstart);
+               comment->memory->stptr[comment->memory->stlen] = '\0';
+       } else {
+               comment = bcalloc(Op_comment, 1, sourceline);
+               comment->source_file = source;
+               comment->memory = make_str_node(tokstart, tok - tokstart, 0);
+       }
+
+       return c;
+}
+
 /* allow_newline --- allow newline after &&, ||, ? and : */
 
 static void
@@ -2953,30 +3006,13 @@ allow_newline(void)
                        break;
                }
                if (c == '#') {
-//                     if (do_pretty_print) {
-                               tok = tokstart;
-                               tokadd('#');
+                       if (do_pretty_print && !do_profile) {
+                       /* collect comment byte code iff doing pretty print but 
not profiling.  */
+                               c = get_comment();
+                       } else {
                                while ((c = nextc(false)) != '\n' && c != 
END_FILE)
-                                       tokadd(c);
-                               if (c == '\n')
-                                       tokadd(c);
-
-                               if (comment != NULL) {
-                                       size_t new = comment->memory->stlen + 
(tok - tokstart) + 2;
-                                       erealloc(comment->memory->stptr, char 
*, new, "allow_newline");
-                                       memcpy(comment->memory->stptr + 
comment->memory->stlen, tokstart, (tok - tokstart));
-                                       comment->memory->stlen += (tok - 
tokstart);
-                                       
comment->memory->stptr[comment->memory->stlen] = '\0';
-                               } else {
-                                       comment = bcalloc(Op_comment, 1, 
sourceline);
-                                       comment->source_file = source;
-
-                                       comment->memory = 
make_str_node(tokstart, tok - tokstart, 0);
-                               }
-//                     } else {
-//                             while ((c = nextc()) != '\n' && c != END_FILE)
-//                                     continue;
-//                     }
+                                       continue;
+                       }
                        if (c == END_FILE) {
                                pushback();
                                break;
@@ -3180,38 +3216,19 @@ retry:
                return lasttok = NEWLINE;
 
        case '#':               /* it's a comment */
-//             if (do_pretty_print) {
-                       tok = tokstart;
-                       tokadd('#');
-                       while ((c = nextc(false)) != '\n') {
-                               if (c == END_FILE)
-                                       break;
-                               tokadd(c);
-                       }
-                       if (c == '\n')
-                               tokadd(c);
-
-                       if (comment != NULL) {
-                               size_t new = comment->memory->stlen + (tok - 
tokstart) + 2;
-                               erealloc(comment->memory->stptr, char *, new, 
"yylex");
-                               memcpy(comment->memory->stptr + 
comment->memory->stlen, tokstart, (tok - tokstart));
-                               comment->memory->stlen += (tok - tokstart);
-                               comment->memory->stptr[comment->memory->stlen] 
= '\0';
-                       } else {
-                               comment = bcalloc(Op_comment, 1, sourceline);
-                               comment->source_file = source;
-                               comment->memory = make_str_node(tokstart, tok - 
tokstart, 0);
-                       }
+               if (do_pretty_print && ! do_profile) {
+                       /* collect comment byte code iff doing pretty print but 
not profiling.  */
+                               c = get_comment();
 
                        if (c == END_FILE)
                                return lasttok = NEWLINE_EOF;
-//             } else {
-//                     while ((c = nextc()) != '\n') {
-//                             if (c == END_FILE)
-//                                     return lasttok = NEWLINE_EOF;
-//                     }
-//             }
-               sourceline++;
+               } else {
+                       while ((c = nextc(false)) != '\n') {
+                               if (c == END_FILE)
+                                       return lasttok = NEWLINE_EOF;
+                       }
+               }
+//             sourceline++;
                return lasttok = NEWLINE;
 
        case '@':
@@ -3220,7 +3237,7 @@ retry:
        case '\\':
 #ifdef RELAXED_CONTINUATION
                /*
-                * This code puports to allow comments and/or whitespace
+                * This code purports to allow comments and/or whitespace
                 * after the `\' at the end of a line used for continuation.
                 * Use it at your own risk. We think it's a bad idea, which
                 * is why it's not on by default.
@@ -3237,9 +3254,13 @@ retry:
                                        lintwarn(
                _("use of `\\ #...' line continuation is not portable"));
                                }
-                               while ((c = nextc(false)) != '\n')
-                                       if (c == END_FILE)
-                                               break;
+                               if (do_pretty_print && !do_profile)
+                                       c = get_comment();
+                               else {
+                                       while ((c = nextc(false)) != '\n')
+                                               if (c == END_FILE)
+                                                       break;
+                               }
                        }
                        pushback();
                }
@@ -3451,7 +3472,7 @@ retry:
                                lastline = sourceline;
                        return lasttok = c;
                }
-               did_newline++;
+               did_newline = true;
                --lexptr;       /* pick up } next time */
                return lasttok = NEWLINE;
 
@@ -5121,11 +5142,6 @@ append_rule(INSTRUCTION *pattern, INSTRUCTION *action)
                }
        }
 
-//     if (comment != NULL) {
-//             ip = list_prepend(ip, comment);
-//             comment = NULL;
-//     }
-
        list_append(rule_list, rp + 1);
 
        if (rule_block[rule] == NULL)
diff --git a/profile.c b/profile.c
index 5c7555e..51ef971 100644
--- a/profile.c
+++ b/profile.c
@@ -882,7 +882,7 @@ cleanup:
                        count = pc->memory->stlen;
                        text = pc->memory->stptr;
 
-                       indent(SPACEOVER);
+                       indent(SPACEOVER);   /* is this correct? Where should 
comments go?  */
                        for (; count > 0; count--, text++) {
                                if (after_newline) {
                                        indent(SPACEOVER);

-----------------------------------------------------------------------

Summary of changes:
 awkgram.y |  150 ++++++++++++++++++++++++++++++++++---------------------------
 profile.c |    2 +-
 2 files changed, 84 insertions(+), 68 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

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