From: Jay Freeman (saurik) Date: Sat, 16 Jun 2012 03:59:17 +0000 (-0700) Subject: Assume we do /not/ have lookahead tokens for lexer. X-Git-Tag: v0.9.458~6 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/5602b1eebd5c9733b58795485c6a592c6e77b4d8?ds=inline Assume we do /not/ have lookahead tokens for lexer. --- diff --git a/Cycript.l.in b/Cycript.l.in index f311c69..d63784e 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -30,7 +30,9 @@ typedef cy::parser::token tk; #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) @@ -237,7 +239,7 @@ XMLName {XMLNameStart}{XMLNamePart}* "(" 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); @@ -249,7 +251,7 @@ XMLName {XMLNameStart}{XMLNamePart}* @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 @@ -269,7 +271,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); -"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); diff --git a/Cycript.yy.in b/Cycript.yy.in index 866127e..1345060 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -532,15 +532,15 @@ LexSetRegExp ; LexNoBrace - : { if (yychar == yyempty_) driver.nobrace_ = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; } + : { if (yychar == yyempty_) driver.no_.OpenBrace = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; } ; LexNoFunction - : { if (yychar == token::Function) yychar = token::Function_; } + : { driver.no_.Function = true; } ; LexNoAtImplementation - : { if (yychar == token::AtImplementation) yychar = token::AtImplementation_; } + : { driver.no_.AtImplementation = true; } ; LexSetStatement diff --git a/Parser.cpp b/Parser.cpp index 32d3d0a..f2d3ad1 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -28,7 +28,6 @@ CYRange WordEndRange_ (0x3ff001000000000LLU, 0x7fffffe87fffffeLLU); // A-Za-z_$ CYDriver::CYDriver(const std::string &filename) : state_(CYClear), - nobrace_(false), data_(NULL), size_(0), file_(NULL), @@ -39,6 +38,7 @@ CYDriver::CYDriver(const std::string &filename) : context_(NULL), mode_(AutoNone) { + memset(&no_, 0, sizeof(no_)); in_.push(false); ScannerInit(); } diff --git a/Parser.hpp b/Parser.hpp index afb2c66..ba896b7 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -474,9 +474,14 @@ class CYDriver { void *scanner_; CYState state_; - bool nobrace_; std::stack in_; + struct { + bool AtImplementation; + bool Function; + bool OpenBrace; + } no_; + const char *data_; size_t size_; FILE *file_;