%{
+#define YYLTYPE cy::location
#include "Cycript.tab.hh"
typedef cy::parser::token tk;
#define YY_EXTRA_TYPE CYDriver *
-#define YYLTYPE cy::location
#define T yylval->newline_ = yyextra->state_ == CYNewLine;
#define C T yyextra->state_ = CYClear;
}
#define YY_INPUT(data, value, size) { \
- if (yyextra->size_ == 0) \
+ if (yyextra->file_ != NULL) { \
+ size_t copy(fread(data, 1, size, yyextra->file_)); \
+ value = copy == 0 ? YY_NULL : copy; \
+ } else if (yyextra->size_ == 0) \
value = YY_NULL; \
else { \
size_t copy(std::min(size, yyextra->size_)); \
%option reentrant
Exponent [eE][+-]?[0-9]+
-Escape \\[\\'"bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}
+Escape \\[\\'"bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}|\\\n
%%
"[" L C return tk::OpenBracket;
"]" L C return tk::CloseBracket;
+"@class" L C return tk::AtClass;
+"@end" L C return tk::AtEnd;
"@selector" L C return tk::AtSelector;
"break" L R yylval->word_ = new CYWord("break"); return tk::Break;
"transient" L C yylval->word_ = new CYWord("transient"); return tk::Transient;
"volatile" L C yylval->word_ = new CYWord("volatile"); return tk::Volatile;
-[a-zA-Z$_][a-zA-Z$_0-9]* yylval->identifier_ = new CYIdentifier(apr_pstrmemdup(yyextra->pool_, yytext, yyleng)); L C return tk::Identifier;
+"each" L C yylval->word_ = new CYIdentifier("each"); return tk::Each;
+"let" L C yylval->word_ = new CYIdentifier("let"); return tk::Let;
+
+[a-zA-Z$_][a-zA-Z$_0-9]* yylval->identifier_ = new CYIdentifier(apr_pstrmemdup(yyextra->pool_, yytext, yyleng)); L C return tk::Identifier_;
(\.[0-9]+|(0|[1-9][0-9]*)(\.[0-9]*)?){Exponent}? yylval->number_ = new CYNumber(strtod(yytext, NULL)); L C return tk::NumericLiteral;
if (yytext[i] == '\\')
switch (next = yytext[++i]) {
+ case '\n': continue;
case '\\': next = '\\'; break;
case '\'': next = '\''; break;
case '"': next = '"'; break;
[ \t] L
<<EOF>> L yyterminate();
-. {
+. L {
CYDriver::Error error;
error.location_ = *yylloc;
error.message_ = "syntax error, unknown token";