From bef92ab720fc8fa60b83e6c4927e691009c4b2be Mon Sep 17 00:00:00 2001 From: Steve Hoover Date: Sat, 27 Jul 2024 21:16:33 -0400 Subject: [PATCH] Indentation change in pre_m4. --- bin/pre_m4 | 155 ++++++++++++++++++++++++++--------------------------- 1 file changed, 76 insertions(+), 79 deletions(-) diff --git a/bin/pre_m4 b/bin/pre_m4 index 28cd358..f51b482 100755 --- a/bin/pre_m4 +++ b/bin/pre_m4 @@ -433,58 +433,57 @@ sub read_line { if ($inside_text_block) { undef($end_block_type); } else { - # TODO: indent - - # Add ')' if evaluated with '*' syntax. - if (($end_block_type ne '') && $m4_block_eval[$m4_quote_depth]) { - $text .= ')'; - } - # Record block end type encoded as the corresponding open quote. - if ($end_block_type ne '') { # } or ] - $line_block_end_type = ($end_block_type eq ']') ? '[' : - ($end_block_type eq '}') ? '{' : - "['"; - # Strict, but not ideal if block quote is on a line with other open quotes. - #if (length($ind) != $m4_indentation_depth[$m4_quote_depth]) { - # &parse_error("Block termination indentation depth is recommended to match the indentation of line $m4_indentation_line_num[$m4_quote_depth].", "Warning"); - #} - } + # Add ')' if evaluated with '*' syntax. + if (($end_block_type ne '') && $m4_block_eval[$m4_quote_depth]) { + $text .= ')'; + } + # Record block end type encoded as the corresponding open quote. + if ($end_block_type ne '') { # } or ] + $line_block_end_type = ($end_block_type eq ']') ? '[' : + ($end_block_type eq '}') ? '{' : + "['"; + # Strict, but not ideal if block quote is on a line with other open quotes. + #if (length($ind) != $m4_indentation_depth[$m4_quote_depth]) { + # &parse_error("Block termination indentation depth is recommended to match the indentation of line $m4_indentation_line_num[$m4_quote_depth].", "Warning"); + #} + } - # Statement substitutions in code context. - if ((($m4_quote_type[$m4_quote_depth] eq '[') || - ($m4_quote_type[$m4_quote_depth] eq '{') - ) && - (length($ind) == $m4_body_indentation_depth[$m4_quote_depth]) - ) { - my $out = $text =~ s/^~//; - my $stmt_type = $out ? "m5__out_stmt" : "m5__stmt"; - # Indentation matches block indentations, so statement substitutions can be made. - if ($text =~ s#^/.*##) { - # M5 code block line comment (single slash). - } else { - if ($text =~ /^m5_/) { - # No substitution on a line beginning with m5_. Report error. - &parse_error("In M5 code context, lines should not start with \"m5_\".", "Warning"); + # Statement substitutions in code context. + if ((($m4_quote_type[$m4_quote_depth] eq '[') || + ($m4_quote_type[$m4_quote_depth] eq '{') + ) && + (length($ind) == $m4_body_indentation_depth[$m4_quote_depth]) + ) { + my $out = $text =~ s/^~//; + my $stmt_type = $out ? "m5__out_stmt" : "m5__stmt"; + # Indentation matches block indentations, so statement substitutions can be made. + if ($text =~ s#^/.*##) { + # M5 code block line comment (single slash). } else { - # word( => m5__l(63)m5__stmt(['m5_word'], - if ($text !~ s/^(\w+)\(/m5__l($line_num)$stmt_type(${OPEN_QUOTE}m5_$1$CLOSE_QUOTE,/) { - # word => m5__stmt_var(word). - if ($text =~ s/^(\w+)(.*)/m5__l($line_num)${stmt_type}_var($OPEN_QUOTE$1$CLOSE_QUOTE)$2/) { - # Replaced word. Must have been ~word. - if (!$out) { - &parse_error("Code block variable statements require \"~\":\n\t\t$orig_text", "Warning"); - } - } else { - # No replacement yet. - # ~( => m5_out( - if ($text !~ s/^\(/m5__l($line_num)m5_out(/ || !$out) { - # No replacement or "~" missing. - if ($text !~ m#//# || $out) { - # Not a comment. Bad statement, except for a few special cases: - # - region lines - # - block begin lines - if (!($ind eq '' && $text =~ /^\\/) && $text !~ /^\*?(<\w+>)?[\[\{]\s*$/) { - &parse_error("Unable to parse code block statement:\n\t\t$orig_text", "Warning"); + if ($text =~ /^m5_/) { + # No substitution on a line beginning with m5_. Report error. + &parse_error("In M5 code context, lines should not start with \"m5_\".", "Warning"); + } else { + # word( => m5__l(63)m5__stmt(['m5_word'], + if ($text !~ s/^(\w+)\(/m5__l($line_num)$stmt_type(${OPEN_QUOTE}m5_$1$CLOSE_QUOTE,/) { + # word => m5__stmt_var(word). + if ($text =~ s/^(\w+)(.*)/m5__l($line_num)${stmt_type}_var($OPEN_QUOTE$1$CLOSE_QUOTE)$2/) { + # Replaced word. Must have been ~word. + if (!$out) { + &parse_error("Code block variable statements require \"~\":\n\t\t$orig_text", "Warning"); + } + } else { + # No replacement yet. + # ~( => m5_out( + if ($text !~ s/^\(/m5__l($line_num)m5_out(/ || !$out) { + # No replacement or "~" missing. + if ($text !~ m#//# || $out) { + # Not a comment. Bad statement, except for a few special cases: + # - region lines + # - block begin lines + if (!($ind eq '' && $text =~ /^\\/) && $text !~ /^\*?(<\w+>)?[\[\{]\s*$/) { + &parse_error("Unable to parse code block statement:\n\t\t$orig_text", "Warning"); + } } } } @@ -492,39 +491,37 @@ sub read_line { } } } - } - - # Block quote substitutions. - # TODO: Do not do this in source/text context. - # TODO: Support labels on all quotes (not just block quotes). They are useful for scoped macros. - # E.g. [ => m5__block([' -or- *