alecAbstraction Layer for Escape Codes |
git clone git://git.dimitrijedobrota.com/alec.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
lexer.l (2121B)
0 %{ 1 #include <stack> 2 #include "driver.hpp" 3 #include "parser.hpp" 4 5 using namespace alec; 6 7 #undef YY_DECL 8 #define YY_DECL int driver::yylex(parser::semantic_type* yylval, location_t *const lloc) 9 10 #define YY_USER_INIT m_yylloc = lloc; 11 #define YY_USER_ACTION copy_location(); 12 13 std::stack<int> mode_st; 14 15 #define BEGIN_MODE(mode) do { \ 16 if(yy_flex_debug) std::cerr<<"Starting mode: "<<mode<<std::endl; \ 17 mode_st.push(YY_START); \ 18 BEGIN((mode)); \ 19 } while(0); 20 21 #define END_MODE() do { \ 22 if(yy_flex_debug) std::cerr<<"Returning to mode: "<<mode_st.top()<<std::endl; \ 23 BEGIN(mode_st.top()); \ 24 mode_st.pop(); \ 25 } while(0); 26 %} 27 28 %option c++ noyywrap debug nodefault 29 %option yyclass = "driver" 30 %option prefix = "yy_alec_" 31 32 33 LINE_END (\n|\r|\r\n) 34 SWITCH_BEGIN "/\*%%\*//\*"{LINE_END} 35 SWITCH_END "\*//\*%%\*/"{LINE_END} 36 37 %x GEN LAST 38 39 %% 40 41 %{ 42 using Token = parser::token; 43 %} 44 45 46 {SWITCH_BEGIN} { BEGIN_MODE(GEN); return Token::SWITCH; } 47 .*{LINE_END} { 48 yylval->emplace<std::string>(yytext); 49 return Token::PROLOGUE; 50 } 51 52 <GEN>{LINE_END} { return Token::EOL; } 53 <GEN>^[\t ]*{LINE_END} { return Token::EOL; } 54 <GEN>^[\t ]*\|*[\t ]*{LINE_END} { return Token::EMPTY; } 55 56 <GEN>^[\t ]*"//".* { 57 yylval->emplace<std::string>(yytext); 58 return Token::COMMENT; 59 } 60 61 <GEN>, { return Token::COMMA; } 62 63 <GEN>[^,\n]* { 64 char *p = yytext + strlen(yytext) - 1; 65 while(isspace(*p)) *p-- = '\0'; 66 while(*yytext && isspace(*yytext)) yytext++; 67 yylval->emplace<std::string>(yytext); 68 return Token::LITERAL; 69 } 70 71 <GEN>{SWITCH_END} { 72 BEGIN_MODE(LAST); 73 return Token::SWITCH; 74 } 75 76 <LAST>.*{LINE_END} { 77 yylval->emplace<std::string>(yytext); 78 return Token::EPILOGUE; 79 } 80 81 %% 82