texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Nesting context for XS parser


From: Gavin D. Smith
Subject: branch master updated: Nesting context for XS parser
Date: Sat, 21 Jan 2023 11:24:55 -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 fee19527ca Nesting context for XS parser
fee19527ca is described below

commit fee19527ca13d4db9ef2930f0902b6f6ab133692
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sat Jan 21 16:24:46 2023 +0000

    Nesting context for XS parser
    
    * tp/Texinfo/XS/parsetexi/context_stack.h (NESTING_CONTEXT):
    Define new structure.
    * tp/Texinfo/XS/parsetexi/context_stack.c (nesting_context): Define.
    * tp/Texinfo/XS/parsetexi/api.c (reset_parser_except_conf):
    Wipe nesting_context.
    
    * tp/Texinfo/XS/parsetexi/parser.c (check_valid_nesting_context):
    New function to check nesting_context.
    (process_remaining_on_line) <@-command>:
    Call it together with check_valid_nesting.
    
    * tp/Texinfo/XS/parsetexi/separator.c (handle_open_brace)
    Increment nesting_context.footnote for @footnote.
    * tp/Texinfo/XS/parsetexi/close.c (close_current),
    * tp/Texinfo/XS/parsetexi/separator.c (handle_close_brace),
    Decrement nesting_context.footnote for @footnote.
---
 ChangeLog                                          | 21 +++++++++++++++++++++
 tp/Texinfo/XS/parsetexi/api.c                      |  1 +
 tp/Texinfo/XS/parsetexi/close.c                    |  3 +++
 tp/Texinfo/XS/parsetexi/context_stack.c            |  9 +++++++++
 tp/Texinfo/XS/parsetexi/context_stack.h            |  9 +++++++++
 tp/Texinfo/XS/parsetexi/parser.c                   | 22 +++++++++++++++++++++-
 tp/Texinfo/XS/parsetexi/separator.c                | 11 ++++++++++-
 .../info_tests/nested_footnotes_separate.pl        | 12 +++++++++++-
 8 files changed, 85 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 61ada4eed1..2b16489992 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2023-01-21  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       Nesting context for XS parser
+
+       * tp/Texinfo/XS/parsetexi/context_stack.h (NESTING_CONTEXT):
+       Define new structure.
+       * tp/Texinfo/XS/parsetexi/context_stack.c (nesting_context): Define.
+       * tp/Texinfo/XS/parsetexi/api.c (reset_parser_except_conf):
+       Wipe nesting_context.
+
+       * tp/Texinfo/XS/parsetexi/parser.c (check_valid_nesting_context):
+       New function to check nesting_context.
+       (process_remaining_on_line) <@-command>:
+       Call it together with check_valid_nesting.
+
+       * tp/Texinfo/XS/parsetexi/separator.c (handle_open_brace)
+       Increment nesting_context.footnote for @footnote.
+       * tp/Texinfo/XS/parsetexi/close.c (close_current),
+       * tp/Texinfo/XS/parsetexi/separator.c (handle_close_brace),
+       Decrement nesting_context.footnote for @footnote.
+
 2023-01-19  Gavin Smith  <gavinsmith0123@gmail.com>
 
        * tp/Texinfo/XS/parsetexi/commands.h: Remove unused flags
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 7210b8c5e9..9e69040c78 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -129,6 +129,7 @@ reset_parser_except_conf (void)
   wipe_errors ();
   reset_context_stack ();
   reset_region_stack ();
+  memset (&nesting_context, 0, sizeof (nesting_context));
   reset_floats ();
   wipe_global_info ();
   set_input_encoding ("utf-8");
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 141fe2672a..3dff0e03e5 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -281,6 +281,9 @@ close_current (ELEMENT *current,
               else if (pop_context () != ct_brace_command)
                 fatal ("context brace command context expected");
             }
+
+          if (current->cmd == CM_footnote)
+            nesting_context.footnote--;
           current = close_brace_command (current, closed_block_command,
                                          interrupting_command);
         }
diff --git a/tp/Texinfo/XS/parsetexi/context_stack.c 
b/tp/Texinfo/XS/parsetexi/context_stack.c
index 0ecd1dec6e..e05a9b5829 100644
--- a/tp/Texinfo/XS/parsetexi/context_stack.c
+++ b/tp/Texinfo/XS/parsetexi/context_stack.c
@@ -140,6 +140,15 @@ current_region (void)
   return region_stack[region_top - 1];
 }
 
