1 /* GNU m4 -- A simple macro processor
3 Copyright (C) 1989-1994, 2004-2013 Free Software Foundation, Inc.
5 This file is part of GNU M4.
7 GNU M4 is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU M4 is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 /* Handling of different input sources, and lexical analysis. */
27 /* Unread input can be either files, that should be read (eg. included
28 files), strings, which should be rescanned (eg. macro expansion text),
29 or quoted macro definitions (as returned by the builtin "defn").
30 Unread input are organised in a stack, implemented with an obstack.
31 Each input source is described by a "struct input_block". The obstack
32 is "current_input". The top of the input stack is "isp".
34 The macro "m4wrap" places the text to be saved on another input
35 stack, on the obstack "wrapup_stack", whose top is "wsp". When EOF
36 is seen on normal input (eg, when "current_input" is empty), input is
37 switched over to "wrapup_stack", and the original "current_input" is
38 freed. A new stack is allocated for "wrapup_stack", which will
39 accept any text produced by calls to "m4wrap" from within the
40 wrapped text. This process of shuffling "wrapup_stack" to
41 "current_input" can continue indefinitely, even generating infinite
42 loops (e.g. "define(`f',`m4wrap(`f')')f"), without memory leaks.
44 Pushing new input on the input stack is done by push_file (),
45 push_string (), push_wrapup () (for wrapup text), and push_macro ()
46 (for macro definitions). Because macro expansion needs direct access
47 to the current input obstack (for optimisation), push_string () are
48 split in two functions, push_string_init (), which returns a pointer
49 to the current input stack, and push_string_finish (), which return a
50 pointer to the final text. The input_block *next is used to manage
51 the coordination between the different push routines.
53 The current file and line number are stored in two global
54 variables, for use by the error handling functions in m4.c. Macro
55 expansion wants to report the line where a macro name was detected,
56 rather than where it finished collecting arguments. This also
57 applies to text resulting from macro expansions. So each input
58 block maintains its own notion of the current file and line, and
59 swapping between input blocks updates the global variables
62 #ifdef ENABLE_CHANGEWORD
68 INPUT_STRING, /* String resulting from macro expansion. */
69 INPUT_FILE, /* File from command line or include. */
70 INPUT_MACRO /* Builtin resulting from defn. */
73 typedef enum input_type input_type;
77 struct input_block *prev; /* previous input_block on the input stack */
78 input_type type; /* see enum values */
79 const char *file; /* file where this input is from */
80 int line; /* line where this input is from */
85 char *string; /* remaining string value */
86 char *end; /* terminating NUL of string */
88 u_s; /* INPUT_STRING */
91 FILE *fp; /* input file handle */
92 bool_bitfield end : 1; /* true if peek has seen EOF */
93 bool_bitfield close : 1; /* true if we should close file on pop */
94 bool_bitfield advance : 1; /* track previous start_of_input_line */
97 builtin_func *func; /* pointer to macro's function */
102 typedef struct input_block input_block;
105 /* Current input file name. */
106 const char *current_file;
108 /* Current input line number. */
111 /* Obstack for storing individual tokens. */
112 static struct obstack token_stack;
114 /* Obstack for storing file names. */
115 static struct obstack file_names;
117 /* Wrapup input stack. */
118 static struct obstack *wrapup_stack;
120 /* Current stack, from input or wrapup. */
121 static struct obstack *current_input;
123 /* Bottom of token_stack, for obstack_free. */
124 static void *token_bottom;
126 /* Pointer to top of current_input. */
127 static input_block *isp;
129 /* Pointer to top of wrapup_stack. */
130 static input_block *wsp;
132 /* Aux. for handling split push_string (). */
133 static input_block *next;
135 /* Flag for next_char () to increment current_line. */
136 static bool start_of_input_line;
138 /* Flag for next_char () to recognize change in input block. */
139 static bool input_change;
141 #define CHAR_EOF 256 /* character return on EOF */
142 #define CHAR_MACRO 257 /* character return for MACRO token */
152 #ifdef ENABLE_CHANGEWORD
154 # define DEFAULT_WORD_REGEXP "[_a-zA-Z][_a-zA-Z0-9]*"
156 static struct re_pattern_buffer word_regexp;
157 static int default_word_regexp;
158 static struct re_registers regs;
160 #else /* ! ENABLE_CHANGEWORD */
161 # define default_word_regexp 1
162 #endif /* ! ENABLE_CHANGEWORD */
165 static const char *token_type_string (token_type);
169 /*-------------------------------------------------------------------.
170 | push_file () pushes an input file on the input stack, saving the |
171 | current file name and line number. If next is non-NULL, this push |
172 | invalidates a call to push_string_init (), whose storage is |
173 | consequently released. If CLOSE_WHEN_DONE, then close FP after |
175 `-------------------------------------------------------------------*/
178 push_file (FILE *fp, const char *title, bool close_when_done)
184 obstack_free (current_input, next);
188 if (debug_level & DEBUG_TRACE_INPUT)
189 DEBUG_MESSAGE1 ("input read from %s", title);
191 i = (input_block *) obstack_alloc (current_input,
192 sizeof (struct input_block));
193 i->type = INPUT_FILE;
194 i->file = (char *) obstack_copy0 (&file_names, title, strlen (title));
199 i->u.u_f.end = false;
200 i->u.u_f.close = close_when_done;
201 i->u.u_f.advance = start_of_input_line;
202 output_current_line = -1;
208 /*---------------------------------------------------------------.
209 | push_macro () pushes a builtin macro's definition on the input |
210 | stack. If next is non-NULL, this push invalidates a call to |
211 | push_string_init (), whose storage is consequently released. |
212 `---------------------------------------------------------------*/
215 push_macro (builtin_func *func)
221 obstack_free (current_input, next);
225 i = (input_block *) obstack_alloc (current_input,
226 sizeof (struct input_block));
227 i->type = INPUT_MACRO;
228 i->file = current_file;
229 i->line = current_line;
237 /*------------------------------------------------------------------.
238 | First half of push_string (). The pointer next points to the new |
240 `------------------------------------------------------------------*/
243 push_string_init (void)
247 M4ERROR ((warning_status, 0,
248 "INTERNAL ERROR: recursive push_string!"));
252 next = (input_block *) obstack_alloc (current_input,
253 sizeof (struct input_block));
254 next->type = INPUT_STRING;
255 next->file = current_file;
256 next->line = current_line;
258 return current_input;
261 /*-------------------------------------------------------------------.
262 | Last half of push_string (). If next is now NULL, a call to |
263 | push_file () has invalidated the previous call to push_string_init |
264 | (), so we just give up. If the new object is void, we do not push |
265 | it. The function push_string_finish () returns a pointer to the |
266 | finished object. This pointer is only for temporary use, since |
267 | reading the next token might release the memory used for the |
269 `-------------------------------------------------------------------*/
272 push_string_finish (void)
274 const char *ret = NULL;
279 if (obstack_object_size (current_input) > 0)
281 size_t len = obstack_object_size (current_input);
282 obstack_1grow (current_input, '\0');
283 next->u.u_s.string = (char *) obstack_finish (current_input);
284 next->u.u_s.end = next->u.u_s.string + len;
287 ret = isp->u.u_s.string; /* for immediate use only */
291 obstack_free (current_input, next); /* people might leave garbage on it. */
296 /*------------------------------------------------------------------.
297 | The function push_wrapup () pushes a string on the wrapup stack. |
298 | When the normal input stack gets empty, the wrapup stack will |
299 | become the input stack, and push_string () and push_file () will |
300 | operate on wrapup_stack. Push_wrapup should be done as |
301 | push_string (), but this will suffice, as long as arguments to |
302 | m4_m4wrap () are moderate in size. |
303 `------------------------------------------------------------------*/
306 push_wrapup (const char *s)
308 size_t len = strlen (s);
310 i = (input_block *) obstack_alloc (wrapup_stack,
311 sizeof (struct input_block));
313 i->type = INPUT_STRING;
314 i->file = current_file;
315 i->line = current_line;
316 i->u.u_s.string = (char *) obstack_copy0 (wrapup_stack, s, len);
317 i->u.u_s.end = i->u.u_s.string + len;
322 /*-------------------------------------------------------------------.
323 | The function pop_input () pops one level of input sources. If the |
324 | popped input_block is a file, current_file and current_line are |
325 | reset to the saved values before the memory for the input_block is |
327 `-------------------------------------------------------------------*/
332 input_block *tmp = isp->prev;
341 if (debug_level & DEBUG_TRACE_INPUT)
344 DEBUG_MESSAGE2 ("input reverted to %s, line %d",
345 tmp->file, tmp->line);
347 DEBUG_MESSAGE ("input exhausted");
350 if (ferror (isp->u.u_f.fp))
352 M4ERROR ((warning_status, 0, "read error"));
353 if (isp->u.u_f.close)
354 fclose (isp->u.u_f.fp);
355 retcode = EXIT_FAILURE;
357 else if (isp->u.u_f.close && fclose (isp->u.u_f.fp) == EOF)
359 M4ERROR ((warning_status, errno, "error reading file"));
360 retcode = EXIT_FAILURE;
362 start_of_input_line = isp->u.u_f.advance;
363 output_current_line = -1;
367 M4ERROR ((warning_status, 0,
368 "INTERNAL ERROR: input stack botch in pop_input ()"));
371 obstack_free (current_input, isp);
372 next = NULL; /* might be set in push_string_init () */
378 /*-------------------------------------------------------------------.
379 | To switch input over to the wrapup stack, main calls pop_wrapup |
380 | (). Since wrapup text can install new wrapup text, pop_wrapup () |
381 | returns false when there is no wrapup text on the stack, and true |
383 `-------------------------------------------------------------------*/
389 obstack_free (current_input, NULL);
390 free (current_input);
394 /* End of the program. Free all memory even though we are about
395 to exit, since it makes leak detection easier. */
396 obstack_free (&token_stack, NULL);
397 obstack_free (&file_names, NULL);
398 obstack_free (wrapup_stack, NULL);
400 #ifdef ENABLE_CHANGEWORD
401 regfree (&word_regexp);
402 #endif /* ENABLE_CHANGEWORD */
406 current_input = wrapup_stack;
407 wrapup_stack = (struct obstack *) xmalloc (sizeof (struct obstack));
408 obstack_init (wrapup_stack);
417 /*-------------------------------------------------------------------.
418 | When a MACRO token is seen, next_token () uses init_macro_token () |
419 | to retrieve the value of the function pointer. |
420 `-------------------------------------------------------------------*/
423 init_macro_token (token_data *td)
425 if (isp->type != INPUT_MACRO)
427 M4ERROR ((warning_status, 0,
428 "INTERNAL ERROR: bad call to init_macro_token ()"));
432 TOKEN_DATA_TYPE (td) = TOKEN_FUNC;
433 TOKEN_DATA_FUNC (td) = isp->u.func;
437 /*-----------------------------------------------------------------.
438 | Low level input is done a character at a time. The function |
439 | peek_input () is used to look at the next character in the input |
440 | stream. At any given time, it reads from the input_block on the |
441 | top of the current input stack. |
442 `-----------------------------------------------------------------*/
448 input_block *block = isp;
458 ch = to_uchar (block->u.u_s.string[0]);
464 ch = getc (block->u.u_f.fp);
467 ungetc (ch, block->u.u_f.fp);
470 block->u.u_f.end = true;
477 M4ERROR ((warning_status, 0,
478 "INTERNAL ERROR: input stack botch in peek_input ()"));
485 /*-------------------------------------------------------------------.
486 | The function next_char () is used to read and advance the input to |
487 | the next character. It also manages line numbers for error |
488 | messages, so they do not get wrong, due to lookahead. The token |
489 | consisting of a newline alone is taken as belonging to the line it |
490 | ends, and the current line number is not incremented until the |
491 | next character is read. 99.9% of all calls will read from a |
492 | string, so factor that out into a macro for speed. |
493 `-------------------------------------------------------------------*/
495 #define next_char() \
496 (isp && isp->type == INPUT_STRING && isp->u.u_s.string[0] \
498 ? to_uchar (*isp->u.u_s.string++) \
517 current_file = isp->file;
518 current_line = isp->line;
519 input_change = false;
525 ch = to_uchar (*isp->u.u_s.string++);
531 if (start_of_input_line)
533 start_of_input_line = false;
534 current_line = ++isp->line;
537 /* If stdin is a terminal, calling getc after peek_input
538 already called it would make the user have to hit ^D
540 ch = isp->u.u_f.end ? EOF : getc (isp->u.u_f.fp);
544 start_of_input_line = true;
550 pop_input (); /* INPUT_MACRO input sources has only one token */
554 M4ERROR ((warning_status, 0,
555 "INTERNAL ERROR: input stack botch in next_char ()"));
559 /* End of input source --- pop one level. */
564 /*-------------------------------------------------------------------.
565 | skip_line () simply discards all immediately following characters, |
566 | upto the first newline. It is only used from m4_dnl (). |
567 `-------------------------------------------------------------------*/
573 const char *file = current_file;
574 int line = current_line;
576 while ((ch = next_char ()) != CHAR_EOF && ch != '\n')
579 /* current_file changed to "" if we see CHAR_EOF, use the
580 previous value we stored earlier. */
581 M4ERROR_AT_LINE ((warning_status, 0, file, line,
582 "Warning: end of file treated as newline"));
583 /* On the rare occasion that dnl crosses include file boundaries
584 (either the input file did not end in a newline, or changeword
585 was used), calling next_char can update current_file and
586 current_line, and that update will be undone as we return to
587 expand_macro. This informs next_char to fix things again. */
588 if (file != current_file || line != current_line)
593 /*------------------------------------------------------------------.
594 | This function is for matching a string against a prefix of the |
595 | input stream. If the string matches the input and consume is |
596 | true, the input is discarded; otherwise any characters read are |
597 | pushed back again. The function is used only when multicharacter |
598 | quotes or comment delimiters are used. |
599 `------------------------------------------------------------------*/
602 match_input (const char *s, bool consume)
604 int n; /* number of characters matched */
605 int ch; /* input character */
610 if (ch != to_uchar (*s))
611 return false; /* fail */
617 return true; /* short match */
621 for (n = 1, t = s++; peek_input () == to_uchar (*s++); )
625 if (*s == '\0') /* long match */
634 /* Failed or shouldn't consume, push back input. */
636 struct obstack *h = push_string_init ();
638 /* `obstack_grow' may be macro evaluating its arg 1 several times. */
639 obstack_grow (h, t, n);
641 push_string_finish ();
645 /*--------------------------------------------------------------------.
646 | The macro MATCH() is used to match a string S against the input. |
647 | The first character is handled inline, for speed. Hopefully, this |
648 | will not hurt efficiency too much when single character quotes and |
649 | comment delimiters are used. If CONSUME, then CH is the result of |
650 | next_char, and a successful match will discard the matched string. |
651 | Otherwise, CH is the result of peek_char, and the input stream is |
652 | effectively unchanged. |
653 `--------------------------------------------------------------------*/
655 #define MATCH(ch, s, consume) \
656 (to_uchar ((s)[0]) == (ch) \
658 && ((s)[1] == '\0' || (match_input ((s) + (consume), consume))))
661 /*--------------------------------------------------------.
662 | Initialize input stacks, and quote/comment characters. |
663 `--------------------------------------------------------*/
671 current_input = (struct obstack *) xmalloc (sizeof (struct obstack));
672 obstack_init (current_input);
673 wrapup_stack = (struct obstack *) xmalloc (sizeof (struct obstack));
674 obstack_init (wrapup_stack);
676 obstack_init (&file_names);
678 /* Allocate an object in the current chunk, so that obstack_free
679 will always work even if the first token parsed spills to a new
681 obstack_init (&token_stack);
682 obstack_alloc (&token_stack, 1);
683 token_bottom = obstack_base (&token_stack);
689 start_of_input_line = false;
691 lquote.string = xstrdup (DEF_LQUOTE);
692 lquote.length = strlen (lquote.string);
693 rquote.string = xstrdup (DEF_RQUOTE);
694 rquote.length = strlen (rquote.string);
695 bcomm.string = xstrdup (DEF_BCOMM);
696 bcomm.length = strlen (bcomm.string);
697 ecomm.string = xstrdup (DEF_ECOMM);
698 ecomm.length = strlen (ecomm.string);
700 #ifdef ENABLE_CHANGEWORD
701 set_word_regexp (user_word_regexp);
706 /*------------------------------------------------------------------.
707 | Functions for setting quotes and comment delimiters. Used by |
708 | m4_changecom () and m4_changequote (). Pass NULL if the argument |
709 | was not present, to distinguish from an explicit empty string. |
710 `------------------------------------------------------------------*/
713 set_quotes (const char *lq, const char *rq)
715 free (lquote.string);
716 free (rquote.string);
718 /* POSIX states that with 0 arguments, the default quotes are used.
719 POSIX XCU ERN 112 states that behavior is implementation-defined
720 if there was only one argument, or if there is an empty string in
721 either position when there are two arguments. We allow an empty
722 left quote to disable quoting, but a non-empty left quote will
723 always create a non-empty right quote. See the texinfo for what
724 some other implementations do. */
730 else if (!rq || (*lq && !*rq))
733 lquote.string = xstrdup (lq);
734 lquote.length = strlen (lquote.string);
735 rquote.string = xstrdup (rq);
736 rquote.length = strlen (rquote.string);
740 set_comment (const char *bc, const char *ec)
745 /* POSIX requires no arguments to disable comments. It requires
746 empty arguments to be used as-is, but this is counter to
747 traditional behavior, because a non-null begin and null end makes
748 it impossible to end a comment. An aardvark has been filed:
749 http://www.opengroup.org/austin/mailarchives/ag-review/msg02168.html
750 This implementation assumes the aardvark will be approved. See
751 the texinfo for what some other implementations do. */
754 else if (!ec || (*bc && !*ec))
757 bcomm.string = xstrdup (bc);
758 bcomm.length = strlen (bcomm.string);
759 ecomm.string = xstrdup (ec);
760 ecomm.length = strlen (ecomm.string);
763 #ifdef ENABLE_CHANGEWORD
766 set_word_regexp (const char *regexp)
769 struct re_pattern_buffer new_word_regexp;
771 if (!*regexp || STREQ (regexp, DEFAULT_WORD_REGEXP))
773 default_word_regexp = true;
777 /* Dry run to see whether the new expression is compilable. */
778 init_pattern_buffer (&new_word_regexp, NULL);
779 msg = re_compile_pattern (regexp, strlen (regexp), &new_word_regexp);
780 regfree (&new_word_regexp);
784 M4ERROR ((warning_status, 0,
785 "bad regular expression `%s': %s", regexp, msg));
789 /* If compilation worked, retry using the word_regexp struct. We
790 can't rely on struct assigns working, so redo the compilation.
791 The fastmap can be reused between compilations, and will be freed
792 by the final regfree. */
793 if (!word_regexp.fastmap)
794 word_regexp.fastmap = xcharalloc (UCHAR_MAX + 1);
795 msg = re_compile_pattern (regexp, strlen (regexp), &word_regexp);
797 re_set_registers (&word_regexp, ®s, regs.num_regs, regs.start, regs.end);
798 if (re_compile_fastmap (&word_regexp))
801 default_word_regexp = false;
804 #endif /* ENABLE_CHANGEWORD */
807 /*--------------------------------------------------------------------.
808 | Parse and return a single token from the input stream. A token |
809 | can either be TOKEN_EOF, if the input_stack is empty; it can be |
810 | TOKEN_STRING for a quoted string; TOKEN_WORD for something that is |
811 | a potential macro name; and TOKEN_SIMPLE for any single character |
812 | that is not a part of any of the previous types. If LINE is not |
813 | NULL, set *LINE to the line where the token starts. |
815 | Next_token () return the token type, and passes back a pointer to |
816 | the token data through TD. The token text is collected on the |
817 | obstack token_stack, which never contains more than one token text |
818 | at a time. The storage pointed to by the fields in TD is |
819 | therefore subject to change the next time next_token () is called. |
820 `--------------------------------------------------------------------*/
823 next_token (token_data *td, int *line)
828 #ifdef ENABLE_CHANGEWORD
830 char *orig_text = NULL;
835 obstack_free (&token_stack, token_bottom);
839 /* Can't consume character until after CHAR_MACRO is handled. */
844 xfprintf (stderr, "next_token -> EOF\n");
849 if (ch == CHAR_MACRO)
851 init_macro_token (td);
854 xfprintf (stderr, "next_token -> MACDEF (%s)\n",
855 find_builtin_by_addr (TOKEN_DATA_FUNC (td))->name);
860 next_char (); /* Consume character we already peeked at. */
862 *line = current_line;
863 if (MATCH (ch, bcomm.string, true))
865 obstack_grow (&token_stack, bcomm.string, bcomm.length);
866 while ((ch = next_char ()) != CHAR_EOF
867 && !MATCH (ch, ecomm.string, true))
868 obstack_1grow (&token_stack, ch);
870 obstack_grow (&token_stack, ecomm.string, ecomm.length);
872 /* current_file changed to "" if we see CHAR_EOF, use the
873 previous value we stored earlier. */
874 M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, *line,
875 "ERROR: end of file in comment"));
879 else if (default_word_regexp && (isalpha (ch) || ch == '_'))
881 obstack_1grow (&token_stack, ch);
882 while ((ch = peek_input ()) != CHAR_EOF && (isalnum (ch) || ch == '_'))
884 obstack_1grow (&token_stack, ch);
890 #ifdef ENABLE_CHANGEWORD
892 else if (!default_word_regexp && word_regexp.fastmap[ch])
894 obstack_1grow (&token_stack, ch);
900 obstack_1grow (&token_stack, ch);
901 startpos = re_search (&word_regexp,
902 (char *) obstack_base (&token_stack),
903 obstack_object_size (&token_stack), 0, 0,
906 regs.end [0] != (regoff_t) obstack_object_size (&token_stack))
908 *(((char *) obstack_base (&token_stack)
909 + obstack_object_size (&token_stack)) - 1) = '\0';
915 obstack_1grow (&token_stack, '\0');
916 orig_text = (char *) obstack_finish (&token_stack);
918 if (regs.start[1] != -1)
919 obstack_grow (&token_stack,orig_text + regs.start[1],
920 regs.end[1] - regs.start[1]);
922 obstack_grow (&token_stack, orig_text,regs.end[0]);
927 #endif /* ENABLE_CHANGEWORD */
929 else if (!MATCH (ch, lquote.string, true))
946 obstack_1grow (&token_stack, ch);
950 bool fast = lquote.length == 1 && rquote.length == 1;
954 /* Try scanning a buffer first. */
955 const char *buffer = (isp && isp->type == INPUT_STRING
956 ? isp->u.u_s.string : NULL);
957 if (buffer && *buffer)
959 size_t len = isp->u.u_s.end - buffer;
960 const char *p = buffer;
963 p = (char *) memchr2 (p, *lquote.string, *rquote.string,
966 while (p && fast && (*p++ == *rquote.string
967 ? --quote_level : ++quote_level));
972 assert (!quote_level);
973 obstack_grow (&token_stack, buffer, p - buffer - 1);
974 isp->u.u_s.string += p - buffer;
977 obstack_grow (&token_stack, buffer, p - buffer);
979 isp->u.u_s.string += p - buffer + 1;
983 obstack_grow (&token_stack, buffer, len);
984 isp->u.u_s.string += len;
988 /* Fall back to a byte. */
992 /* current_file changed to "" if we see CHAR_EOF, use
993 the previous value we stored earlier. */
994 M4ERROR_AT_LINE ((EXIT_FAILURE, 0, file, *line,
995 "ERROR: end of file in string"));
997 if (MATCH (ch, rquote.string, true))
999 if (--quote_level == 0)
1001 obstack_grow (&token_stack, rquote.string, rquote.length);
1003 else if (MATCH (ch, lquote.string, true))
1006 obstack_grow (&token_stack, lquote.string, lquote.length);
1009 obstack_1grow (&token_stack, ch);
1011 type = TOKEN_STRING;
1014 obstack_1grow (&token_stack, '\0');
1016 TOKEN_DATA_TYPE (td) = TOKEN_TEXT;
1017 TOKEN_DATA_TEXT (td) = (char *) obstack_finish (&token_stack);
1018 #ifdef ENABLE_CHANGEWORD
1019 if (orig_text == NULL)
1020 orig_text = TOKEN_DATA_TEXT (td);
1021 TOKEN_DATA_ORIG_TEXT (td) = orig_text;
1024 xfprintf (stderr, "next_token -> %s (%s)\n",
1025 token_type_string (type), TOKEN_DATA_TEXT (td));
1030 /*-----------------------------------------------.
1031 | Peek at the next token from the input stream. |
1032 `-----------------------------------------------*/
1038 int ch = peek_input ();
1044 else if (ch == CHAR_MACRO)
1046 result = TOKEN_MACDEF;
1048 else if (MATCH (ch, bcomm.string, false))
1050 result = TOKEN_STRING;
1052 else if ((default_word_regexp && (isalpha (ch) || ch == '_'))
1053 #ifdef ENABLE_CHANGEWORD
1054 || (! default_word_regexp && word_regexp.fastmap[ch])
1055 #endif /* ENABLE_CHANGEWORD */
1058 result = TOKEN_WORD;
1060 else if (MATCH (ch, lquote.string, false))
1062 result = TOKEN_STRING;
1068 result = TOKEN_OPEN;
1071 result = TOKEN_COMMA;
1074 result = TOKEN_CLOSE;
1077 result = TOKEN_SIMPLE;
1081 xfprintf (stderr, "peek_token -> %s\n", token_type_string (result));
1082 #endif /* DEBUG_INPUT */
1090 token_type_string (token_type t)
1116 print_token (const char *s, token_type t, token_data *td)
1118 xfprintf (stderr, "%s: ", s);
1125 xfprintf (stderr, "char:");
1129 xfprintf (stderr, "word:");
1133 xfprintf (stderr, "string:");
1137 xfprintf (stderr, "macro: %p\n", TOKEN_DATA_FUNC (td));
1141 xfprintf (stderr, "eof\n");
1144 xfprintf (stderr, "\t\"%s\"\n", TOKEN_DATA_TEXT (td));
1147 static void M4_GNUC_UNUSED
1153 while ((t = next_token (&td, NULL)) != TOKEN_EOF)
1154 print_token ("lex", t, &td);
1156 #endif /* DEBUG_INPUT */