texinfo-commits
[Top][All Lists]
Advanced

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

[6088] parsetexi more complete line argument parsing


From: Gavin D. Smith
Subject: [6088] parsetexi more complete line argument parsing
Date: Sat, 31 Jan 2015 21:53:22 +0000

Revision: 6088
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6088
Author:   gavin
Date:     2015-01-31 21:53:20 +0000 (Sat, 31 Jan 2015)
Log Message:
-----------
parsetexi more complete line argument parsing

Modified Paths:
--------------
    trunk/parsetexi/ChangeLog
    trunk/parsetexi/command_data.txt
    trunk/parsetexi/end_line.c
    trunk/parsetexi/parser.c
    trunk/parsetexi/parser.h

Modified: trunk/parsetexi/ChangeLog
===================================================================
--- trunk/parsetexi/ChangeLog   2015-01-31 18:18:39 UTC (rev 6087)
+++ trunk/parsetexi/ChangeLog   2015-01-31 21:53:20 UTC (rev 6088)
@@ -1,5 +1,13 @@
-2015-01-24  Gavin Smith  <address@hidden>
+2015-01-31  Gavin Smith  <address@hidden>
 
+       * command_data.txt: Specify argument types of the other "misc" 
+       commands.
+       * end_linec (parse_line_command_args): More complete 
+       implementation.
+       * parser.c (digit_chars): New variable.
+
+2015-01-30  Gavin Smith  <address@hidden>
+
        * end_line.c (end_line_misc_line): Set "misc_content" key as 
        intended, instead of "misc_args".
        <sectioning commands>: Set "level" extra value.

Modified: trunk/parsetexi/command_data.txt
===================================================================
--- trunk/parsetexi/command_data.txt    2015-01-31 18:18:39 UTC (rev 6087)
+++ trunk/parsetexi/command_data.txt    2015-01-31 21:53:20 UTC (rev 6088)
@@ -47,15 +47,15 @@
 bye                    misc            MISC_skipline
 end                    misc            MISC_text
 # set, clear
-set                    misc
-clear                  misc
-unmacro                misc
+set                    misc            MISC_special
+clear                  misc            MISC_special
+unmacro                misc            MISC_special
 # comments
 c                      misc            MISC_lineraw
 comment                misc            MISC_lineraw
 # special
-definfoenclose         misc
-alias                  misc
+definfoenclose         misc            3
+alias                  misc            2
 # number of arguments is not known in advance.
 columnfractions                misc            1
 # file names
@@ -68,8 +68,8 @@
 contents                       misc            MISC_skipline
 shortcontents                  misc            MISC_skipline
 summarycontents                        misc            MISC_skipline
-insertcopying                  misc
-clickstyle                     misc
+insertcopying                  misc            MISC_noarg
+clickstyle                     misc            MISC_special
 # more relevant in preamble
 setcontentsaftertitlepage      misc            MISC_skipline
 setshortcontentsaftertitlepage misc            MISC_skipline
@@ -80,26 +80,26 @@
 pagesizes                      misc            MISC_line
 # or one? 200mm,150mm 11.5in
 finalout                       misc            MISC_skipline
-paragraphindent                        misc
+paragraphindent                        misc            1
 # or a number and forbids anything else on the line
-firstparagraphindent           misc
-frenchspacing                  misc
-codequoteundirected            misc
-codequotebacktick              misc
-xrefautomaticsectiontitle      misc
-deftypefnnewline               misc
-fonttextsize                   misc
-allowcodebreaks                        misc
-exampleindent                  misc
-footnotestyle                  misc
-urefbreakstyle                 misc
+firstparagraphindent           misc            1
+frenchspacing                  misc            1
+codequoteundirected            misc            1
+codequotebacktick              misc            1
+xrefautomaticsectiontitle      misc            1
+deftypefnnewline               misc            1
+fonttextsize                   misc            1
+allowcodebreaks                        misc            1
+exampleindent                  misc            1
+footnotestyle                  misc            1
+urefbreakstyle                 misc            1
 afourpaper                     misc            MISC_skipline
 afivepaper                     misc            MISC_skipline
 afourlatex                     misc            MISC_skipline
 afourwide                      misc            MISC_skipline
-headings                       misc
+headings                       misc            1
 # interacts with setchapternewpage
-setchapternewpage              misc
+setchapternewpage              misc            1
 
 # only relevant in TeX, and special
 everyheading                   misc            MISC_lineraw
@@ -110,18 +110,18 @@
 oddfooting                     misc            MISC_lineraw
 
 smallbook                      misc            MISC_skipline
