xref: /minix3/external/bsd/flex/dist/tests/test-ccl/scanner.l (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*357f1050SThomas Veerman /*
2*357f1050SThomas Veerman  * This file is part of flex.
3*357f1050SThomas Veerman  *
4*357f1050SThomas Veerman  * Redistribution and use in source and binary forms, with or without
5*357f1050SThomas Veerman  * modification, are permitted provided that the following conditions
6*357f1050SThomas Veerman  * are met:
7*357f1050SThomas Veerman  *
8*357f1050SThomas Veerman  * 1. Redistributions of source code must retain the above copyright
9*357f1050SThomas Veerman  *    notice, this list of conditions and the following disclaimer.
10*357f1050SThomas Veerman  * 2. Redistributions in binary form must reproduce the above copyright
11*357f1050SThomas Veerman  *    notice, this list of conditions and the following disclaimer in the
12*357f1050SThomas Veerman  *    documentation and/or other materials provided with the distribution.
13*357f1050SThomas Veerman  *
14*357f1050SThomas Veerman  * Neither the name of the University nor the names of its contributors
15*357f1050SThomas Veerman  * may be used to endorse or promote products derived from this software
16*357f1050SThomas Veerman  * without specific prior written permission.
17*357f1050SThomas Veerman  *
18*357f1050SThomas Veerman  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19*357f1050SThomas Veerman  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20*357f1050SThomas Veerman  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21*357f1050SThomas Veerman  * PURPOSE.
22*357f1050SThomas Veerman  */
23*357f1050SThomas Veerman 
24*357f1050SThomas Veerman %{
25*357f1050SThomas Veerman /* A template scanner file to build "scanner.c". */
26*357f1050SThomas Veerman #include <stdio.h>
27*357f1050SThomas Veerman #include <stdlib.h>
28*357f1050SThomas Veerman #include "config.h"
29*357f1050SThomas Veerman /*#include "parser.h" */
30*357f1050SThomas Veerman 
31*357f1050SThomas Veerman #define err_abort() do{printf("ERROR: flex line %d. input line %d.\n", __LINE__, yylineno); abort();} while(0)
32*357f1050SThomas Veerman #define a_ok()      do{printf("OK: flex line %d. input line %d.\n", __LINE__, yylineno); return 1;}while(0)
33*357f1050SThomas Veerman %}
34*357f1050SThomas Veerman 
35*357f1050SThomas Veerman %option 8bit outfile="scanner.c" prefix="test"
36*357f1050SThomas Veerman %option nounput nomain noyywrap
37*357f1050SThomas Veerman %option warn
38*357f1050SThomas Veerman 
39*357f1050SThomas Veerman 
40*357f1050SThomas Veerman %%
41*357f1050SThomas Veerman 
42*357f1050SThomas Veerman ^"^alpha:"[[:^alpha:]]+@alpha@\n        printf("OK: %s", yytext); ++yylineno; return 1;
43*357f1050SThomas Veerman ^"^digit:"[[:^digit:]]+@digit@\n        printf("OK: %s", yytext); ++yylineno; return 1;
44*357f1050SThomas Veerman ^"^alnum:"[[:^alnum:]]+@alnum@\n        printf("OK: %s", yytext); ++yylineno; return 1;
45*357f1050SThomas Veerman ^"^upper:"[[:^upper:]]+@upper@\n        printf("OK: %s", yytext); ++yylineno; return 1;
46*357f1050SThomas Veerman ^"^lower:"[[:^lower:]]+@lower@\n        printf("OK: %s", yytext); ++yylineno; return 1;
47*357f1050SThomas Veerman ^"^space:"[[:^space:]]+@space@\n        printf("OK: %s", yytext); ++yylineno; return 1;
48*357f1050SThomas Veerman ^"^blank:"[[:^blank:]]+@blank@\n        printf("OK: %s", yytext); ++yylineno; return 1;
49*357f1050SThomas Veerman ^"^punct:"[[:^punct:]]+@punct@\n        printf("OK: %s", yytext); ++yylineno; return 1;
50*357f1050SThomas Veerman ^"^cntrl:"[[:^cntrl:]]+@cntrl@\n        printf("OK: %s", yytext); ++yylineno; return 1;
51*357f1050SThomas Veerman ^"^xdigit:"[[:^xdigit:]]+@xdigit@\n      printf("OK: %s", yytext); ++yylineno; return 1;
52*357f1050SThomas Veerman 
53*357f1050SThomas Veerman ^"a-d:"[[:alpha:]]{-}[[:digit:]]+@a-d@\n  printf("OK: %s", yytext); ++yylineno; return 1;
54*357f1050SThomas Veerman ^"l-xyz:"([[:lower:]]{-}[xyz])+@l-xyz@\n    printf("OK: %s", yytext); ++yylineno; return 1;
55*357f1050SThomas Veerman ^"abcd-bc:"([abcd]{-}[bc])+@abcd-bc@\n          printf("OK: %s", yytext); ++yylineno; return 1;
56*357f1050SThomas Veerman ^"abcde-b-c:"([abcde]{-}[b]{-}[c])+@abcde-b-c@\n    printf("OK: %s", yytext); ++yylineno; return 1;
57*357f1050SThomas Veerman ^"^XY-^XYZ:"([^XY]{-}[^XYZ])+@^XY-^XYZ@\n    printf("OK: %s", yytext); ++yylineno; return 1;
58*357f1050SThomas Veerman 
59*357f1050SThomas Veerman ^"a+d:"([[:alpha:]]{+}[[:digit:]])+"@a+d@"\n    a_ok();
60*357f1050SThomas Veerman ^"a-u+Q:"([[:alpha:]]{-}[[:upper:]]{+}[Q])+"@a-u+Q@"\n    a_ok();
61*357f1050SThomas Veerman 
62*357f1050SThomas Veerman ^"ia:"(?i:a)+@ia@\n                          printf("OK: %s", yytext); ++yylineno; return 1;
63*357f1050SThomas Veerman ^"iabc:"(?i:abc)+@iabc@\n                    printf("OK: %s", yytext); ++yylineno; return 1;
64*357f1050SThomas Veerman ^"ia-c:"(?i:[a-c]+)@ia-c@\n                             printf("OK: %s", yytext); ++yylineno; return 1;
65*357f1050SThomas Veerman 
66*357f1050SThomas Veerman     /* We don't want this one to match. */
67*357f1050SThomas Veerman ^"check-a:"(?i:(?-i:A))@\n               err_abort();
68*357f1050SThomas Veerman ^"check-a:"(?i:(?-i:(?i:A)))@\n          printf("OK: %s", yytext); ++yylineno; return 1;
69*357f1050SThomas Veerman 
70*357f1050SThomas Veerman     /* We don't want this one to match. */
71*357f1050SThomas Veerman ^"dot-all-1:"(?-s:XXX.*)@dot-all-1@\n    err_abort();
72*357f1050SThomas Veerman ^"dot-all-1:"(?s:XXX.*)@dot-all-1@\n    a_ok();
73*357f1050SThomas Veerman 
74*357f1050SThomas Veerman ^"x1:"(?x:   a | b  )+@x1@\n              a_ok();
75*357f1050SThomas Veerman ^"x2:"(?x:   a |
76*357f1050SThomas Veerman         (?# Comment )
77*357f1050SThomas Veerman     b
78*357f1050SThomas Veerman     )+@x2@\n              a_ok();
79*357f1050SThomas Veerman 
80*357f1050SThomas Veerman 
81*357f1050SThomas Veerman .|\n                       { err_abort(); }
82*357f1050SThomas Veerman %%
83*357f1050SThomas Veerman 
84*357f1050SThomas Veerman int main(void);
85*357f1050SThomas Veerman 
86*357f1050SThomas Veerman int
main()87*357f1050SThomas Veerman main ()
88*357f1050SThomas Veerman {
89*357f1050SThomas Veerman     yyin = stdin;
90*357f1050SThomas Veerman     yyout = stdout;
91*357f1050SThomas Veerman     while (yylex())
92*357f1050SThomas Veerman         ;
93*357f1050SThomas Veerman     printf("TEST RETURNING OK.\n");
94*357f1050SThomas Veerman     return 0;
95*357f1050SThomas Veerman }
96