jftt/l2/3.lex
2024-11-03 22:14:31 +01:00

65 lines
899 B
Text

%{
#include <stdbool.h>
bool leave_docs = false;
%}
%x SINGLE_LINE
%x MULTI_LINE
%%
<INITIAL>"///"|"//!" {
if (leave_docs) {
ECHO;
} else {
BEGIN(SINGLE_LINE);
}
}
<INITIAL>"/**"|"/*!" {
if (leave_docs) {
ECHO;
} else {
BEGIN(MULTI_LINE);
}
}
<INITIAL>"//" { BEGIN(SINGLE_LINE); }
<INITIAL>. { ECHO; }
<SINGLE_LINE>\n { BEGIN(INITIAL); }
<SINGLE_LINE>. { }
<INITIAL>"/*" { BEGIN(MULTI_LINE); }
<MULTI_LINE>"*/" { BEGIN(INITIAL); }
<MULTI_LINE>. { }
%%
// single line comment
/*
* multi line comment
*/
/// single line doc 1
//! single line doc 2
/**
* multi line doc 1
*/
/*!
* multi line doc 2
*/
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc > 1) {
leave_docs = true;
}
yylex();
return EXIT_SUCCESS;
}