]> git.draconx.ca Git - dxcommon.git/commitdiff
gen-tree.awk: Allow simple '#' comments.
authorNick Bowler <nbowler@draconx.ca>
Sat, 18 Jun 2022 01:33:07 +0000 (21:33 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sat, 18 Jun 2022 01:33:07 +0000 (21:33 -0400)
scripts/gen-tree.awk
tests/scripts.at

index d04378a81ff9161d3bc0605ed79ce1e1bec1162f..c461e5d1b97ec211575241408a54d03d4f63530a 100755 (executable)
@@ -5,9 +5,11 @@
 # Generate one or more C array initializers to encode simple tree structures
 # in a compact format.
 #
-# Each nonempty line of the input file is either an option specification
-# or # a tree specification.  An option specification (described later)
-# begins with an @ character.  Other lines specify tree nodes.
+# Each nonempty line of the input file is either a comment, an option
+# specification or a tree specification.  Each line is distinguished by
+# its first character.  A # character introduces a comment, an @ character
+# introduces an option specification (described later), and all other
+# nonempty lines are tree nodes.
 #
 # The first field of a tree specification must be a valid C identifier,
 # optionally followed by a comma.  The identifiers used on non-leaf nodes
@@ -102,6 +104,10 @@ BEGIN {
   indent_stack[0] = 0;
 }
 
+# Comments
+NF == 0 { next }
+$0 ~ /^#/ { next }
+
 # Options
 sub(/^@/, "", $0) {
   if (NF == 1) {
@@ -118,7 +124,6 @@ sub(/^@/, "", $0) {
   next
 }
 
-NF == 0 { next }
 { indent = index($0, $1) - 1 }
 
 indent > 0 {
index dcbcce56ead507575e2e45f83920daa05907bad6..41dfbb43760bcf95cd87792db5101e851cd1d882 100644 (file)
@@ -306,7 +306,8 @@ AT_SETUP([gen-tree.awk])
 AT_KEYWORDS([gen-tree awk script scripts])
 
 AT_DATA([tree.def],
-[[ROOT0
+[[# comment
+ROOT0
   r0a, r0a_OFFSET
     r0b, r0b_OFFSET
       r0c
@@ -314,6 +315,7 @@ AT_DATA([tree.def],
   r0e, r0e_OFFSET
     r0f
     r0g
+# comment
 ROOT1
   r1a, r1a_OFFSET
     r1b, r1b_OFFSET
@@ -325,6 +327,7 @@ ROOT1
       r1e
       r1b
       r1e
+# comment
 ]])
 
 AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
@@ -366,7 +369,7 @@ int main(void)
   return 0;
 }
 ]])
-cp tree.def expout
+sed '/^#/d' tree.def >expout
 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [expout])
 
 AT_CLEANUP