Created
March 1, 2013 05:38
-
-
Save mythagel/5062673 to your computer and use it in GitHub Desktop.
Extracted CMake lexer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
#include <stdio.h> | |
#include <errno.h> | |
int file_num; | |
int file_num_max; | |
char **files; | |
extern int errno; | |
%} | |
%pointer | |
%x STRING | |
MAKEVAR \$\([A-Za-z0-9_]*\) | |
%% | |
\n { | |
fprintf(stderr, "newline\n"); | |
return 1; | |
} | |
#.* { | |
fprintf(stderr, "comment: '%s'\n", yytext); | |
} | |
\( { | |
fprintf(stderr, "lparen\n"); | |
return 1; | |
} | |
\) { | |
fprintf(stderr, "rparen\n"); | |
return 1; | |
} | |
[A-Za-z_][A-Za-z0-9_]+ { | |
fprintf(stderr, "identifier: '%s'\n", yytext); | |
return 1; | |
} | |
({MAKEVAR}|[^ \t\r\n\(\)#\\\"]|\\.)({MAKEVAR}|[^ \t\r\n\(\)#\\\"]|\\.|\"({MAKEVAR}|[^\r\n\(\)#\\\"]|\\.)*\")* { | |
fprintf(stderr, "unquoted-argument: '%s'\n", yytext); | |
return 1; | |
} | |
\" { | |
fprintf(stderr, "quoted: '%s'\n", yytext); | |
BEGIN(STRING); | |
} | |
<STRING>([^\\\n\"]|\\(.|\n))+ { | |
fprintf(stderr, "string1: '%s'\n", yytext); | |
} | |
<STRING>\n { | |
fprintf(stderr, "string2: '%s'\n", yytext); | |
} | |
<STRING>\" { | |
fprintf(stderr, "string3: '%s'\n", yytext); | |
BEGIN(INITIAL); | |
return 1; | |
} | |
<STRING>. { | |
fprintf(stderr, "string4: '%s'\n", yytext); | |
} | |
<STRING><<EOF>> { | |
fprintf(stderr, "string5: '%s'\n", yytext); | |
BEGIN(INITIAL); | |
return 1; | |
} | |
[ \t\r] { | |
fprintf(stderr, "ws: '%s'\n", yytext); | |
} | |
. { | |
fprintf(stderr, "badchar: '%s'\n", yytext); | |
return 1; | |
} | |
<<EOF>> { | |
fprintf(stderr, "eof\n"); | |
return 0; | |
} | |
%% | |
int main(int argc, char *argv[]) { | |
file_num=1; | |
file_num_max = argc; | |
files = argv; | |
if ( argc > 1 ) { | |
if ( (yyin = fopen(argv[file_num],"r")) == 0 ) { | |
perror(argv[file_num]); | |
exit(1); | |
} | |
} | |
while( yylex() ) | |
; | |
return 0; | |
} | |
int yywrap() { | |
fclose(yyin); | |
if ( ++file_num < file_num_max ) { | |
if ( (yyin = fopen(files[file_num],"r")) == 0 ) { | |
perror(files[file_num]); | |
exit(1); | |
} | |
return 0; | |
} else { | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment