]> git.saurik.com Git - cycript.git/blobdiff - Cycript.l.in
Use a single std::istream& to replace file_/data_.
[cycript.git] / Cycript.l.in
index f311c69d4725664eb36beff6b44d62e683d385a3..f2bd9b9b4afcad8fc7857174a0beb535036f4d83 100644 (file)
@@ -30,7 +30,9 @@ typedef cy::parser::token tk;
 
 #define F(value) do { \
     int token(value); \
 
 #define F(value) do { \
     int token(value); \
-    yyextra->nobrace_ = false; \
+    yyextra->no_.AtImplementation = false; \
+    yyextra->no_.Function = false; \
+    yyextra->no_.OpenBrace = false; \
     return token; \
 } while (false)
 
     return token; \
 } while (false)
 
@@ -88,18 +90,12 @@ int H(char c) {
 }
 
 #define YY_INPUT(data, value, size) { \
 }
 
 #define YY_INPUT(data, value, size) { \
-    if (yyextra->file_ != NULL) { \
-        size_t copy(fread(data, 1, size, yyextra->file_)); \
-        value = copy == 0 ? YY_NULL : copy; \
-    } else if (yyextra->size_ == 0) \
+    if (yyextra->data_.eof()) \
         value = YY_NULL; \
     else { \
         value = YY_NULL; \
     else { \
-        size_t copy(size); \
-        copy = (std::min(copy, yyextra->size_)); \
-        memcpy(data, yyextra->data_, copy); \
-        yyextra->data_ += copy; \
-        yyextra->size_ -= copy; \
-        value = copy; \
+        yyextra->data_.read(data, size); \
+        size_t copy(yyextra->data_.gcount()); \
+        value = copy == 0 ? YY_NULL : copy; \
     } \
 }
 
     } \
 }
 
@@ -237,7 +233,7 @@ XMLName {XMLNameStart}{XMLNamePart}*
 "("    L C F(tk::OpenParen);
 ")"    L C F(tk::CloseParen);
 
 "("    L C F(tk::OpenParen);
 ")"    L C F(tk::CloseParen);
 
-"{"    L C F(yyextra->nobrace_ ? tk::OpenBrace__ : yylval->newline_ ? tk::OpenBrace_ : tk::OpenBrace);
+"{"    L C F(yyextra->no_.OpenBrace ? tk::OpenBrace__ : yylval->newline_ ? tk::OpenBrace_ : tk::OpenBrace);
 "}"    L C F(tk::CloseBrace);
 
 "["    L C F(tk::OpenBracket);
 "}"    L C F(tk::CloseBrace);
 
 "["    L C F(tk::OpenBracket);
@@ -249,7 +245,7 @@ XMLName {XMLNameStart}{XMLNamePart}*
 
 @begin ObjectiveC
 "@end"            L C F(tk::AtEnd);
 
 @begin ObjectiveC
 "@end"            L C F(tk::AtEnd);
-"@implementation" L C F(tk::AtImplementation);
+"@implementation" L C F(yyextra->no_.AtImplementation ? tk::AtImplementation_ : tk::AtImplementation);
 "@import"         L C F(tk::AtImport);
 "@selector"       L C F(tk::AtSelector);
 @end
 "@import"         L C F(tk::AtImport);
 "@selector"       L C F(tk::AtSelector);
 @end
@@ -269,7 +265,7 @@ XMLName {XMLNameStart}{XMLNamePart}*
 "else"         L C I(word, Word("else"), tk::Else);
 "finally"      L C I(word, Word("finally"), tk::Finally);
 "for"          L C I(word, Word("for"), tk::For);
 "else"         L C I(word, Word("else"), tk::Else);
 "finally"      L C I(word, Word("finally"), tk::Finally);
 "for"          L C I(word, Word("for"), tk::For);
-"function"     L C I(word, Word("function"), tk::Function);
+"function"     L C I(word, Word("function"), yyextra->no_.Function ? tk::Function_ : tk::Function);
 "if"           L C I(word, Word("if"), tk::If);
 "in"           L C I(word, Word("in"), yyextra->in_.top() ? tk::In_ : tk::In);
 "instanceof"   L C I(word, Word("instanceof"), tk::InstanceOf);
 "if"           L C I(word, Word("if"), tk::If);
 "in"           L C I(word, Word("in"), yyextra->in_.top() ? tk::In_ : tk::In);
 "instanceof"   L C I(word, Word("instanceof"), tk::InstanceOf);