texinfo-commits
[Top][All Lists]
Advanced

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

[7241] parsetexi update


From: gavinsmith0123
Subject: [7241] parsetexi update
Date: Sun, 3 Jul 2016 14:01:44 +0000 (UTC)

Revision: 7241
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7241
Author:   gavin
Date:     2016-07-03 14:01:44 +0000 (Sun, 03 Jul 2016)
Log Message:
-----------
parsetexi update

Modified Paths:
--------------
    trunk/tp/parsetexi/api.c
    trunk/tp/parsetexi/command_data.txt
    trunk/tp/parsetexi/commands.h
    trunk/tp/parsetexi/context_stack.c
    trunk/tp/parsetexi/element_types.c
    trunk/tp/parsetexi/element_types.h
    trunk/tp/parsetexi/element_types.txt
    trunk/tp/parsetexi/handle_commands.c
    trunk/tp/parsetexi/parser.c
    trunk/tp/parsetexi/parser.h
    trunk/tp/parsetexi/separator.c

Modified: trunk/tp/parsetexi/api.c
===================================================================
--- trunk/tp/parsetexi/api.c    2016-06-26 13:36:28 UTC (rev 7240)
+++ trunk/tp/parsetexi/api.c    2016-07-03 14:01:44 UTC (rev 7241)
@@ -255,6 +255,8 @@
       || e->type == ET_before_item
       || e->type == ET_inter_item
       || e->cmd == CM_TeX
+      || e->type == ET_elided
+      || e->type == ET_elided_block
       || (command_flags(e) & CF_root)
       || (command_data(e->cmd).flags & CF_brace
           && (command_data(e->cmd).data >= 0
@@ -305,12 +307,12 @@
       else
         hv_store (e->hv, "type", strlen ("type"), sv, 0);
 
-      //SvUTF8_on (sv);
-      /* We will have to do something like that, but first we need to make 
sure 
-         the strings we have are in UTF-8 to start with.  This would lead to 
an 
-         unnecessary round trip with "@documentencoding ISO-8859-1" for Info 
-         and plain text output, when we first convert the characters in the 
-         input file to UTF-8, and convert them back again for the output.
+      SvUTF8_on (sv);
+      /* FIXME: Check that the strings we have are in UTF-8 to start with.
+         This would lead to an unnecessary round trip with "@documentencoding 
+         ISO-8859-1" for Info and plain text output, when we first convert the 
+         characters in the input file to UTF-8, and convert them back again 
for 
+         the output.
       
          The alternative is to leave the UTF-8 flag off, and hope that Perl 
          interprets 8-bit encodings like ISO-8859-1 correctly.  See

Modified: trunk/tp/parsetexi/command_data.txt
===================================================================
--- trunk/tp/parsetexi/command_data.txt 2016-06-26 13:36:28 UTC (rev 7240)
+++ trunk/tp/parsetexi/command_data.txt 2016-07-03 14:01:44 UTC (rev 7241)
@@ -329,13 +329,13 @@
 acronym                brace   2
 
 # inline format command
-inlineraw              brace,inline    BRACE_inline
-inlinefmt              brace,inline    BRACE_inline
-inlinefmtifelse                brace,inline    BRACE_inline
+inlineraw              brace,inline    2
+inlinefmt              brace,inline    2
+inlinefmtifelse                brace,inline    3
 
 # inline conditional commands
-inlineifclear          brace,inline    BRACE_inline
-inlineifset            brace,inline    BRACE_inline
+inlineifclear          brace,inline    2
+inlineifset            brace,inline    2
 
 email                  brace   2
 

Modified: trunk/tp/parsetexi/commands.h
===================================================================
--- trunk/tp/parsetexi/commands.h       2016-06-26 13:36:28 UTC (rev 7240)
+++ trunk/tp/parsetexi/commands.h       2016-07-03 14:01:44 UTC (rev 7241)
@@ -107,5 +107,4 @@
 #define BRACE_context -1 /* Can enclose paragraph breaks. */
 #define BRACE_accent -2
 #define BRACE_style -3
-#define BRACE_inline -4
-#define BRACE_other -5
+#define BRACE_other -4

Modified: trunk/tp/parsetexi/context_stack.c
===================================================================
--- trunk/tp/parsetexi/context_stack.c  2016-06-26 13:36:28 UTC (rev 7240)
+++ trunk/tp/parsetexi/context_stack.c  2016-07-03 14:01:44 UTC (rev 7241)
@@ -67,7 +67,8 @@
 }
 
 
-/* the valid regions are 'titlepage', 'copying', and 'documentdescription' */
+/* The valid regions are 'titlepage', 'copying', and 'documentdescription'.
+   This stack isn't used that much. */
 
 static ELEMENT **region_stack;
 static size_t region_top; /* One above last pushed region. */

Modified: trunk/tp/parsetexi/element_types.c
===================================================================
--- trunk/tp/parsetexi/element_types.c  2016-06-26 13:36:28 UTC (rev 7240)
+++ trunk/tp/parsetexi/element_types.c  2016-07-03 14:01:44 UTC (rev 7241)
@@ -58,5 +58,7 @@
 "bracketed_def_content",
 "bracketed_multitable_prototype",
 "row_prototype",
+"elided",
+"elided_block",
 
 };