+
+
+
+
+/* Command nesting context. */
+
+NESTING_CONTEXT nesting_context;
+
+
 
 /* used for @kbd */
 int
diff --git a/tp/Texinfo/XS/parsetexi/context_stack.h 
b/tp/Texinfo/XS/parsetexi/context_stack.h
index 3d8444e657..321e79d03f 100644
--- a/tp/Texinfo/XS/parsetexi/context_stack.h
+++ b/tp/Texinfo/XS/parsetexi/context_stack.h
@@ -52,5 +52,14 @@ enum command_id current_region_cmd (void);
 void reset_region_stack (void);
 
 
+
+/* Used to check indirect nesting, e.g. @footnote{@emph{@footnote{...}}} */
+typedef struct {
+    int footnote;
+} NESTING_CONTEXT;
+
+extern NESTING_CONTEXT nesting_context;
+
+
 int in_preformatted_context_not_menu(void);
 #endif
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index bdb8d78904..ef26491e9f 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -1138,6 +1138,23 @@ check_valid_nesting (ELEMENT *current, enum command_id 
cmd)
     }
 }
 
+void
+check_valid_nesting_context (enum command_id cmd)
+{
+  enum command_id invalid_context = 0;
+  if (cmd == CM_footnote && nesting_context.footnote > 0)
+    {
+      invalid_context = CM_footnote;
+    }
+
+  if (invalid_context)
+    {
+      line_warn ("@%s should not appear anywhere inside @%s",
+        command_name(cmd),
+        command_name(invalid_context));
+    }
+}
+
 /* *LINEP is a pointer into the line being processed.  It is advanced past any
    bytes processed.
    Return STILL_MORE_TO_PROCESS when there is more to process on the line
@@ -1913,7 +1930,10 @@ value_invalid:
         }
 
       if (current->parent)
-        check_valid_nesting (current, cmd);
+        {
+          check_valid_nesting (current, cmd);
+          check_valid_nesting_context (cmd);
+        }
 
       if (def_line_continuation)
         {
diff --git a/tp/Texinfo/XS/parsetexi/separator.c 
b/tp/Texinfo/XS/parsetexi/separator.c
index d94e61ba4a..0aa3385556 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -99,7 +99,11 @@ handle_open_brace (ELEMENT *current, char **line_inout)
                     }
                 }
 #undef float
-        }
+            }
+          else if (command == CM_footnote)
+            {
+              nesting_context.footnote++;
+            }
 
           /* Add to context stack. */
           switch (command)
@@ -248,6 +252,8 @@ handle_close_brace (ELEMENT *current, char **line_inout)
             }
           else if (pop_context () != ct_brace_command)
             fatal ("context brace command context expected");
+          if (current->parent->cmd == CM_footnote)
+            nesting_context.footnote--;
         }
       /* determine if trailing spaces are ignored */
       else if (command_data(current->parent->cmd).data == BRACE_arguments)
@@ -526,6 +532,9 @@ handle_close_brace (ELEMENT *current, char **line_inout)
           closed_command = current->parent->cmd;
           counter_pop (&count_remaining_args);
 
+          if (closed_command == CM_footnote)
+            nesting_context.footnote--;
+
           register_global_command (current->parent);
           current = current->parent->parent;
           if (close_preformatted_command(closed_command))
diff --git a/tp/t/results/info_tests/nested_footnotes_separate.pl 
b/tp/t/results/info_tests/nested_footnotes_separate.pl
index 4450af8fef..e175959c53 100644
--- a/tp/t/results/info_tests/nested_footnotes_separate.pl
+++ b/tp/t/results/info_tests/nested_footnotes_separate.pl
@@ -200,7 +200,17 @@ $result_menus{'nested_footnotes_separate'} = {
   'info' => {}
 };
 
-$result_errors{'nested_footnotes_separate'} = [];
+$result_errors{'nested_footnotes_separate'} = [
+  {
+    'error_line' => 'warning: @footnote should not appear anywhere inside 
@footnote
+',
+    'file_name' => '',
+    'line_nr' => 6,
+    'macro' => '',
+    'text' => '@footnote should not appear anywhere inside @footnote',
+    'type' => 'warning'
+  }
+];
 
 
 $result_floats{'nested_footnotes_separate'} = {};



reply via email to

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