texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: @caption, @shortcaption nesting checking


From: Gavin D. Smith
Subject: branch master updated: @caption, @shortcaption nesting checking
Date: Sat, 21 Jan 2023 20:10:09 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new d44dac64bc @caption, @shortcaption nesting checking
d44dac64bc is described below

commit d44dac64bc110f7c87100186991ece7e642df2be
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Jan 22 01:09:58 2023 +0000

    @caption, @shortcaption nesting checking
    
    * tp/Texinfo/XS/parsetexi/parser.c (check_valid_nesting_context):
    Check if @caption or @shortcaption is called in caption context.
    
    * tp/Texinfo/XS/parsetexi/separator.c (handle_open_brace)
    Increment nesting_context.footnote for @caption, @shortcaption.
    * tp/Texinfo/XS/parsetexi/close.c (close_current),
    * tp/Texinfo/XS/parsetexi/separator.c (handle_close_brace),
    Decrement nesting_context.footnote for @caption, @shortcaption.
---
 ChangeLog                               | 14 +++++++++++++-
 tp/TODO                                 |  2 ++
 tp/Texinfo/XS/parsetexi/close.c         |  2 ++
 tp/Texinfo/XS/parsetexi/context_stack.h |  1 +
 tp/Texinfo/XS/parsetexi/parser.c        |  6 ++++++
 tp/Texinfo/XS/parsetexi/separator.c     |  7 +++++++
 6 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 08f0986d09..e903a88eb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2023-01-22  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       @caption, @shortcaption nesting checking
+
+       * tp/Texinfo/XS/parsetexi/parser.c (check_valid_nesting_context):
+       Check if @caption or @shortcaption is called in caption context.
+
+       * tp/Texinfo/XS/parsetexi/separator.c (handle_open_brace)
+       Increment nesting_context.footnote for @caption, @shortcaption.
+       * tp/Texinfo/XS/parsetexi/close.c (close_current),
+       * tp/Texinfo/XS/parsetexi/separator.c (handle_close_brace),
+       Decrement nesting_context.footnote for @caption, @shortcaption.
+
 2023-01-21  Gavin Smith <gavinsmith0123@gmail.com>
 
        Indent goto labels
@@ -10,7 +23,6 @@
        Indent goto labels so that they do not appear as the function
        in git diff.
 
-
 2023-01-21  Gavin Smith  <gavinsmith0123@gmail.com>
 
        Nesting context for XS parser
diff --git a/tp/TODO b/tp/TODO
index 3ffd78df80..21478b05cc 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -72,8 +72,10 @@ Some erroneous constructs not already warned against:
  @table in @menu
 
  @caption in @caption
+   -- done in XS parser
 
  nested footnotes
+   -- done in XS parser
 
  @example
  @heading A heading
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index ad28b23fd4..ff47ba88e4 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -284,6 +284,8 @@ close_current (ELEMENT *current,
 
           if (current->cmd == CM_footnote)
             nesting_context.footnote--;
+          if (current->cmd == CM_caption || current->cmd == CM_shortcaption)
+            nesting_context.caption--;
           current = close_brace_command (current, closed_block_command,
                                          interrupting_command);
         }
diff --git a/tp/Texinfo/XS/parsetexi/context_stack.h 
b/tp/Texinfo/XS/parsetexi/context_stack.h
index 321e79d03f..cb92746455 100644
--- a/tp/Texinfo/XS/parsetexi/context_stack.h
+++ b/tp/Texinfo/XS/parsetexi/context_stack.h
@@ -56,6 +56,7 @@ void reset_region_stack (void);
 /* Used to check indirect nesting, e.g. @footnote{@emph{@footnote{...}}} */
 typedef struct {
     int footnote;
+    int caption;
 } NESTING_CONTEXT;
 
 extern NESTING_CONTEXT nesting_context;
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 067f5eeefa..e22951fb0a 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1146,6 +1146,12 @@ check_valid_nesting_context (enum command_id cmd)
     {
       invalid_context = CM_footnote;
     }
+  else if ((cmd == CM_caption || cmd == CM_shortcaption)
+             && nesting_context.caption > 0)
+    {
+      line_warn ("@%s should not appear anywhere inside caption",
+        command_name(cmd));
+    }
 
   if (invalid_context)
     {
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index 4a7694f05e..33e7a163e1 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -67,6 +67,7 @@ handle_open_brace (ELEMENT *current, char **line_inout)
             {
 #define float floatxx
               ELEMENT *float;
+              nesting_context.caption++;
               if (!current->parent->parent
                   || current->parent->parent->cmd != CM_float)
                 {
@@ -254,6 +255,9 @@ handle_close_brace (ELEMENT *current, char **line_inout)
             fatal ("context brace command context expected");
           if (current->parent->cmd == CM_footnote)
             nesting_context.footnote--;
+          else if (current->parent->cmd == CM_caption
+                   || current->parent->cmd == CM_shortcaption)
+            nesting_context.caption--;
         }
       /* determine if trailing spaces are ignored */
       else if (command_data(current->parent->cmd).data == BRACE_arguments)
@@ -534,6 +538,9 @@ handle_close_brace (ELEMENT *current, char **line_inout)
 
           if (closed_command == CM_footnote)
             nesting_context.footnote--;
+          else if (closed_command == CM_caption
+                     || closed_command == CM_shortcaption)
+            nesting_context.caption--;
 
           register_global_command (current->parent);
           current = current->parent->parent;



reply via email to

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