xref: /netbsd-src/external/bsd/flex/dist/tests/ccl.l (revision 56bd85463476f90bb489799c99292bb30d6771c0)
130da1778Schristos /*
230da1778Schristos  * This file is part of flex.
330da1778Schristos  *
430da1778Schristos  * Redistribution and use in source and binary forms, with or without
530da1778Schristos  * modification, are permitted provided that the following conditions
630da1778Schristos  * are met:
730da1778Schristos  *
830da1778Schristos  * 1. Redistributions of source code must retain the above copyright
930da1778Schristos  *    notice, this list of conditions and the following disclaimer.
1030da1778Schristos  * 2. Redistributions in binary form must reproduce the above copyright
1130da1778Schristos  *    notice, this list of conditions and the following disclaimer in the
1230da1778Schristos  *    documentation and/or other materials provided with the distribution.
1330da1778Schristos  *
1430da1778Schristos  * Neither the name of the University nor the names of its contributors
1530da1778Schristos  * may be used to endorse or promote products derived from this software
1630da1778Schristos  * without specific prior written permission.
1730da1778Schristos  *
1830da1778Schristos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1930da1778Schristos  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
2030da1778Schristos  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2130da1778Schristos  * PURPOSE.
2230da1778Schristos  */
2330da1778Schristos 
2430da1778Schristos %{
2530da1778Schristos /* A template scanner file to build "scanner.c". */
2630da1778Schristos #include <stdio.h>
2730da1778Schristos #include <stdlib.h>
2830da1778Schristos #include "config.h"
2930da1778Schristos /*#include "parser.h" */
3030da1778Schristos 
3130da1778Schristos #define err_abort() do{printf("ERROR: flex line %d. input line %d.\n", __LINE__, yylineno); abort();} while(0)
3230da1778Schristos #define a_ok()      do{printf("OK: flex line %d. input line %d.\n", __LINE__, yylineno); return 1;}while(0)
3330da1778Schristos %}
3430da1778Schristos 
3530da1778Schristos %option 8bit prefix="test"
3630da1778Schristos %option nounput nomain noyywrap noinput
3730da1778Schristos %option warn
3830da1778Schristos 
3930da1778Schristos 
4030da1778Schristos %%
4130da1778Schristos 
4230da1778Schristos ^"^alpha:"[[:^alpha:]]+@alpha@\n        printf("OK: %s", yytext); ++yylineno; return 1;
4330da1778Schristos ^"^digit:"[[:^digit:]]+@digit@\n        printf("OK: %s", yytext); ++yylineno; return 1;
4430da1778Schristos ^"^alnum:"[[:^alnum:]]+@alnum@\n        printf("OK: %s", yytext); ++yylineno; return 1;
4530da1778Schristos ^"^upper:"[[:^upper:]]+@upper@\n        printf("OK: %s", yytext); ++yylineno; return 1;
4630da1778Schristos ^"^lower:"[[:^lower:]]+@lower@\n        printf("OK: %s", yytext); ++yylineno; return 1;
4730da1778Schristos ^"^space:"[[:^space:]]+@space@\n        printf("OK: %s", yytext); ++yylineno; return 1;
4830da1778Schristos ^"^blank:"[[:^blank:]]+@blank@\n        printf("OK: %s", yytext); ++yylineno; return 1;
4930da1778Schristos ^"^punct:"[[:^punct:]]+@punct@\n        printf("OK: %s", yytext); ++yylineno; return 1;
5030da1778Schristos ^"^cntrl:"[[:^cntrl:]]+@cntrl@\n        printf("OK: %s", yytext); ++yylineno; return 1;
5130da1778Schristos ^"^xdigit:"[[:^xdigit:]]+@xdigit@\n      printf("OK: %s", yytext); ++yylineno; return 1;
5230da1778Schristos 
5330da1778Schristos ^"a-d:"[[:alpha:]]{-}[[:digit:]]+@a-d@\n  printf("OK: %s", yytext); ++yylineno; return 1;
5430da1778Schristos ^"l-xyz:"([[:lower:]]{-}[xyz])+@l-xyz@\n    printf("OK: %s", yytext); ++yylineno; return 1;
5530da1778Schristos ^"abcd-bc:"([abcd]{-}[bc])+@abcd-bc@\n          printf("OK: %s", yytext); ++yylineno; return 1;
5630da1778Schristos ^"abcde-b-c:"([abcde]{-}[b]{-}[c])+@abcde-b-c@\n    printf("OK: %s", yytext); ++yylineno; return 1;
5730da1778Schristos ^"^XY-^XYZ:"([^XY]{-}[^XYZ])+@^XY-^XYZ@\n    printf("OK: %s", yytext); ++yylineno; return 1;
5830da1778Schristos 
5930da1778Schristos ^"a+d:"([[:alpha:]]{+}[[:digit:]])+"@a+d@"\n    a_ok();
6030da1778Schristos ^"a-u+Q:"([[:alpha:]]{-}[[:upper:]]{+}[Q])+"@a-u+Q@"\n    a_ok();
6130da1778Schristos 
6230da1778Schristos ^"ia:"(?i:a)+@ia@\n                          printf("OK: %s", yytext); ++yylineno; return 1;
6330da1778Schristos ^"iabc:"(?i:abc)+@iabc@\n                    printf("OK: %s", yytext); ++yylineno; return 1;
6430da1778Schristos ^"ia-c:"(?i:[a-c]+)@ia-c@\n                             printf("OK: %s", yytext); ++yylineno; return 1;
6530da1778Schristos 
6630da1778Schristos     /* We don't want this one to match. */
6730da1778Schristos ^"check-a:"(?i:(?-i:A))@\n               err_abort();
6830da1778Schristos ^"check-a:"(?i:(?-i:(?i:A)))@\n          printf("OK: %s", yytext); ++yylineno; return 1;
6930da1778Schristos 
7030da1778Schristos     /* We don't want this one to match. */
7130da1778Schristos ^"dot-all-1:"(?-s:XXX.*)@dot-all-1@\n    err_abort();
7230da1778Schristos ^"dot-all-1:"(?s:XXX.*)@dot-all-1@\n    a_ok();
7330da1778Schristos 
7430da1778Schristos ^"x1:"(?x:   a | b  )+@x1@\n              a_ok();
7530da1778Schristos ^"x2:"(?x:   a |
7630da1778Schristos         (?# Comment )
7730da1778Schristos     b
7830da1778Schristos     )+@x2@\n              a_ok();
7930da1778Schristos 
8030da1778Schristos 
8130da1778Schristos .|\n                       { err_abort(); }
8230da1778Schristos %%
8330da1778Schristos 
8430da1778Schristos int main(void);
8530da1778Schristos 
8630da1778Schristos int
main(void)87*56bd8546Schristos main (void)
8830da1778Schristos {
8930da1778Schristos     yyin = stdin;
9030da1778Schristos     yyout = stdout;
9130da1778Schristos     while (yylex())
9230da1778Schristos         ;
9330da1778Schristos     printf("TEST RETURNING OK.\n");
9430da1778Schristos     return 0;
9530da1778Schristos }
96