m4-patches
[Top][All Lists]
Advanced

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

FYI: 24-gary-changesyntax-dollar.patch


From: Gary V. Vaughan
Subject: FYI: 24-gary-changesyntax-dollar.patch
Date: Fri, 27 Jun 2003 15:03:02 +0100
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.3) Gecko/20030312

Applied to HEAD.
--
  ())_. Gary V. Vaughan     gary@(oranda.demon.co.uk|gnu.org)
  ( '/  Research Scientist  http://www.oranda.demon.co.uk       ,_())____
  / )=  GNU Hacker          http://www.gnu.org/software/libtool  \'      `&
`(_~)_  Tech' Author        http://sources.redhat.com/autobook   =`---d__/
Index: ChangeLog
from  Gary V. Vaughan  <address@hidden>
        * doc/m4.texinfo (Changesyntax): Document Dollar syntax class.
        * m4/m4module.h (M4__SYNTAX_STRING): New syntax class. Be careful
        not to slow the parser down.
        (M4__IS_STRING): New macro to test string syntax class membership.
        * m4/syntax.c: Adjust docucomment.
        (m4_syntax_create): Add a default M4_SYNTAX_DOLLAR element.
        (m4_syntax_code): Translate `$' -> M4_SYNTAX_DOLLAR.
        * m4/input.c (init_builtin_token): Comment typo.
        (m4__next_token): Comment typo.
        Accept M4_SYNTAX_DOLLAR items into M4_TOKEN_STRING type tokens
        by using the new M4__IS_STRING macro.
        * m4/macro.c (m4_process_macro): Use M4_IS_DOLLAR to test for
        variable references in macro expansions.

Index: doc/m4.texinfo
===================================================================
RCS file: /cvsroot/m4/m4/doc/m4.texinfo,v
retrieving revision 1.16
diff -u -p -u -r1.16 m4.texinfo
--- doc/m4.texinfo 27 Jun 2003 12:18:51 -0000 1.16
+++ doc/m4.texinfo 27 Jun 2003 13:57:22 -0000
@@ -2039,6 +2039,10 @@ Characters that close the argument list 
 Characters that separate the arguments of a macro call.  Default
 is @kbd{,}.
 
address@hidden Dollar
+Characters that can introduce an argument reference in the body of a
+macro.  Default is @kbd{$}.
+
 @item Other
 Characters that have no special syntactical meaning to @code{m4}.
 Default is all characters expect those in the categories above.
@@ -2100,6 +2104,8 @@ Open parenthesis
 Close parenthesis
 @item ,
 Argument separator
address@hidden $
+Dollar
 @item O
 Other
 @item @@
@@ -2171,8 +2177,32 @@ test(a, b, c)
 @end example
 
 @noindent
-It is not yet possible to redefine the @samp{$} used to indicate macro
-arguments in user defined macros.
+It is possible to redefine the @samp{$} used to indicate macro arguments
+in user defined macros.
+
address@hidden
+define(`argref', `Dollar: $#, Question: ?#')
address@hidden
+argref(1, 2, 3)
address@hidden: 3, Question: ?#
+changesyntax(`$?', `O$')
address@hidden
+argref(1,2,3)
address@hidden: $#, Question: 3
address@hidden example
+
address@hidden
+Dollar class syntax elements are copied to the output if there is no
+valid expansion.
+
address@hidden
+define(`escape', `$?`'1$?1?')
address@hidden
+changesyntax(`$?')
address@hidden
+escape(foo)
address@hidden
address@hidden example
 
 Macro calls can be given a @TeX{} or Texinfo like syntax using an
 escape.  If one or more characters are defined as escapes macro names
Index: m4/input.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/input.c,v
retrieving revision 1.29
diff -u -p -u -r1.29 input.c
--- m4/input.c 26 Jun 2003 14:57:32 -0000 1.29
+++ m4/input.c 27 Jun 2003 13:57:25 -0000
@@ -515,7 +515,7 @@ m4_pop_wrapup (void)
   return TRUE;
 }
 
-/* When a BUILTIN token is seen, next_token () uses init_builtin_token
+/* When a BUILTIN token is seen, m4__next_token () uses init_builtin_token
    to retrieve the value of the function pointer.  */
 static void
 init_builtin_token (m4 *context, m4_symbol_value *token)
@@ -718,11 +718,11 @@ m4_input_exit (void)
    is a potential macro name; and M4_TOKEN_SIMPLE for any single character
    that is not a part of any of the previous types.
 
-   M4_next_token () returns the token type, and passes back a pointer to the
-   token data through VALUE.  The token text is collected on the obstack
+   M4__next_token () returns the token type, and passes back a pointer to
+   the token data through VALUE.  The token text is collected on the obstack
    token_stack, which never contains more than one token text at a time.
    The storage pointed to by the fields in VALUE is therefore subject to
-   change the next time next_token () is called.        */
+   change the next time m4__next_token () is called.  */
 m4__token_type
 m4__next_token (m4 *context, m4_symbol_value *token)
 {
@@ -890,11 +890,14 @@ m4__next_token (m4 *context, m4_symbol_v
       {
        obstack_1grow (&token_stack, ch);
 
-       if (M4_IS_OTHER (M4SYNTAX, ch) || M4_IS_NUM (M4SYNTAX, ch))
+       if (M4_IS_OTHER (M4SYNTAX, ch) || M4__IS_STRING (M4SYNTAX, ch))
          {
            while ((ch = next_char(context)) != CHAR_EOF
-                  && (M4_IS_OTHER (M4SYNTAX, ch) || M4_IS_NUM (M4SYNTAX, ch)))
-             obstack_1grow (&token_stack, ch);
+                  && (M4_IS_OTHER (M4SYNTAX, ch)
+                      || M4__IS_STRING (M4SYNTAX, ch)))
+             {
+               obstack_1grow (&token_stack, ch);
+             }
 
            if (ch != CHAR_EOF)
              unget_input(ch);
@@ -918,11 +921,11 @@ m4__next_token (m4 *context, m4_symbol_v
        else
          type = M4_TOKEN_SIMPLE;
       }
-    else                               /* EVERYTHING ELSE */
+    else                               /* EVERYTHING ELSE AGAIN?! */
       {
        obstack_1grow (&token_stack, ch);
 
-       if (M4_IS_OTHER (M4SYNTAX, ch) || M4_IS_NUM (M4SYNTAX, ch))
+       if (M4_IS_OTHER (M4SYNTAX, ch) || M4__IS_STRING (M4SYNTAX, ch))
          type = M4_TOKEN_STRING;
        else if (M4_IS_SPACE (M4SYNTAX, ch))
          type = M4_TOKEN_SPACE;
Index: m4/m4module.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4module.h,v
retrieving revision 1.52
diff -u -p -u -r1.52 m4module.h
--- m4/m4module.h 26 Jun 2003 14:57:32 -0000 1.52
+++ m4/m4module.h 27 Jun 2003 13:57:27 -0000
@@ -335,7 +335,7 @@ extern      boolean          m4_is_syntax_macro_esca
 #define M4_SYNTAX_OPEN         (0x0003)
 #define M4_SYNTAX_CLOSE                (0x0004)
 #define M4_SYNTAX_COMMA                (0x0005)
-#define M4_SYNTAX_DOLLAR       (0x0006) /* not used yet */
+#define M4_SYNTAX_DOLLAR       (0x0006)
 #define M4_SYNTAX_ACTIVE       (0x0007)
 #define M4_SYNTAX_ESCAPE       (0x0008)
 #define M4_SYNTAX_ASSIGN       (0x0009)
@@ -346,6 +346,11 @@ extern     boolean          m4_is_syntax_macro_esca
 #define M4_SYNTAX_NUM          (0x0020)
 #define M4_SYNTAX_ALNUM                (M4_SYNTAX_ALPHA|M4_SYNTAX_NUM)
 
+/* We can OR the valid M4_TOKEN_STRING chars together, since they are
+   carefully chosen not to overlap.  This reduces the number of comparisons
+   the compiled code needs in order to speed up m4__next_token () a bit.  */
+#define M4__SYNTAX_STRING      (M4_SYNTAX_NUM|M4_SYNTAX_DOLLAR)
+
 /* These are bit masks to AND with other categories.
    See input.c for details. */
 #define M4_SYNTAX_LQUOTE       (0x0100)
@@ -381,6 +386,7 @@ extern      boolean          m4_is_syntax_macro_esca
 #define M4_IS_BCOMM(S, C)  ((S)->table[(int)(C)] & M4_SYNTAX_BCOMM)
 #define M4_IS_ECOMM(S, C)  ((S)->table[(int)(C)] & M4_SYNTAX_ECOMM)
 
+#define M4__IS_STRING(S, C) (m4__is_syntax((S), (C), M4__SYNTAX_STRING))
 #define M4_IS_IDENT(S, C)  (M4_IS_OTHER((S),(C))||M4_IS_ALNUM((S),(C)))
 
 
Index: m4/macro.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/macro.c,v
retrieving revision 1.30
diff -u -p -u -r1.30 macro.c
--- m4/macro.c 26 Jun 2003 14:57:32 -0000 1.30
+++ m4/macro.c 27 Jun 2003 13:57:27 -0000
@@ -330,13 +330,15 @@ m4_process_macro (m4 *context, m4_symbol
 
   for (text = m4_get_symbol_text (symbol); *text != '\0';)
     {
-      if (*text != '$')
+      char ch;
+
+      if (!M4_IS_DOLLAR (M4SYNTAX, *text))
        {
          obstack_1grow (obs, *text);
          text++;
          continue;
        }
-      text++;
+      ch = *text++;
       switch (*text)
        {
        case '0': case '1': case '2': case '3': case '4':
@@ -370,7 +372,7 @@ m4_process_macro (m4 *context, m4_symbol
          if (m4_get_no_gnu_extensions_opt (context)
              || !SYMBOL_ARG_SIGNATURE (symbol))
            {
-             obstack_1grow (obs, '$');
+             obstack_1grow (obs, ch);
            }
          else
            {
Index: m4/syntax.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/syntax.c,v
retrieving revision 1.4
diff -u -p -u -r1.4 syntax.c
--- m4/syntax.c 26 Jun 2003 14:57:32 -0000 1.4
+++ m4/syntax.c 27 Jun 2003 13:57:27 -0000
@@ -79,17 +79,17 @@
    M4_SYNTAX_ALPHA     Reads macro name
    M4_SYNTAX_LQUOTE    Reads all until balanced M4_SYNTAX_RQUOTE
 
-   M4_SYNTAX_OTHER     and M4_SYNTAX_NUM
-                       Reads all M4_SYNTAX_OTHER and M4_SYNTAX_NUM
+   M4_SYNTAX_OTHER  }  Reads all M4_SYNTAX_OTHER, M4_SYNTAX_NUM
+   M4_SYNTAX_NUM    }  and M4_SYNTAX_DOLLAR
+   M4_SYNTAX_DOLLAR }
+
    M4_SYNTAX_SPACE     Reads all M4_SYNTAX_SPACE
    M4_SYNTAX_ACTIVE    Returns a single char as a word
    the rest            Returned as a single char
 
-   M4_SYNTAX_DOLLAR is not currently used.  The character $ is treated as a
-   M4_SYNTAX_OTHER.  It could be done, but it will slow next_token () down
-   a bit.  The $ is not really a part of m4's input syntax in the sense
-   that a string is parsed equally whether there is a $ or not.  The
-   character $ is used by convention in user macros.  */
+   The $ is not really a part of m4's input syntax in the sense that a
+   string is parsed equally whether there is a $ or not.  The character
+   $ is used by convention in user macros.  */
 
 static boolean check_is_macro_escaped (m4_syntax_table *syntax);
 static int add_syntax_attribute           (m4_syntax_table *syntax, int ch, 
int code);
@@ -109,6 +109,8 @@ m4_syntax_create (void)
        add_syntax_attribute (syntax, ch, M4_SYNTAX_CLOSE);
       else if (ch == ',')
        add_syntax_attribute (syntax, ch, M4_SYNTAX_COMMA);
+      else if (ch == '$')
+       add_syntax_attribute (syntax, ch, M4_SYNTAX_DOLLAR);
       else if (ch == '=')
        add_syntax_attribute (syntax, ch, M4_SYNTAX_ASSIGN);
       else if (isspace (ch))
@@ -174,9 +176,7 @@ m4_syntax_code (char ch)
     case ',': code = M4_SYNTAX_COMMA;  break;
     case '=': code = M4_SYNTAX_ASSIGN; break;
     case '@': code = M4_SYNTAX_ESCAPE; break;
-#if 0                          /* not yet used */
     case '$': code = M4_SYNTAX_DOLLAR; break;
-#endif
 
     case 'L': case 'l': code = M4_SYNTAX_LQUOTE; break;
     case 'R': case 'r': code = M4_SYNTAX_RQUOTE; break;

reply via email to

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