Modified: trunk/tp/parsetexi/element_types.h
===================================================================
--- trunk/tp/parsetexi/element_types.h  2016-06-26 13:36:28 UTC (rev 7240)
+++ trunk/tp/parsetexi/element_types.h  2016-07-03 14:01:44 UTC (rev 7241)
@@ -59,6 +59,8 @@
 ET_bracketed_def_content,
 ET_bracketed_multitable_prototype,
 ET_row_prototype,
+ET_elided,
+ET_elided_block,
 };
 
 extern char *element_type_names[];

Modified: trunk/tp/parsetexi/element_types.txt
===================================================================
--- trunk/tp/parsetexi/element_types.txt        2016-06-26 13:36:28 UTC (rev 
7240)
+++ trunk/tp/parsetexi/element_types.txt        2016-07-03 14:01:44 UTC (rev 
7241)
@@ -84,3 +84,7 @@
 bracketed_multitable_prototype
 row_prototype
 
+# for unexpanded parts of conditionals
+elided
+elided_block
+

Modified: trunk/tp/parsetexi/handle_commands.c
===================================================================
--- trunk/tp/parsetexi/handle_commands.c        2016-06-26 13:36:28 UTC (rev 
7240)
+++ trunk/tp/parsetexi/handle_commands.c        2016-07-03 14:01:44 UTC (rev 
7241)
@@ -756,6 +756,19 @@
     add_expanded_format ("info");
 }
 
+int
+format_expanded_p (char *format)
+{
+  int i;
+  for (i = 0; i < sizeof (expanded_formats)/sizeof (*expanded_formats);
+       i++)
+    {
+      if (!strcmp (format, expanded_formats[i].format))
+        return expanded_formats[i].expandedp;
+    }
+  return 0;
+}
+
 /* line 4632 */
 /* A command name has been read that starts a multiline block, which should
    end in @end <command name>.  The block will be processed until 
@@ -938,7 +951,6 @@
           block = new_element (ET_NONE);
 
           block->cmd = cmd;
-          block->line_nr = line_nr;
           add_to_element_contents (current, block);
           current = block;
         }
@@ -951,6 +963,31 @@
           else if (command_data(cmd).flags & CF_format_raw)
             {
               push_context (ct_rawpreformatted);
+              if (!format_expanded_p (command_name(cmd)))
+                {
+                  ELEMENT *e;
+                  enum command_id dummy;
+                  char *line_dummy;
+
+                  e = new_element (ET_elided_block);
+                  add_to_element_contents (current, e);
+                  line_dummy = line;
+                  while (!is_end_current_command (current,
+                                                  &line_dummy, &dummy))
+                    {
+                      line = new_line ();
+                      if (!line)
+                        abort (); // TODO
+                      line_dummy = line;
+                    }
+                  e = new_element (ET_empty_line_after_command);
+                  text_append_n (&e->text, "\n", 1);
+                  add_to_element_contents (current, e);
+
+                  e = new_element (ET_empty_line);
+                  add_to_element_contents (current, e);
+                  goto funexit;
+                }
             }
 
           // 4775
@@ -1024,6 +1061,7 @@
 
           }
         } /* 4827 */
+      block->line_nr = line_nr;
       mark_and_warn_invalid (cmd, invalid_parent, block);
       register_global_command (cmd, block);
       start_empty_line_after_command (current, &line, block);

