parser error message modified and bug 14039 fixed 18/17018/3
Cedric Delamarre [Tue, 11 Aug 2015 13:13:13 +0000 (15:13 +0200)]
Change-Id: I9b239415324ce5c41f45c8b21dd90ea28526a293

scilab/modules/ast/includes/parse/parser.hxx
scilab/modules/ast/includes/parse/parser_private.hxx
scilab/modules/ast/src/cpp/parse/bison/parsescilab.yy
scilab/modules/ast/src/cpp/parse/parser.cpp
scilab/modules/ast/src/cpp/parse/parsescilab.cpp

index d506be4..05a86fb 100644 (file)
@@ -34,7 +34,6 @@ class EXTERN_AST Parser
 {
 public:
     Parser() :
-        _stop_on_first_error(false),
         _strict_mode(false),
         _parse_trace(false),
         _exit_status(Succeded),
@@ -146,20 +145,11 @@ public:
         _strict_mode = false;
     }
 
-    bool stopOnFirstError(void)
-    {
-        return _stop_on_first_error;
-    }
-    void enableStopOnFirstError(void)
-    {
-        _stop_on_first_error = true;
-    }
-    void disableStopOnFirstError(void)
-    {
-        _stop_on_first_error = false;
-    }
-
     void releaseTmpFile();
+    bool stopOnFirstError(void);
+    void enableStopOnFirstError(void);
+    void disableStopOnFirstError(void);
+
     /** \} */
 
 
@@ -167,7 +157,6 @@ private :
     const std::wstring _file_name;
     const std::wstring _prog_name;
     std::wstring _error_message;
-    bool _stop_on_first_error;
     bool _strict_mode;
     bool _parse_trace;
     ParserStatus _exit_status;
index 2a4aa1c..0445149 100644 (file)
@@ -33,7 +33,6 @@ public :
 
     static void pushControlStatus(Parser::ControlStatus control_status)
     {
-        //std::cout << "Push front : " << control_status << std::endl;
         _control_status.push_front(control_status);
     }
 
@@ -41,8 +40,6 @@ public :
     {
         if (!_control_status.empty())
         {
-            //std::cout << "Pop front" << std::endl;
-            //std::cout << "size = " << _control_status.size() << std::endl;
             _control_status.pop_front();
         }
     }
@@ -131,7 +128,7 @@ public :
     */
     static const std::wstring getProgName(void)
     {
-        return L"Scilab6";
+        return L"Scilab";
     }
     static void setProgName(const std::wstring& progName)
     {
index 63937d6..78b218b 100644 (file)
@@ -104,7 +104,7 @@ static void print_rules(const std::string& _parent, const double _value)
     {                                                           \
         if(ParserSingleInstance::stopOnFirstError())            \
         {                                                       \
-            return ParserSingleInstance::getExitStatus();       \
+            ParserSingleInstance::setExitStatus(Parser::ParserStatus::Failed);       \
         }                                                       \
     }
 
index c0af39a..9be6c35 100644 (file)
@@ -176,6 +176,19 @@ void Parser::parse(const wchar_t *command)
     FREE(pstCommand);
 }
 
+bool Parser::stopOnFirstError(void)
+{
+    return ParserSingleInstance::stopOnFirstError();
+}
+void Parser::enableStopOnFirstError(void)
+{
+    ParserSingleInstance::enableStopOnFirstError();
+}
+void Parser::disableStopOnFirstError(void)
+{
+    ParserSingleInstance::disableStopOnFirstError();
+}
+
 /** \brief parse the given file command */
 void ParserSingleInstance::parse(const char *command)
 {
@@ -283,6 +296,11 @@ std::wstring& ParserSingleInstance::getErrorMessage(void)
 
 void ParserSingleInstance::appendErrorMessage(const std::wstring& message)
 {
+    if (ParserSingleInstance::stopOnFirstError() && _error_message.empty() == false)
+    {
+        return;
+    }
+
     _error_message += message;
 }
 
@@ -316,7 +334,7 @@ std::wstring ParserSingleInstance::_file_name;
 std::wstring ParserSingleInstance::_prog_name;
 std::wstring ParserSingleInstance::_error_message;
 bool ParserSingleInstance::_strict_mode = false;
-bool ParserSingleInstance::_stop_on_first_error = false;
+bool ParserSingleInstance::_stop_on_first_error = true;
 ast::Exp* ParserSingleInstance::_the_program = nullptr;
 Parser::ParserStatus ParserSingleInstance::_exit_status = Parser::Succeded;
 std::list<Parser::ControlStatus> ParserSingleInstance::_control_status;
index a18e707..65c642c 100644 (file)
@@ -169,7 +169,7 @@ static void print_rules(const std::string& _parent, const double _value)
     {                                                           \
         if(ParserSingleInstance::stopOnFirstError())            \
         {                                                       \
-            return ParserSingleInstance::getExitStatus();       \
+            ParserSingleInstance::setExitStatus(Parser::ParserStatus::Failed);       \
         }                                                       \
     }