]> git.saurik.com Git - cycript.git/blobdiff - Cycript.l
Added CYNoLeader after 'case', implemented a pass-through LetStatement binding (tempo...
[cycript.git] / Cycript.l
index b1ff59a61ccf46548fd462dce74e76df41f1b8c7..063e9004fd0fcc584dd053cde11b51423316fa99 100644 (file)
--- a/Cycript.l
+++ b/Cycript.l
@@ -1,9 +1,9 @@
 %{
+#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;
@@ -35,7 +35,10 @@ int H(char c) {
 }
 
 #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_)); \
@@ -58,7 +61,7 @@ int H(char c) {
 %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
 
 %%
 
@@ -119,6 +122,8 @@ Escape   \\[\\'"bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}
 "["    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;
@@ -182,7 +187,10 @@ Escape   \\[\\'"bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}
 "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;
 
@@ -199,6 +207,7 @@ Escape   \\[\\'"bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}
 
         if (yytext[i] == '\\')
             switch (next = yytext[++i]) {
+                case '\n': continue;
                 case '\\': next = '\\'; break;
                 case '\'': next = '\''; break;
                 case '"': next = '"'; break;
@@ -229,7 +238,7 @@ Escape   \\[\\'"bfnrtv]|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}
 [ \t] L
 <<EOF>> L yyterminate();
 
-. {
+. {
     CYDriver::Error error;
     error.location_ = *yylloc;
     error.message_ = "syntax error, unknown token";