-syncodeindex                   misc
-synindex                       misc
-defindex                       misc
-defcodeindex                   misc
-documentlanguage               misc    MISC_text
-kbdinputstyle                  misc
-everyheadingmarks              misc
-everyfootingmarks              misc
-evenheadingmarks               misc
-oddheadingmarks                        misc
-evenfootingmarks               misc
-oddfootingmarks                        misc
+syncodeindex                   misc            2
+synindex                       misc            2
+defindex                       misc            1
+defcodeindex                   misc            1
+documentlanguage               misc            MISC_text
+kbdinputstyle                  misc            1
+everyheadingmarks              misc            1
+everyfootingmarks              misc            1
+evenheadingmarks               misc            1
+oddheadingmarks                        misc            1
+evenfootingmarks               misc            1
+oddfootingmarks                        misc            1
 # not valid for info (should be in @iftex)
 cropmarks                      misc            MISC_skipline
 
@@ -136,28 +136,28 @@
 author                         misc            MISC_line
 subtitle                       misc            MISC_line
 title                          misc            MISC_line
-sp                             misc
+sp                             misc            1
 page                           misc            MISC_skipline
-need                           misc
+need                           misc            1
 # formatting
-noindent                       misc
-indent                         misc
+noindent                       misc            MISC_skipspace
+indent                         misc            MISC_skipspace
 exdent                         misc            MISC_line
 headitem                       misc            MISC_skipspace
 item                           misc            MISC_skipspace
 itemx                          misc            MISC_skipspace
 tab                            misc            MISC_skipspace
 # only valid in heading or footing
-thischapter                    misc
-thischaptername                        misc
-thischapternum                 misc
-thisfile                       misc
-thispage                       misc
-thistitle                      misc
+thischapter                    misc            MISC_noarg
+thischaptername                        misc            MISC_noarg
+thischapternum                 misc            MISC_noarg
+thisfile                       misc            MISC_noarg
+thispage                       misc            MISC_noarg
+thistitle                      misc            MISC_noarg
 # not valid for info (should be in @iftex)
 vskip                          misc            MISC_lineraw
 # obsolete @-commands.
-refill                         misc
+refill                         misc            MISC_noarg
 # Remove spaces and end of lines after the 
 # commands? If no, they can lead to empty lines
 # TODO: Check what these two are.

Modified: trunk/parsetexi/end_line.c
===================================================================
--- trunk/parsetexi/end_line.c  2015-01-31 18:18:39 UTC (rev 6087)
+++ trunk/parsetexi/end_line.c  2015-01-31 21:53:20 UTC (rev 6088)
@@ -60,6 +60,12 @@
 ELEMENT *
 parse_line_command_args (ELEMENT *line_command)
 {
+#define ADD_ARG(string) { \
+    ELEMENT *new = new_element (ET_NONE); \
+    text_append (&new->text, string); \
+    add_to_element_contents (line_args, new); \
+}
+
   ELEMENT *line_args;
   ELEMENT *arg = line_command->args.list[0];
   ELEMENT *argarg = 0;
