From: Jay Freeman (saurik) Date: Wed, 25 Nov 2015 14:32:27 +0000 (-0800) Subject: Fix =>, yield, and throw with respect to newlines. X-Git-Tag: v0.9.590~285 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/6265f0de51456b03f8f81d29a445958a73dcf47c?ds=sidebyside Fix =>, yield, and throw with respect to newlines. --- diff --git a/Console.cpp b/Console.cpp index 4de0b7d..6239c35 100644 --- a/Console.cpp +++ b/Console.cpp @@ -416,7 +416,7 @@ class History { } void operator +=(const std::string &command) { - add_history(command_.c_str()); + add_history(command.c_str()); ++histlines_; } }; @@ -530,6 +530,7 @@ static void Console(CYOptions &options) { } command_ += line; + command_ += "\n"; char *begin(line), *end(line + strlen(line)); while (char *nl = reinterpret_cast(memchr(begin, '\n', end - begin))) { @@ -558,7 +559,7 @@ static void Console(CYOptions &options) { if (parser.parse() != 0 || !driver.errors_.empty()) { for (CYDriver::Errors::const_iterator error(driver.errors_.begin()); error != driver.errors_.end(); ++error) { CYPosition begin(error->location_.begin); - if (begin.line != lines.size() || begin.column < lines.back().size() || error->warning_) { + if (begin.line != lines.size() + 1 || error->warning_) { CYPosition end(error->location_.end); if (begin.line != lines.size()) { @@ -578,14 +579,13 @@ static void Console(CYOptions &options) { std::cerr << " | "; std::cerr << error->message_ << std::endl; - history += command_; + history += command_.substr(0, command_.size() - 1); goto restart; } } driver.errors_.clear(); - command_ += '\n'; prompt = "cy> "; goto read; } @@ -600,7 +600,7 @@ static void Console(CYOptions &options) { code = str.str(); } - history += command_; + history += command_.substr(0, command_.size() - 1); if (debug) { std::cout << "cy= "; diff --git a/Cycript.l.in b/Cycript.l.in index d54ba0a..8c183a4 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -301,7 +301,7 @@ XMLName {XMLNameStart}{XMLNamePart}* "=" L C F(tk::Equal, hi::Operator); "==" L C F(tk::EqualEqual, hi::Operator); "===" L C F(tk::EqualEqualEqual, hi::Operator); -"=>" L C F(tk::EqualRight, hi::Operator); +"=>" L C F(yylval->newline_ ? tk::EqualRight_ : tk::EqualRight, hi::Operator); "!" L C F(tk::Exclamation, hi::Operator); "!=" L C F(tk::ExclamationEqual, hi::Operator); "!==" L C F(tk::ExclamationEqualEqual, hi::Operator); @@ -459,7 +459,7 @@ XMLName {XMLNameStart}{XMLNamePart}* "volatile" L C I(identifier, Identifier("volatile"), tk::Volatile, hi::Meta); "let" L C I(identifier, Identifier("let"), tk::Let, hi::Meta); -"yield" L C I(identifier, Identifier("yield"), tk::Yield, hi::Control); +"yield" L R I(identifier, Identifier("yield"), tk::Yield, hi::Control); "each" L C I(identifier, Identifier("each"), tk::Each, hi::Control); "of" L C I(identifier, Identifier("of"), tk::Of, hi::Operator); diff --git a/Cycript.yy.in b/Cycript.yy.in index 6f88b07..d5d7c98 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -172,6 +172,7 @@ int cylex(YYSTYPE *, CYLocation *, void *); %token EqualEqual "==" %token EqualEqualEqual "===" %token EqualRight "=>" +%token EqualRight_ "\n=>" %token Exclamation "!" %token ExclamationEqual "!=" %token ExclamationEqualEqual "!==" @@ -696,7 +697,7 @@ IdentifierType // XXX: currently I only have this as Word // | "let" { $$ = $1; } - | "yield" { $$ = $1; } + | "yield" NewLineOpt { $$ = $1; } | "each" { $$ = $1; } | "of" { $$ = $1; } @@ -1306,7 +1307,7 @@ LabelledStatement /* }}} */ /* 12.13 The throw Statement {{{ */ ThrowStatement - : "throw" LexSetRegExp "\n" StrictSemi { YYABORT; } + : "throw" LexSetRegExp "\n" StrictSemi { error(@1, "throw without exception"); } | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); } ; /* }}} */