| 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 |
%{ |
| 25 |
/* A template scanner file to build "scanner.c". */ |
| 26 |
#include <stdio.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include "config.h" |
| 29 |
/*#include "parser.h" */ |
| 30 |
|
| 31 |
#define err_abort() do{printf("ERROR: flex line %d. input line %d.\n", __LINE__, yylineno); abort();} while(0) |
| 32 |
#define a_ok() do{printf("OK: flex line %d. input line %d.\n", __LINE__, yylineno); return 1;}while(0) |
| 33 |
%} |
| 34 |
|
| 35 |
%option 8bit prefix="test" |
| 36 |
%option nounput nomain noyywrap noinput |
| 37 |
%option warn |
| 38 |
|
| 39 |
|
| 40 |
%% |
| 41 |
|
| 42 |
^"^alpha:"[[:^alpha:]]+@alpha@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 43 |
^"^digit:"[[:^digit:]]+@digit@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 44 |
^"^alnum:"[[:^alnum:]]+@alnum@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 45 |
^"^upper:"[[:^upper:]]+@upper@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 46 |
^"^lower:"[[:^lower:]]+@lower@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 47 |
^"^space:"[[:^space:]]+@space@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 48 |
^"^blank:"[[:^blank:]]+@blank@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 49 |
^"^punct:"[[:^punct:]]+@punct@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 50 |
^"^cntrl:"[[:^cntrl:]]+@cntrl@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 51 |
^"^xdigit:"[[:^xdigit:]]+@xdigit@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 52 |
|
| 53 |
^"a-d:"[[:alpha:]]{-}[[:digit:]]+@a-d@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 54 |
^"l-xyz:"([[:lower:]]{-}[xyz])+@l-xyz@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 55 |
^"abcd-bc:"([abcd]{-}[bc])+@abcd-bc@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 56 |
^"abcde-b-c:"([abcde]{-}[b]{-}[c])+@abcde-b-c@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 57 |
^"^XY-^XYZ:"([^XY]{-}[^XYZ])+@^XY-^XYZ@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 58 |
|
| 59 |
^"a+d:"([[:alpha:]]{+}[[:digit:]])+"@a+d@"\n a_ok(); |
| 60 |
^"a-u+Q:"([[:alpha:]]{-}[[:upper:]]{+}[Q])+"@a-u+Q@"\n a_ok(); |
| 61 |
|
| 62 |
^"ia:"(?i:a)+@ia@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 63 |
^"iabc:"(?i:abc)+@iabc@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 64 |
^"ia-c:"(?i:[a-c]+)@ia-c@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 65 |
|
| 66 |
/* We don't want this one to match. */ |
| 67 |
^"check-a:"(?i:(?-i:A))@\n err_abort(); |
| 68 |
^"check-a:"(?i:(?-i:(?i:A)))@\n printf("OK: %s", yytext); ++yylineno; return 1; |
| 69 |
|
| 70 |
/* We don't want this one to match. */ |
| 71 |
^"dot-all-1:"(?-s:XXX.*)@dot-all-1@\n err_abort(); |
| 72 |
^"dot-all-1:"(?s:XXX.*)@dot-all-1@\n a_ok(); |
| 73 |
|
| 74 |
^"x1:"(?x: a | b )+@x1@\n a_ok(); |
| 75 |
^"x2:"(?x: a | |
| 76 |
(?# Comment ) |
| 77 |
b |
| 78 |
)+@x2@\n a_ok(); |
| 79 |
|
| 80 |
|
| 81 |
.|\n { err_abort(); } |
| 82 |
%% |
| 83 |
|
| 84 |
int main(void); |
| 85 |
|
| 86 |
int |
| 87 |
main (void) |
| 88 |
{ |
| 89 |
yyin = stdin; |
| 90 |
yyout = stdout; |
| 91 |
while (yylex()) |
| 92 |
; |
| 93 |
printf("TEST RETURNING OK.\n"); |
| 94 |
return 0; |
| 95 |
} |