return token;
}
+#define CYLEX() do if (yyla.empty()) { \
+ YYCDEBUG << "Mapping a token: "; \
+ yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \
+ YY_SYMBOL_PRINT("Next token is", yyla); \
+} while (false)
+
#define CYMAP(to, from) do { \
- if (yyla.empty()) \
- yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \
+ CYLEX(); \
if (yyla.type == yytranslate_(token::from)) \
yyla.type = yytranslate_(token::to); \
} while (false)
LexPopYield: { driver.yield_.pop(); };
LexSetRegExp
- : { driver.SetCondition(CYDriver::RegExpCondition); }
+ : { CYLEX(); if (yyla.type == yytranslate_(token::Slash)) { yyla.clear(); driver.SetRegEx(false); } else if (yyla.type == yytranslate_(token::SlashEqual)) { yyla.clear(); driver.SetRegEx(true); } }
;
LexNewLine
%s Div
%s DivOrTemplateTail
-%s RegExp
-%s RegExpOrTemplateTail
@begin E4X
%x XMLContent
%%
/* RegEx {{{ */
-<RegExp,RegExpOrTemplateTail>\/ L CYLexBufferStart(RegularExpression); CYLexBufferUnit('/');
-
<RegularExpression>{
\/{UnicodePart}* R CYLexBufferUnits(yytext, yyleng); CYLexBufferEnd(literal, RegEx, tk::RegularExpressionLiteral, hi::Constant);
\/{UnicodePart}*{UnicodeFail} R E("invalid flags")
"*=" L F(tk::StarEqual, hi::Operator);
"~" L F(tk::Tilde, hi::Operator);
-<Div,DivOrTemplateTail>"/" L F(tk::Slash, hi::Operator);
-<Div,DivOrTemplateTail>"/=" L F(tk::SlashEqual, hi::Operator);
+"/" L F(tk::Slash, hi::Operator);
+"/=" L F(tk::SlashEqual, hi::Operator);
":" L F(tk::Colon, hi::Structure);
"," L F(tk::Comma, hi::Structure);
")" L F(tk::CloseParen, hi::Structure);
"{" L yyextra->template_.push(false); F(yyextra->newline_ ? tk::OpenBrace_ : tk::OpenBrace, hi::Structure);
-<Div,RegExp>"}" L S(template_); F(tk::CloseBrace, hi::Structure);
+<Div>"}" L S(template_); F(tk::CloseBrace, hi::Structure);
"[" L F(tk::OpenBracket, hi::Structure);
"]" L F(tk::CloseBracket, hi::Structure);
/* }}} */
/* Template {{{ */
"`" L yyextra->tail_ = false; CYLexBufferStart(StrictAccentString);
-<DivOrTemplateTail,RegExpOrTemplateTail>"}" L yyextra->tail_ = true; S(template_); CYLexBufferStart(StrictAccentString);
+<DivOrTemplateTail>"}" L yyextra->tail_ = true; S(template_); CYLexBufferStart(StrictAccentString);
<StrictAccentString>{
"`" R CYLexBufferEnd(string, String, yyextra->tail_ ? tk::TemplateTail : tk::NoSubstitutionTemplate, hi::Constant);
%%
+#undef yyextra
+#define yyextra this
+#define yyscanner scanner_
+
void CYDriver::ScannerInit() {
cylex_init(&scanner_);
cyset_extra(this, scanner_);
cylex_destroy(scanner_);
}
+void CYDriver::SetRegEx(bool equal) {
+ CYLexBufferStart(RegularExpression);
+ CYLexBufferUnit('/');
+ if (equal)
+ CYLexBufferUnit('=');
+}
+
void CYDriver::SetCondition(Condition condition) {
struct yyguts_t *yyg(reinterpret_cast<struct yyguts_t *>(scanner_));
switch (condition) {
- case RegExpCondition:
- BEGIN(template_.top() ? RegExpOrTemplateTail : RegExp);
- break;
@begin E4X
case XMLContentCondition:
BEGIN(XMLContent);
void CYDriver::PushCondition(Condition condition) {
switch (condition) {
- case RegExpCondition:
- yy_push_state(RegExp, scanner_);
- break;
@begin E4X
case XMLContentCondition:
yy_push_state(XMLContent, scanner_);