Modified: trunk/tp/parsetexi/parser.c
===================================================================
--- trunk/tp/parsetexi/parser.c 2016-06-26 13:36:28 UTC (rev 7240)
+++ trunk/tp/parsetexi/parser.c 2016-07-03 14:01:44 UTC (rev 7241)
@@ -61,7 +61,7 @@
   if (!isalnum (*q))
     return 0; /* Invalid. */
 
-  while (isalnum (*q) || *q == '-')
+  while (isalnum (*q) || *q == '-' || *q == '_')
     q++;
   ret = strndup (p, q - p);
   p = q;
@@ -574,6 +574,9 @@
   trimmed = new_element (ET_NONE);
   trimmed->parent_type = route_not_in_tree;
 
+  if (original->contents.number == 0)
+    return trimmed;
+
   i = 1;
   t = original->contents.list[0]->type;
   if (t != ET_empty_line_after_command
@@ -1303,7 +1306,7 @@
             }
           else if ((outer_flags & CF_brace // full text
                    && (command_data(outer).data == BRACE_style
-                       || command_data(outer).data == BRACE_inline))
+                       || (outer_flags & CF_inline)))
                    || outer == CM_center // full line
                    || outer == CM_exdent
                    || outer == CM_item

Modified: trunk/tp/parsetexi/parser.h
===================================================================
--- trunk/tp/parsetexi/parser.h 2016-06-26 13:36:28 UTC (rev 7240)
+++ trunk/tp/parsetexi/parser.h 2016-07-03 14:01:44 UTC (rev 7241)
@@ -71,6 +71,7 @@
                                      ELEMENT *command);
 ELEMENT *trim_spaces_comment_from_content (ELEMENT *original);
 ELEMENT *begin_paragraph (ELEMENT *current);
+int format_expanded_p (char *format);
 
 extern const char *whitespace_chars, *whitespace_chars_except_newline;
 extern const char *digit_chars;

Modified: trunk/tp/parsetexi/separator.c
===================================================================
--- trunk/tp/parsetexi/separator.c      2016-06-26 13:36:28 UTC (rev 7240)
+++ trunk/tp/parsetexi/separator.c      2016-07-03 14:01:44 UTC (rev 7241)
@@ -179,11 +179,18 @@
         {
           current->type = ET_brace_command_arg;
 
+          if (command_data(command).flags & CF_inline)
+            {
+              // 4956
+
+              if (command == CM_inlineraw)
+                push_context (ct_inlineraw);
+            }
           /* Commands which are said to take a positive number of arguments
              disregard leading and trailing whitespace.  In 
              'handle_close_brace', the 'brace_command_contents' array
              is set.  */
-          if (command_data(command).data > 0)
+          else if (command_data(command).data > 0)
             {
               ELEMENT *e;
               e = new_element (ET_empty_spaces_before_argument);
@@ -193,10 +200,6 @@
               add_extra_element (current->parent,
                                      "spaces_before_argument", e);
             }
-          else if (command_data(command).data == BRACE_inline)
-            {
-              // 4956
-            }
         }
       debug ("OPENED");
     }
@@ -232,7 +235,6 @@
   else if (current_context() == ct_math
            || current_context() == ct_rawpreformatted
            || current_context() == ct_inlineraw)
-    //     || ignore_global_commands () - whatever that is
     {
       ELEMENT *b = new_element (ET_bracketed);
       b->line_nr = line_nr;
@@ -272,8 +274,7 @@
           /* The Perl code here checks that the popped context and the
              parent command match as strings. */
         }
-      else if (command_data(current->parent->cmd).data > 0 /* sic */
-               || command_data(current->parent->cmd).data == BRACE_inline)
+      else if (command_data(current->parent->cmd).data > 0) /* sic */
         {
           // 5033
           /* @inline* always have end spaces considered as normal text */
@@ -371,14 +372,19 @@
                || closed_command == CM_abbr
                || closed_command == CM_acronym)
         { // 5129
-          /* TODO: For @abbr and @acronym, keep track of whether an expansion
-             for the abbreviation has been given.  This is used in the HTML
-             output for the <abbr title> attribute.  Or we could just move
-             the code to HTML.pm. */
+          if (current->parent->cmd == CM_inlineraw)
+            {
+              if (ct_inlineraw != pop_context ())
+                abort ();
+            }
+          if (current->parent->args.number == 0)
+            {
+              line_warn ("@%s missing first argument",
+                         command_name(current->parent->cmd));
+            }
         }
       else if (closed_command == CM_errormsg) // 5173
         {
-          // if (!ignore_global_commands)
           line_error (text_convert (current));
         }
       else if (closed_command == CM_U)
