aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2018-11-26 20:52:23 +0200
committerArnold D. Robbins <arnold@skeeve.com>2018-11-26 20:52:23 +0200
commit1e6c88c44319694bfb2e9c0ca11db01ec670f0ad (patch)
tree72c69c3b8f3dd2f2af13e9d09d8d8ddc5b7be78f
parented06eeafe3dc901759e20466446fec48e83402fc (diff)
downloadegawk-1e6c88c44319694bfb2e9c0ca11db01ec670f0ad.tar.gz
egawk-1e6c88c44319694bfb2e9c0ca11db01ec670f0ad.tar.bz2
egawk-1e6c88c44319694bfb2e9c0ca11db01ec670f0ad.zip
Continue polishing comments. New test.
-rwxr-xr-xChangeLog6
-rw-r--r--awkgram.c10
-rw-r--r--awkgram.y10
-rw-r--r--profile.c4
-rw-r--r--test/ChangeLog7
-rw-r--r--test/Makefile.am6
-rw-r--r--test/Makefile.in11
-rw-r--r--test/Maketests5
-rw-r--r--test/profile11.awk321
-rw-r--r--test/profile11.ok346
-rw-r--r--test/profile5.ok2
11 files changed, 717 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index b43973cc..c58ea9d2 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-26 Arnold D. Robbins <arnold@skeeve.com>
+
+ * profile.c (print_comment): Indent for chained comment.
+ * awkgram.y (load_library): Return early if just pretty printing.
+ (yylex): Fix handling of ?: and allow_newline etc.
+
2018-11-25 Arnold D. Robbins <arnold@skeeve.com>
* main.c (platform_name): New function returning platform name.
diff --git a/awkgram.c b/awkgram.c
index e063d039..c89fc033 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -5353,6 +5353,9 @@ load_library(INSTRUCTION *file, void **srcfile_p)
return false;
}
+ if (do_pretty_print && ! do_profile)
+ return true;
+
if (strlen(src) == 0) {
if (do_lint)
lintwarn_ln(file->source_line, _("empty filename after @load"));
@@ -6188,13 +6191,14 @@ retry:
// fall through
case ':':
yylval = GET_INSTRUCTION(Op_cond_exp);
- if (c == ':' && qm_col_count > 0) {
- if (do_posix) {
+ if (qm_col_count > 0) {
+ if (! do_posix) {
INSTRUCTION *new_comment = NULL;
allow_newline(& new_comment);
yylval->comment = new_comment;
}
- qm_col_count--;
+ if (c == ':')
+ qm_col_count--;
}
return lasttok = c;
diff --git a/awkgram.y b/awkgram.y
index 4d3e44e1..4be4413f 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2882,6 +2882,9 @@ load_library(INSTRUCTION *file, void **srcfile_p)
return false;
}
+ if (do_pretty_print && ! do_profile)
+ return true;
+
if (strlen(src) == 0) {
if (do_lint)
lintwarn_ln(file->source_line, _("empty filename after @load"));
@@ -3717,13 +3720,14 @@ retry:
// fall through
case ':':
yylval = GET_INSTRUCTION(Op_cond_exp);
- if (c == ':' && qm_col_count > 0) {
- if (do_posix) {
+ if (qm_col_count > 0) {
+ if (! do_posix) {
INSTRUCTION *new_comment = NULL;
allow_newline(& new_comment);
yylval->comment = new_comment;
}
- qm_col_count--;
+ if (c == ':')
+ qm_col_count--;
}
return lasttok = c;
diff --git a/profile.c b/profile.c
index 5494b170..3041545a 100644
--- a/profile.c
+++ b/profile.c
@@ -1349,6 +1349,10 @@ print_comment(INSTRUCTION* pc, long in)
if (pc->comment) {
// chaining should only be two deep
assert(pc->comment->comment == NULL);
+ // if first was EOL comment, next must be block comment,
+ // it needs to be indented.
+ if (pc->memory->comment_type == EOL_COMMENT)
+ in++;
print_comment(pc->comment, in);
}
}
diff --git a/test/ChangeLog b/test/ChangeLog
index bf0cbffa..3def1823 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,10 @@
+2018-11-26 Arnold D. Robbins <arnold@skeeve.com>
+
+ * profile5.ok: Updated after code change.
+ * Makefile.am (GAWK_EXT_TESTS): New test, profile11.ok. Add
+ to the other relevant macros.
+ * profile11.awk, profile11.ok: New files.
+
2018-11-25 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (GAWK_EXT_TESTS): Fix layout of the list.
diff --git a/test/Makefile.am b/test/Makefile.am
index e1ecc649..3e7394f9 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -899,6 +899,8 @@ EXTRA_DIST = \
profile9.ok \
profile10.awk \
profile10.ok \
+ profile11.awk \
+ profile11.ok \
prt1eval.awk \
prt1eval.ok \
prtoeval.awk \
@@ -1307,7 +1309,7 @@ GAWK_EXT_TESTS = \
nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \
patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge \
procinfs profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
- profile7 profile8 profile9 profile10 pty1 pty2 \
+ profile7 profile8 profile9 profile10 profile11 pty1 pty2 \
rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin \
rsstart1 rsstart2 rsstart3 rstest6 \
shadow shadowbuiltin sortfor sortfor2 sortu sourcesplit split_after_fpat \
@@ -1364,7 +1366,7 @@ NEED_NONDEC = mpfrbigint2 nondec2 intarray forcenum
NEED_POSIX = printf0 posix2008sub paramasfunc1 paramasfunc2 muldimposix
# List of tests that need --pretty-print
-NEED_PRETTY = profile4 profile5 profile8 profile9 profile10
+NEED_PRETTY = profile4 profile5 profile8 profile9 profile10 profile11
# List of tests that need --re-interval
NEED_RE_INTERVAL = gsubtst3 reint reint2
diff --git a/test/Makefile.in b/test/Makefile.in
index 1e3fe2ee..3daf6980 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1157,6 +1157,8 @@ EXTRA_DIST = \
profile9.ok \
profile10.awk \
profile10.ok \
+ profile11.awk \
+ profile11.ok \
prt1eval.awk \
prt1eval.ok \
prtoeval.awk \
@@ -1565,7 +1567,7 @@ GAWK_EXT_TESTS = \
nastyparm negtime next nondec nondec2 nonfatal1 nonfatal2 nonfatal3 \
patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge \
procinfs profile0 profile1 profile2 profile3 profile4 profile5 profile6 \
- profile7 profile8 profile9 profile10 pty1 pty2 \
+ profile7 profile8 profile9 profile10 profile11 pty1 pty2 \
rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin \
rsstart1 rsstart2 rsstart3 rstest6 \
shadow shadowbuiltin sortfor sortfor2 sortu sourcesplit split_after_fpat \
@@ -1621,7 +1623,7 @@ NEED_NONDEC = mpfrbigint2 nondec2 intarray forcenum
NEED_POSIX = printf0 posix2008sub paramasfunc1 paramasfunc2 muldimposix
# List of tests that need --pretty-print
-NEED_PRETTY = profile4 profile5 profile8 profile9 profile10
+NEED_PRETTY = profile4 profile5 profile8 profile9 profile10 profile11
# List of tests that need --re-interval
NEED_RE_INTERVAL = gsubtst3 reint reint2
@@ -4396,6 +4398,11 @@ profile10:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+profile11:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
regnul1:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 65f0197c..067854e3 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1724,6 +1724,11 @@ profile10:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+profile11:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --pretty-print=_$@ >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
regnul1:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/profile11.awk b/test/profile11.awk
new file mode 100644
index 00000000..180e3bb5
--- /dev/null
+++ b/test/profile11.awk
@@ -0,0 +1,321 @@
+
+# comments/for.awk
+BEGIN {
+ for (i = 1; i <= 10; i++) print i
+
+ for (i = 1; i <= 10; i++) # comment 0
+ print i
+
+ for (i = 1; # comment 1a
+ i <= 10; i++) print i
+
+ for (i = 1; i <= 10; # comment 2a
+ i++) print i
+
+ for (i = 1; # comment 1b
+ i <= 10; # comment 2b
+ i++) print i
+
+ for (i = 1; # comment 1c
+ i <= 10; # comment 2c
+ i++) # comment 3c
+ print i
+}
+
+# comments/for0.awk
+BEGIN {
+ for (iggy in foo) # comment 5
+ # comment 6
+ ;
+}
+
+# comments/for1.awk
+BEGIN {
+ for (iggy in foo) # comment 1
+ # comment 2
+ {
+ print iggy
+ }
+
+ for (iggy in foo) # comment 3
+ # comment 4
+ print iggy
+
+ for (iggy in foo) # comment 5
+ # comment 6
+ ;
+}
+
+# comments/for2.awk
+BEGIN {
+ for (;;) print i
+
+ for (;;) # comment 0
+ print i
+
+ for (; # comment 1a
+ ;) print i
+
+ for (; ; # comment 2a
+ ) print i
+
+ for (; # comment 1b
+ ; # comment 2b
+ ) print i
+
+ for (; # comment 1c
+ ; # comment 2c
+ ) # comment 3c
+ print i
+}
+
+# comments/for_del.awk
+BEGIN { for (iggy in foo) delete foo[iggy] }
+
+# comments/do.awk
+BEGIN {
+ do # DO comment
+ { # LBRACE comment
+ # block comment
+ print 42
+ } # rbrace comment
+ while (0) # WHILE comment
+}
+
+# comments/do2.awk
+BEGIN {
+ do # DO comment
+ { # LBRACE comment
+ # block comment
+ print 42
+ } # rbrace comment
+ while (0)
+}
+
+# comments2/do.awk
+BEGIN {
+ do # do comment
+ { # lbrace comment
+ # block comment
+ print 42
+ } # rbace EOL comment
+ # rbrace block comment
+ while (1) # while comment
+}
+
+# comments2/if.awk
+BEGIN {
+ if (a) # IF comment
+ print "foo" # print comment
+
+ if (a) # IF comment 2
+ { # lbrace comment
+ print "bar"
+ }
+ else # ELSE comment
+ print "baz"
+}
+
+# comments/if0.awk
+BEGIN {
+ if (a)
+ ; # nothing
+ else
+ print "b"
+}
+
+# comments/switch.awk
+BEGIN {
+ a = 5
+ switch (a) # switch EOL comment
+ # switch block comment
+ { # lbrace EOL comment
+ # lbrace block comment
+ case 5: # comment after case
+ print "five!"
+ break
+ # block comment after case
+ default: # comment after default
+ print "default" # print comment
+ break
+ } # rbrace EOL comment
+ # rbrace block comment
+}
+
+# comments2/switch.awk
+BEGIN {
+ a = 5
+ switch (a) # switch EOL comment
+ # switch block comment
+ { # lbrace EOL comment
+ # lbrace block comment
+ case 5:
+ print "five!"
+ break;
+ # block comment after case
+ } # rbrace EOL comment
+ # rbrace block comment
+}
+
+# comments2/switch0.awk
+BEGIN {
+ a = 5
+ switch (a)
+ {
+ case 5: # case comment
+ print "five!"
+ break
+ default: # default comment
+ print "default"
+ break
+ }
+}
+
+# comments2/switch1.awk
+BEGIN {
+ a = 5
+ switch (a)
+ {
+ case 5:
+ # case comment
+ print "five!"
+ break
+ default: # default comment
+ print "default"
+ break
+ }
+}
+
+# comments2/while.awk
+BEGIN {
+ while (1) # while comment
+ { # lbrace comment
+ # block comment
+ print 42
+ }
+}
+
+# comments2/while2.awk
+BEGIN {
+ while (1) # while comment
+ { # lbrace comment
+ # block comment
+ }
+}
+
+# comments2/f.awk
+function bar(p1,
+ p2)
+{
+ print "foo"
+} # rbrace eol
+ # rbrace block
+
+# comments2/function.awk
+function baz(p1, # comment
+ p2)
+ # comment before braces
+{ # lbrace eol
+ # lbrace block
+ print "foo"
+} # rbrace eol
+ # rbrace block
+
+# comments/function.awk
+function funny(param1, # param comment 1
+ param2, param3, # param comment 2
+ param4)
+ # Comment between header and body
+{ # lbrace EOL comment
+ # lbrace block comment
+ print "funny"
+} # rbrace EOL comment
+ # rbrace block comment
+
+# comments/function2.awk
+function funnyhaha(param1,
+ param2, param3,
+ param4)
+{ # lbrace EOL comment
+ # lbrace block comment
+ print "funny"
+} # rbrace EOL comment
+ # rbrace block comment
+
+# comments/callcoma.awk
+function callme(a, b, c)
+{
+ printf("a = %s, b = %s, c = %s\n", # format comment
+ a, # a2 comment
+ b, # b2 comment
+ c)
+}
+
+BEGIN {
+ callme(1, # 1 comment
+ 2, # 2 comment
+ 3)
+}
+
+# comments/exp.awk
+/foo/, # range comment
+ # range comment 2
+
+# range comment b
+
+# range comment c
+/bar/ { print }
+
+# comments/load.awk
+@load "filefuncs" # get file functions
+
+BEGIN {
+ stat("/etc/passwd", data)
+ for (i in data)
+ print i, data[i]
+}
+
+# comments/andor.awk
+BEGIN {
+ if (a && # and comment
+ b || # or comment
+ c)
+ print "foo"
+}
+
+# comments/qmcol-qm.awk
+BEGIN {
+ a = 1 ? # qm comment
+ 2 :
+ 3
+ print a
+}
+
+# comments/qmcol-colon.awk
+BEGIN {
+ a = 1 ?
+ 2 : # colon comment
+ 3
+ print a
+}
+
+# comments/qmcolboth.awk
+BEGIN {
+ a = 1 ? # qm comment
+ 2 : # colon comment
+ 3
+ print a
+}
+
+# test beginning of line block comments (com2.awk)
+BEGIN {
+ print "hi" # comment 1
+# comment 2
+ print "there"
+
+ if (foo) {
+ print "hello" # comment 3
+# comment 4
+ print "world"
+ }
+}
diff --git a/test/profile11.ok b/test/profile11.ok
new file mode 100644
index 00000000..1be49aa8
--- /dev/null
+++ b/test/profile11.ok
@@ -0,0 +1,346 @@
+# comments/for.awk
+BEGIN {
+ for (i = 1; i <= 10; i++) {
+ print i
+ }
+ for (i = 1; i <= 10; i++) { # comment 0
+ print i
+ }
+ for (i = 1; # comment 1a
+ i <= 10; i++) {
+ print i
+ }
+ for (i = 1; i <= 10; # comment 2a
+ i++) {
+ print i
+ }
+ for (i = 1; # comment 1b
+ i <= 10; # comment 2b
+ i++) {
+ print i
+ }
+ for (i = 1; # comment 1c
+ i <= 10; # comment 2c
+ i++) { # comment 3c
+ print i
+ }
+}
+
+# comments/for0.awk
+BEGIN {
+ for (iggy in foo) {
+ # comment 5
+
+ # comment 6
+ }
+}
+
+# comments/for1.awk
+BEGIN {
+ for (iggy in foo) {
+ # comment 1
+
+ # comment 2
+ print iggy
+ }
+ for (iggy in foo) {
+ # comment 3
+
+ # comment 4
+ print iggy
+ }
+ for (iggy in foo) {
+ # comment 5
+
+ # comment 6
+ }
+}
+
+# comments/for2.awk
+BEGIN {
+ for (;;) {
+ print i
+ }
+ for (;;) { # comment 0
+ print i
+ }
+ for (; # comment 1a
+ ; ) {
+ print i
+ }
+ for (; ; # comment 2a
+ ) {
+ print i
+ }
+ for (; # comment 1b
+ ; # comment 2b
+ ) {
+ print i
+ }
+ for (; # comment 1c
+ ; # comment 2c
+ ) { # comment 3c
+ print i
+ }
+}
+
+# comments/for_del.awk
+BEGIN {
+ for (iggy in foo) {
+ delete foo[iggy]
+ }
+}
+
+# comments/do.awk
+BEGIN {
+ do { # DO comment
+ # LBRACE comment
+ # block comment
+ print 42
+ } while (0) # WHILE comment
+ # rbrace comment
+}
+
+# comments/do2.awk
+BEGIN {
+ do { # DO comment
+ # LBRACE comment
+ # block comment
+ print 42
+ } while (0) # rbrace comment
+}
+
+# comments2/do.awk
+BEGIN {
+ do { # do comment
+ # lbrace comment
+ # block comment
+ print 42
+ } while (1) # while comment
+ # rbace EOL comment
+ # rbrace block comment
+}
+
+# comments2/if.awk
+BEGIN {
+ if (a) {
+ # IF comment
+ print "foo" # print comment
+ }
+ if (a) { # lbrace comment
+ # IF comment 2
+ print "bar"
+ } else {
+ # ELSE comment
+ print "baz"
+ }
+}
+
+# comments/if0.awk
+BEGIN {
+ if (a) {
+ # nothing
+ } else {
+ print "b"
+ }
+}
+
+# comments/switch.awk
+BEGIN {
+ a = 5
+ switch (a) {
+ # switch EOL comment
+
+ # switch block comment
+
+ # lbrace EOL comment
+
+ # lbrace block comment
+ case 5: # comment after case
+ print "five!"
+ break
+ # block comment after case
+ default: # comment after default
+ print "default" # print comment
+ break
+ }
+ # rbrace EOL comment
+ # rbrace block comment
+}
+
+# comments2/switch.awk
+BEGIN {
+ a = 5
+ switch (a) {
+ # switch EOL comment
+
+ # switch block comment
+
+ # lbrace EOL comment
+
+ # lbrace block comment
+ case 5:
+ print "five!"
+ break
+ # block comment after case
+ }
+ # rbrace EOL comment
+ # rbrace block comment
+}
+
+# comments2/switch0.awk
+BEGIN {
+ a = 5
+ switch (a) {
+ case 5: # case comment
+ print "five!"
+ break
+ default: # default comment
+ print "default"
+ break
+ }
+}
+
+# comments2/switch1.awk
+BEGIN {
+ a = 5
+ switch (a) {
+ case 5:
+ # case comment
+ print "five!"
+ break
+ default: # default comment
+ print "default"
+ break
+ }
+}
+
+# comments2/while.awk
+BEGIN {
+ while (1) {
+ # while comment
+ # lbrace comment
+ # block comment
+ print 42
+ }
+}
+
+# comments2/while2.awk
+BEGIN {
+ while (1) {
+ # while comment
+ # lbrace comment
+ # block comment
+ }
+}
+
+# comments2/f.awk
+BEGIN {
+ callme(1, # 1 comment
+ 2, # 2 comment
+ 3)
+}
+
+# comments/load.awk
+BEGIN {
+ stat("/etc/passwd", data)
+ for (i in data) {
+ print i, data[i]
+ }
+}
+
+# comments/andor.awk
+BEGIN {
+ if (a && # and comment
+ b || # or comment
+ c) {
+ print "foo"
+ }
+}
+
+# comments/qmcol-qm.awk
+BEGIN {
+ a = 1 ? # qm comment
+ 2 : 3
+ print a
+}
+
+# comments/qmcol-colon.awk
+BEGIN {
+ a = 1 ? 2 : # colon comment
+ 3
+ print a
+}
+
+# comments/qmcolboth.awk
+BEGIN {
+ a = 1 ? # qm comment
+ 2 : # colon comment
+ 3
+ print a
+}
+
+# test beginning of line block comments (com2.awk)
+BEGIN {
+ print "hi" # comment 1
+ # comment 2
+ print "there"
+ if (foo) {
+ print "hello" # comment 3
+ # comment 4
+ print "world"
+ }
+}
+
+# range comment
+# range comment 2
+
+# range comment b
+
+# range comment c
+/foo/, /bar/ {
+ print
+}
+
+
+function bar(p1, p2)
+{
+ print "foo"
+}
+
+# comment
+
+# comment before braces
+function baz(p1, p2)
+{
+ # lbrace eol
+ # lbrace block
+ print "foo"
+}
+
+function callme(a, b, c)
+{
+ printf "a = %s, b = %s, c = %s\n", # format comment
+ a, # a2 comment
+ b, # b2 comment
+ c
+}
+
+# param comment 1
+
+# param comment 2
+
+# Comment between header and body
+function funny(param1, param2, param3, param4)
+{
+ # lbrace EOL comment
+ # lbrace block comment
+ print "funny"
+}
+
+function funnyhaha(param1, param2, param3, param4)
+{
+ # lbrace EOL comment
+ # lbrace block comment
+ print "funny"
+}
diff --git a/test/profile5.ok b/test/profile5.ok
index 7ac24024..0880f028 100644
--- a/test/profile5.ok
+++ b/test/profile5.ok
@@ -72,7 +72,7 @@ BEGIN { ########################################################################
_QSTR[_CHR[i]] = _QSTRQ[_CHR[i]]
}
_QSTR["\\"] = "\\\\" #; _QSTR["\""]="\\\""
-#_____________________________________________________________________________
+ #_____________________________________________________________________________
_CHR["CR"] = "\r"
_CHR["EOL"] = "\r\n"
_CHR["EOF"] = "\032"