1/*
2 * This file is part of flex.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE.
22 */
23
24/* The point of this test is to be sure our M4 madness does not
25 * interfere with user code. I particular, we are looking
26 * for instances of M4 quotes, [[ and ]], in here to make it through the flex
27 * machinery unscathed.
28 */
29
30/* sect 1     [ 1 ]           TEST_XXX */
31/* sect 1    [[ 2 ]]          TEST_XXX */
32/* sect 1   [[[ 3 ]]]         TEST_XXX */
33/* sect 1  [[[[ 4 ]]]]        TEST_XXX */
34/* sect 1  ]] unmatched [[    TEST_XXX */
35
36%{
37/* A template scanner file to build "scanner.c". */
38#include <stdio.h>
39#include <stdlib.h>
40#include "config.h"
41#include <assert.h>
42/*#include "parser.h" */
43
44/* sect 1 block    [ 1 ]        TEST_XXX */
45/* sect 1 block   [[ 2 ]]       TEST_XXX */
46/* sect 1 block  [[[ 3 ]]]      TEST_XXX */
47/* sect 1 block [[[[ 4 ]]]]     TEST_XXX */
48/* sect 1 block ]] unmatched [[ TEST_XXX */
49
50static int a[1] = {0};
51static int b[1] = {0};
52static int c[1] = {0};
53
54static int foo (int i){
55    return a[b[c[i]]]; /* sect 1 code  TEST_XXX */
56}
57%}
58
59%option 8bit prefix="test"
60%option nounput nomain noyywrap noinput
61%option warn
62
63
64%%
65  /* indented code    [ 1 ] */
66  /* indented code   [[ 2 ]] */
67  /* indented code  [[[ 3 ]]] */
68  /* indented code [[[[ 4 ]]]] */
69  /* indented code ]] unmatched [[ */
70%{
71// non-indented code    [ 1 ]
72// non-indented code   [[ 2 ]]
73// non-indented code  [[[ 3 ]]]
74// non-indented code [[[[ 4 ]]]]
75%}
76
77a       /* action comment    [ 1 ]          */ ;
78b       /* action comment   [[ 2 ]]         */ ;
79c       /* action comment  [[[ 3 ]]]        */ ;
80d       /* action comment [[[[ 4 ]]]]       */ ;
81e       /* action comment ]] unmatched [[   */ ;
82f       return 1+foo(a[b[c[0]]]);
83.|\n    {
84
85#if 0
86               action code     [ 1 ]        TEST_XXX
87               action code    [[ 2 ]]       TEST_XXX
88               action code   [[[ 3 ]]]      TEST_XXX
89               action code  [[[[ 4 ]]]]     TEST_XXX
90               action code  ]] unmatched [[ TEST_XXX
91#endif
92            /* action block    [ 1 ]        TEST_XXX */
93            /* action block   [[ 2 ]]       TEST_XXX */
94            /* action block  [[[ 3 ]]]      TEST_XXX */
95            /* action block [[[[ 4 ]]]]     TEST_XXX */
96            /* action block ]] unmatched [[ TEST_XXX */
97            assert(!strcmp("[[ 2 ]]", "[""[ 2 ]""]"));
98            assert(!strcmp("[[[ 3 ]]]", "[""[""[ 3 ]""]""]"));
99            assert(!strcmp("[[[[ 4 ]]]]", "[""[""[""[ 4 ]""]""]""]"));
100            assert(!strcmp("]] unmatched [[", "]""] unmatched [""["));
101            assert(!strcmp("]]m4_define(alpha, beta)[[",
102             "]""]m4_""define(alpha, beta)[""["));
103            return 1+foo(a[b[c[0]]]);  /*   TEST_XXX */
104         }
105%%
106
107/* sect 3     [ 1 ]        TEST_XXX */
108/* sect 3    [[ 2 ]]       TEST_XXX */
109/* sect 3   [[[ 3 ]]]      TEST_XXX */
110/* sect 3  [[[[ 4 ]]]]     TEST_XXX */
111/* sect 3  ]] unmatched [[ TEST_XXX */
112static int bar (int i){
113    return c[b[a[i]]]; /* sect 3 code TEST_XXX */
114}
115int main(void);
116
117#define CONCAT_IDENTS(a, b) a##b
118int
119main (void)
120{
121    /* m4_m4exit(100) */
122    FILE *M4_YY_NOT_IN_HEADER = stdin;
123    yyin = CONCAT_IDENTS(M4_, YY_NOT_IN_HEADER);
124    yyout = stdout;
125    while (yylex())
126        ;
127    assert(!strcmp("YY_G( alpha)", "Y""Y_G( alpha)"));
128    printf("TEST RETURNING OK.\n");
129    return bar(0);
130}
131
132