@@ -565,12 +571,133 @@
   type = current->type;
   current = current->parent;
 
-#if 0
-  /* TODO 5244 */
-  if (current is an inline command (like inlineraw) all brace commands))
+  // 5244
+  if (command_flags(current) & CF_inline)
     {
+      KEY_PAIR *k;
+      int expandp = 0;
+      debug ("THE INLINE PART");
+      k = lookup_extra_key (current, "format");
+      if (!k)
+        {
+          KEY_PAIR *k;
+          char *inline_type = 0;
+          k = lookup_extra_key (current, "brace_command_contents");
+          if (k)
+            {
+              ELEMENT *args = 0, *arg = 0;
+              int i;
+              args = (ELEMENT *) k->value;
+              if (!args)
+                goto inline_no_arg;
+              if (args->contents.number == 0)
+                goto inline_no_arg;
+              arg = args->contents.list[0];
+              if (!arg)
+                goto inline_no_arg; /* Possible if registered as 'undef'. */
+              /* Find text argument.
+                 TODO: Should we use trim_spaces_comment_from_content instead?
+                 Or use a function for this? */
+              for (i = 0; i < arg->contents.number; i++)
+                {
+                  enum element_type t = arg->contents.list[i]->type;
+                  if (arg->contents.list[i]->text.end > 0
+                      && t != ET_empty_line_after_command
+                      && t != ET_empty_spaces_after_command
+                      && t != ET_empty_spaces_before_argument
+                      && t != ET_empty_space_at_end_def_bracketed
+                      && t != ET_empty_spaces_after_close_brace)
+                    break;
+                }
+              if (i != arg->contents.number)
+                {
+                  inline_type = arg->contents.list[i]->text.text;
+                }
+            }
+
+
+          debug ("INLINE <%s>", inline_type);
+          if (!inline_type)
+            {
+inline_no_arg:
+              /* Condition is missing */
+              debug ("INLINE COND MISSING");
+            }
+          else if (current->cmd == CM_inlineraw
+              || current->cmd == CM_inlinefmt
+              || current->cmd == CM_inlinefmtifelse)
+            {
+              if (format_expanded_p (inline_type))
+                {
+                  expandp = 1;
+                  add_extra_string (current, "expand_index", "1");
+                }
+              else
+                expandp = 0;
+            }
+          else if (current->cmd == CM_inlineifset
+                   || current->cmd == CM_inlineifclear)
+            {
+              expandp = 0;
+              if (fetch_value (current, inline_type, strlen (inline_type)))
+                expandp = 1;
+              if (current->cmd == CM_inlineifclear)
+                expandp = !expandp;
+            }
+          else
+            expandp = 0;
+
+          add_extra_string (current, "format", inline_type);
+
+          /* Skip first argument for a false @inlinefmtifelse */
+          if (!expandp && current->cmd == CM_inlinefmtifelse)
+            {
+              // TODO
+            }
+          counter_dec (&count_remaining_args);
+          expandp = 1;
+        }
+      else if (current->cmd == CM_inlinefmtifelse)
+        {
+          /* Second art of @inlinefmtifelse when condition is true.  Discard
+             second argument. */
+          expandp = 0;
+        }
+
+      /* If this command is not being expanded, add a dummy argument, and
+         scan forward to the closing brace. */
+      if (!expandp)
+        {
+          ELEMENT *e;
+          int brace_count = 1;
+          e = new_element (ET_elided);
+          add_to_element_args (current, e);
+          while (brace_count > 0)
+            {
+              line += strcspn (line, "{}");
+              switch (*line)
+                {
+                case '{':
+                  brace_count++;
+                  break;
+                case '}':
+                  brace_count--;
+                  break;
+                default:
+                  line = next_text ();
+                  if (!line)
+                    {
+                      /* ERROR - unbalanced brace */
+                    }
+                  continue;
+                }
+              line++;
+            }
+          current = last_args_child (current);
+          line--;  /* on '}' */
+          goto funexit;
+        }
     }
-#endif
 
   counter_dec (&count_remaining_args);
   new_arg = new_element (type);
@@ -580,6 +707,7 @@
   text_append (&e->text, ""); /* See comment in parser.c:merge_text */
   add_to_element_contents (current, e);
   
+funexit:
   *line_inout = line;
   return current;
 }




reply via email to

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