]> git.saurik.com Git - cycript.git/commitdiff
Fix =>, yield, and throw with respect to newlines.
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 25 Nov 2015 14:32:27 +0000 (06:32 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Wed, 25 Nov 2015 14:32:27 +0000 (06:32 -0800)
Console.cpp
Cycript.l.in
Cycript.yy.in

index 4de0b7d1a49d49d6a8e52bd31e8c72c3c009382a..6239c357d962cd3c437d7f254904ad4156fb92b9 100644 (file)
@@ -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<char *>(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= ";
index d54ba0a128a21b26fa73a65b5d5ed3aaa9bb08d1..8c183a42387318cb863ec7e2a56611ae6396884b 100644 (file)
@@ -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);
index 6f88b07ef94b7febb62a42027803656428154142..d5d7c981b72ce02d30f7a40c2e1a8ac90a3a7201 100644 (file)
@@ -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); }
     ;
 /* }}} */