@@ -108,9 +114,18 @@
   switch (command)
     {
     case CM_alias:
+      {
+        /* @alias NEW = EXISTING */
+        break;
+      }
     case CM_definfoenclose:
+      {
+        /* @definfoenclose phoo,//,\\ */
+        break;
+      }
     case CM_columnfractions:
       {
+        /*  @multitable @columnfractions .33 .33 .33 */
         ELEMENT *new;
         char *p = line, *q;
         while (1)
@@ -129,17 +144,32 @@
         break;
       }
     case CM_sp:
+      {
+        /* Argument is at least one digit. */
+        if (strchr (digit_chars, *line)
+            && !*(line + 1 + strspn (line + 1, digit_chars)))
+          {
+            ADD_ARG (line)
+          }
+        else
+          abort ();
+        break;
+      }
     case CM_defindex:
     case CM_defcodeindex:
+      {
+        /* TODO: Alphanumeric + hyphens */
+        break;
+      }
     case CM_synindex:
     case CM_syncodeindex:
+      {
+        /* synindex FROM TO */
+        break;
+      }
     case CM_printindex:
       {
-        /* TODO: Check and interpret argument. */
-        ELEMENT *new;
-        new = new_element (ET_NONE);
-        text_append (&new->text, line);
-        add_to_element_contents (line_args, new);
+        ADD_ARG (line);
         break;
       }
     case CM_everyheadingmarks:
@@ -148,14 +178,105 @@
     case CM_oddheadingmarks:
     case CM_evenfootingmarks:
     case CM_oddfootingmarks:
+      {
+        if (!strcmp (line, "top") || !strcmp (line, "bottom"))
+          {
+            ADD_ARG (line);
+          }
+        else
+          abort ();
+
+        break;
+      }
     case CM_fonttextsize:
+      {
+        if (!strcmp (line, "10") || !strcmp (line, "11"))
+          {
+            ADD_ARG (line);
+          }
+        else
+          abort ();
+        break;
+      }
     case CM_footnotestyle:
+      {
+        if (!strcmp (line, "separate") || !strcmp (line, "end"))
+          {
+            ADD_ARG(line)
+          }
+        else
+          abort ();
+        break;
+      }
     case CM_setchapternewpage:
+      {
+        if (!strcmp (line, "on") || !strcmp (line, "off")
+            || !strcmp (line, "odd"))
+          {
+            ADD_ARG(line)
+          }
+        else
+          abort ();
+        break;
+      }
     case CM_need:
+      {
+        /* valid: 2, 2., .2, 2.2 */
+
+        int valid = 1;
+        char *pline = line;
+        char *first_digits = 0;
+        char *second_digits = 0;
+        
+        if (line[0] == '\0')
+          valid = 0;
+        else
+          {
+            if (strchr (digit_chars, *pline))
+              pline = first_digits = line + strspn (line, digit_chars);
+
+            if (*pline == '.')
+              {
+                pline++;
+                if (strchr (digit_chars, *pline))
+                  {
+                    pline = second_digits = pline + strspn (pline, 
+                                                            digit_chars);
+                  }
+              }
+
+            if (*pline /* Bytes remaining at end of argument. */
+                || (!first_digits && !second_digits)) /* Need digits either 
+                                                         before or after the 
+                                                         decimal point. */
+              valid = 0;
+          }
+
+        if (valid)
+          ADD_ARG(line)
+        else
+          abort ();
+
+        break;
+      }
     case CM_paragraphindent:
+      {
+        break;
+      }
     case CM_firstparagraphindent:
+      {
+        if (!strcmp (line, "none") || !strcmp (line, "insert"))
+          {
+            ADD_ARG(line)
+          }
+        else
+          abort ();
+
+        break;
+      }
     case CM_exampleindent:
       {
+        break;
       }
     case CM_frenchspacing:
     case CM_xrefautomaticsectiontitle:
@@ -163,16 +284,65 @@
     case CM_codequotebacktick:
     case CM_deftypefnnewline:
       {
-        /* Argument is either "on" or "off". */
+        if (!strcmp (line, "on") || !strcmp (line, "off"))
+          {
+            ADD_ARG(line)
+          }
+        else
+          abort ();
+
+        break;
       }
     case CM_kbdinputstyle:
+      {
+        if (!strcmp (line, "code") || !strcmp (line, "example")
+            || !strcmp (line, "distinct"))
+          {
+            ADD_ARG(line)
+          }
+        else
+          abort ();
+        break;
+      }
     case CM_allowcodebreaks:
+      {
+        if (!strcmp (line, "true") || !strcmp (line, "false"))
+          {
+            ADD_ARG(line)
+          }
+        else
+          abort ();
+        break;
+      }
     case CM_urefbreakstyle:
+      {
+        if (!strcmp (line, "after") || !strcmp (line, "before")
+            || !strcmp (line, "none"))
+          {
+            ADD_ARG(line)
+          }
+        else
+          abort ();
+        break;
+      }
     case CM_headings:
+      {
+        if (!strcmp (line, "off") || !strcmp (line, "on")
+            || !strcmp (line, "double") || !strcmp (line, "singleafter")
+            || !strcmp (line, "doubleafter"))
+          {
+            ADD_ARG(line)
+          }
+        else
+          abort ();
+        break;
+      }
     default:
       ;
     }
   return line_args;
+
+#undef ADD_ARG
 }
 
 // 2257

Modified: trunk/parsetexi/parser.c
===================================================================
--- trunk/parsetexi/parser.c    2015-01-31 18:18:39 UTC (rev 6087)
+++ trunk/parsetexi/parser.c    2015-01-31 21:53:20 UTC (rev 6088)
@@ -36,6 +36,7 @@
 /* Utility functions */
 
 const char *whitespace_chars = " \t\f\r\n";
+const char *digit_chars = "0123456789";
 
 // [^\S\r\n] in Perl
 const char *whitespace_chars_except_newline = " \t\f";

Modified: trunk/parsetexi/parser.h
===================================================================
--- trunk/parsetexi/parser.h    2015-01-31 18:18:39 UTC (rev 6087)
+++ trunk/parsetexi/parser.h    2015-01-31 21:53:20 UTC (rev 6088)
@@ -44,6 +44,7 @@
 void start_empty_line_after_command (ELEMENT *current, char **line_inout);
 
 extern const char *whitespace_chars, *whitespace_chars_except_newline;
+extern const char *digit_chars;
 
 extern ELEMENT *current_node;
 extern ELEMENT *current_section;




reply via email to

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