%initstate 0 %white [\ \t]+ %comments ##.+ %% STATE:0{ ### skip initial spaces... \s* {BEGIN 1; } ## dont return... } STATE:1{ ### initial Directives and Metadate \n(\w+): { BEGIN 2; return("DIR",$1); } \n([\t]*\n)+ { BEGIN 3; return("LB",""); } (\w+): { BEGIN 2; return("DIR",$1); } } STATE:2{ ### directive values $__CBB { BEGIN 1; return("CB",$2);} (.*) { BEGIN 1; return("VAL",__remsp($1)); } } STATE:3{ ### Quest and Tex (?:\s*)#t\{ { BEGIN 5; yynextreturn("BEG","");return("T","");} (?:\s*)#q\{ { BEGIN 4; yynextreturn("BEG","");return("Q","");} (?:\s*)#q\[(\d+)\]\{ { BEGIN 4; yynextreturn("INT",$1); yynextreturn("BEG","");return("Q","");} (\s*\S(?:.|\n)*?)\n(?=#) { return("TEX",$1); } (\s*\S(?:.|\n)*?)(?=__EOF__) { return("TEX",$1); } } STATE:4{ ### Question block ($__CBB) { return("CB",$1);} [}] { BEGIN 3; return("END",""); } ([,+;]) { return($1,""); } ([\~a-zA-Z\/.\-_0-9]+) { return("ID",$1); } } STATE:5{ ### Theory block [}] { BEGIN 3; return("END",""); } ([,+;]) { return($1,""); } ([\~a-zA-Z\/.\-_0-9]+) { return("ID",$1); } } %% sub fff2{}