|
From: <ma...@us...> - 2009-09-21 11:28:29
|
Revision: 349
http://scstudio.svn.sourceforge.net/scstudio/?rev=349&view=rev
Author: madzin
Date: 2009-09-21 11:28:21 +0000 (Mon, 21 Sep 2009)
Log Message:
-----------
New error messages
--Thir line, and those below, will be ignored--
M trunk/tests/z120_test/z120_test42.mpr.result
M trunk/tests/z120_test/z120_test50.mpr.result
M trunk/tests/z120_test/z120_test53.mpr.result
A trunk/src/data/Z120/display_error.cpp
M trunk/src/data/Z120/Z120.g
A trunk/src/data/Z120/display_error.h
M trunk/src/data/Z120/Context.cpp
M trunk/src/data/Z120/CMakeLists.txt
Modified Paths:
--------------
trunk/src/data/Z120/CMakeLists.txt
trunk/src/data/Z120/Context.cpp
trunk/src/data/Z120/Z120.g
trunk/tests/z120_test/z120_test42.mpr.result
trunk/tests/z120_test/z120_test50.mpr.result
trunk/tests/z120_test/z120_test53.mpr.result
Added Paths:
-----------
trunk/src/data/Z120/display_error.cpp
trunk/src/data/Z120/display_error.h
Modified: trunk/src/data/Z120/CMakeLists.txt
===================================================================
--- trunk/src/data/Z120/CMakeLists.txt 2009-09-20 23:03:16 UTC (rev 348)
+++ trunk/src/data/Z120/CMakeLists.txt 2009-09-21 11:28:21 UTC (rev 349)
@@ -12,7 +12,10 @@
z120_load.cpp
Z120.g
Context.h
+ Context_Impl.h
Context.cpp
+ display_error.h
+ display_error.cpp
Z120Lexer.c
Z120Parser.c)
Modified: trunk/src/data/Z120/Context.cpp
===================================================================
--- trunk/src/data/Z120/Context.cpp 2009-09-20 23:03:16 UTC (rev 348)
+++ trunk/src/data/Z120/Context.cpp 2009-09-21 11:28:21 UTC (rev 349)
@@ -28,72 +28,8 @@
#ifndef __ParserStruct__
#define __ParserStruct__
-#include "data/Z120/Context.h"
-#include <stdlib.h>
-#include <string>
-#include <iostream>
-#include <map>
-#include <list>
-#include <set>
-#include "data/msc.h"
-#include "z120.h"
+#include "Context_Impl.h"
-struct Context
-{
- std::string msc_name;
-
- /*
- * BMsc: name of instance
- * HMsc: name of node
- */
- std::string element_name;
-
- /*
- * Textual file
- */
- typedef std::multimap<std::string, MscPtr> MscPtrMap;
- MscPtrMap mscs; // map of msc in the file
- typedef std::set<std::string> MscNameSet;
- MscNameSet nonpointed; // msc which is not refered
- std::map<std::string, std::set<ReferenceNodePtr> > future_reference; //map of name of nodes on which was refered and does not exist
- Z120* z;
-
- /*
- * BMsc
- */
- BMscPtr myBmsc;
- std::set<std::string> coregion_area_finished; // set of instances which has currently finished coregion area
- std::set<std::string> coregion_area_opened; //set of instances which has currently opend coregion area
- std::map<std::string, InstancePtr> instances; // map of instances (key: name of instance, value: smart pointer to instance)
- std::multimap<std::string, CompleteMessagePtr> messages; // map of future complete messages
- std::map<std::string, EventPtr> future_events; // map of name of events on which was pointed before they were created
- std::map<std::string, CoregionEventPtr> named_events; // map of name of events
- std::set<std::string> order_events; //set of name of events which takes place after keywords 'before', 'after'
- EventPtr current_event; //event which was currently created
- std::string event_name; //name of event
- int not_create_event; //flag for event in case msc has two labeled event with the same name
- int no_message_label; //flag for message which does not have label
- int open_instance; //counter of open instances
-
- /*
- * HMsc
- */
- HMscPtr myHmsc;
- StartNodePtr start_node;
- std::pair<std::string, EndNodePtr> end_node;
- std::list<std::string> connect_name; // name of HMsc nodes which are successors of actual node
- std::string reference_name;
- std::string condition_name;
- std::map<std::string, HMscNodePtr> hmsc_nodes; // map of hmsc nodes (key: name of node, value: smart pointer to node)
- std::map<std::string, std::set<std::string> > future_connections; // map of nodes to which node will be connected
- int node_type; //flag to recognize HMsc nodes (ConnectionNode, ReferenceNode, ConditionNode). Used in Z120.g
-
- ~Context() {}
-};
-
-
-void create_future_connections_fun(struct Context* context, SuccessorNode* succ);
-
/*
* Set name of Msc
*/
Modified: trunk/src/data/Z120/Z120.g
===================================================================
--- trunk/src/data/Z120/Z120.g 2009-09-20 23:03:16 UTC (rev 348)
+++ trunk/src/data/Z120/Z120.g 2009-09-21 11:28:21 UTC (rev 349)
@@ -26,27 +26,34 @@
options
{
language = C;
-// backtrack=true;
k=3;
}
-//@rulecatch {
-// pANTLR3_EXCEPTION exe = EXCEPTION;
-// if(NULL != exe) {
-// bug_report_fun(context, "Part of the file has not been read correctly\n");
-// }
-//}
-
-
@header{
#include "data/Z120/Context.h"
+ #include "data/Z120/display_error.h"
}
@members{
struct Context* context;
+
+ void scstudio_error_reporting(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
+ {
+ display_error(context, recognizer, tokenNames);
+ }
+
}
+@parser::apifuncs
+{
+ void reportError (pANTLR3_BASE_RECOGNIZER recognizer);
+ RECOGNIZER->reportError = &reportError;
+ void scstudio_error_reporting(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames);
+ RECOGNIZER->displayRecognitionError = &scstudio_error_reporting;
+}
+
+
/*
* removed due to: Z120.g:40:1: syntax error: antlr: Z120.g:40:1: unexpected token: tokens
tokens
@@ -371,7 +378,7 @@
set_instance_name_fun(context, (char*) ($NAME.text->chars));
}
':' instance_event_list
- | instance_name_list ':' multi_instance_event_list
+// | instance_name_list ':' multi_instance_event_list
;
instance_event_list:
Added: trunk/src/data/Z120/display_error.cpp
===================================================================
--- trunk/src/data/Z120/display_error.cpp (rev 0)
+++ trunk/src/data/Z120/display_error.cpp 2009-09-21 11:28:21 UTC (rev 349)
@@ -0,0 +1,248 @@
+#include "data/Z120/display_error.h"
+#include "data/Z120/Context_Impl.h"
+
+void reportError (pANTLR3_BASE_RECOGNIZER recognizer)
+ {
+ if (recognizer->state->errorRecovery == ANTLR3_TRUE)
+ {
+ return;
+ }
+
+ // Signal we are in error recovery now
+ //
+ recognizer->state->errorRecovery = ANTLR3_TRUE;
+
+ // Indicate this recognizer had an error while processing.
+ //
+ recognizer->state->errorCount++;
+
+ // Call the error display routine
+ //
+ recognizer->displayRecognitionError(recognizer, recognizer->state->tokenNames);
+
+
+ }
+
+
+//void scstudio_error_reporting(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
+void display_error(struct Context* context, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
+{
+// pANTLR3_PARSER parser;
+// pANTLR3_TREE_PARSER tparser;
+// pANTLR3_INT_STREAM is;
+ pANTLR3_STRING ttext;
+ pANTLR3_STRING ftext;
+ pANTLR3_EXCEPTION ex;
+// pANTLR3_COMMON_TOKEN theToken;
+// pANTLR3_BASE_TREE theBaseTree;
+// pANTLR3_COMMON_TREE theCommonTree;
+
+ // Retrieve some info for easy reading.
+ //
+ ex = recognizer->state->exception;
+ ttext = NULL;
+
+ // See if there is a 'filename' we can use
+ //
+ if (ex->streamName == NULL)
+ {
+ if (((pANTLR3_COMMON_TOKEN)(ex->token))->type == ANTLR3_TOKEN_EOF)
+ {
+ context->z->print_report(RS_ERROR, stringize() << "-end of input-(");
+ }
+ else
+ {
+ context->z->print_report(RS_ERROR,stringize() << "-unknown source-(");
+ }
+ }
+ else
+ {
+ ftext = ex->streamName->to8(ex->streamName);
+ context->z->print_report(RS_ERROR, stringize() << (char*) ftext->chars << "(Line: "
+ << recognizer->state->exception->line << ", Line position: "
+ << recognizer->state->exception->charPositionInLine << ")");
+ }
+
+ // should be as helpful as possible for grammar developers and serve as an example
+ // of what you can do with each exception type. In general, when you make up your
+ // 'real' handler, you should debug the routine with all possible errors you expect
+ // which will then let you be as specific as possible about all circumstances.
+ //
+ // Note that in the general case, errors thrown by tree parsers indicate a problem
+ // with the output of the parser or with the tree grammar itself. The job of the parser
+ // is to produce a perfect (in traversal terms) syntactically correct tree, so errors
+ // at that stage should really be semantic errors that your own code determines and handles
+ // in whatever way is appropriate.
+ //
+ switch (ex->type)
+ {
+ case ANTLR3_UNWANTED_TOKEN_EXCEPTION:
+
+ // Indicates that the recognizer was fed a token which seesm to be
+ // spurious input. We can detect this when the token that follows
+ // this unwanted token would normally be part of the syntactically
+ // correct stream. Then we can see that the token we are looking at
+ // is just something that should not be there and throw this exception.
+ //
+ if (tokenNames == NULL)
+ {
+ context->z->print_report(RS_ERROR, stringize() << " Extraneous input...");
+ }
+ else
+ {
+ if (ex->expecting == ANTLR3_TOKEN_EOF)
+ {
+ context->z->print_report(RS_ERROR, stringize() << "Extraneous input - expected <EOF>\n");
+ }
+ else
+ {
+ context->z->print_report(RS_ERROR, stringize() << " Error " << recognizer->state->exception->type << ": " << "Extraneous input - expected " << (char*) (tokenNames[ex->expecting]) << "...\n");
+ }
+ }
+ break;
+
+ case ANTLR3_MISSING_TOKEN_EXCEPTION:
+
+ // Indicates that the recognizer detected that the token we just
+ // hit would be valid syntactically if preceeded by a particular
+ // token. Perhaps a missing ';' at line end or a missing ',' in an
+ // expression list, and such like.
+ //
+ if (tokenNames == NULL)
+ {
+ context->z->print_report(RS_ERROR, stringize() << "Missing token (" << ex->expecting << ")...");
+ }
+ else
+ {
+ if (ex->expecting == ANTLR3_TOKEN_EOF)
+ {
+ context->z->print_report(RS_ERROR, stringize() << "Missing <EOF>");
+ }
+ else
+ {
+ context->z->print_report(RS_ERROR, stringize() << " Error " << recognizer->state->exception->type << ": " << "Missing " << (char*) (tokenNames[ex->expecting]));
+ }
+ }
+ break;
+ case ANTLR3_RECOGNITION_EXCEPTION:
+
+ // Indicates that the recognizer received a token
+ // in the input that was not predicted. This is the basic exception type
+ // from which all others are derived. So we assume it was a syntax error.
+ // You may get this if there are not more tokens and more are needed
+ // to complete a parse for instance.
+ //
+ context->z->print_report(RS_ERROR, stringize() << "syntax error...\n");
+ break;
+
+ case ANTLR3_MISMATCHED_TOKEN_EXCEPTION:
+
+ // We were expecting to see one thing and got another. This is the
+ // most common error if we coudl not detect a missing or unwanted token.
+ // Here you can spend your efforts to
+ // derive more useful error messages based on the expected
+ // token set and the last token and so on. The error following
+ // bitmaps do a good job of reducing the set that we were looking
+ // for down to something small. Knowing what you are parsing may be
+ // able to allow you to be even more specific about an error.
+ //
+ if (tokenNames == NULL)
+ {
+ context->z->print_report(RS_ERROR, stringize() << "syntax error...\n");
+ }
+ else
+ {
+ if (ex->expecting == ANTLR3_TOKEN_EOF)
+ {
+ context->z->print_report(RS_ERROR, stringize() << "expected <EOF>");
+ }
+ else
+ {
+ context->z->print_report(RS_ERROR, stringize() << " Error " << recognizer->state->exception->type << ": " << "expected " << tokenNames[ex->expecting] << "...");
+ }
+ }
+ break;
+ case ANTLR3_NO_VIABLE_ALT_EXCEPTION:
+
+ // We could not pick any alt decision from the input given
+ // so god knows what happened - however when you examine your grammar,
+ // you should. It means that at the point where the current token occurred
+ // that the DFA indicates nowhere to go from here.
+ //
+ context->z->print_report(RS_ERROR, stringize() << " Error " << recognizer->state->exception->type << ": " << " : cannot match to any predicted input...\n");
+
+ break;
+
+ case ANTLR3_MISMATCHED_SET_EXCEPTION:
+
+ {
+ ANTLR3_UINT32 count;
+ ANTLR3_UINT32 bit;
+ ANTLR3_UINT32 size;
+ ANTLR3_UINT32 numbits;
+ pANTLR3_BITSET errBits;
+
+ // This means we were able to deal with one of a set of
+ // possible tokens at this point, but we did not see any
+ // member of that set.
+ //
+ context->z->print_report(RS_ERROR, stringize() << " : unexpected input...\n expected one of : ");
+
+ // What tokens could we have accepted at this point in the
+ // parse?
+ //
+ count = 0;
+ errBits = antlr3BitsetLoad (ex->expectingSet);
+ numbits = errBits->numBits (errBits);
+ size = errBits->size (errBits);
+
+ if (size > 0)
+ {
+ // However many tokens we could have dealt with here, it is usually
+ // not useful to print ALL of the set here. I arbitrarily chose 8
+ // here, but you should do whatever makes sense for you of course.
+ // No token number 0, so look for bit 1 and on.
+ //
+ for (bit = 1; bit < numbits && count < 8 && count < size; bit++)
+ {
+ // TODO: This doesn;t look right - should be asking if the bit is set!!
+ //
+
+ if (tokenNames[bit])
+ {
+ context->z->print_report(RS_ERROR, stringize() << (count > 0 ? ", " : "") << tokenNames[bit]);
+ count++;
+ }
+ }
+ context->z->print_report(RS_ERROR, stringize() << "");
+ }
+ else
+ {
+ context->z->print_report(RS_ERROR, stringize() << "Actually dude, we didn't seem to be expecting anything here, or at least");
+ context->z->print_report(RS_ERROR, stringize() << "I could not work out what I was expecting, like so many of us these days!");
+ }
+ }
+ break;
+
+ case ANTLR3_EARLY_EXIT_EXCEPTION:
+
+ // We entered a loop requiring a number of token sequences
+ // but found a token that ended that sequence earlier than
+ // we should have done.
+ //
+ context->z->print_report(RS_ERROR, stringize() << " : missing elements...");
+ break;
+
+ default:
+
+ // We don't handle any other exceptions here, but you can
+ // if you wish. If we get an exception that hits this point
+ // then we are just going to report what we know about the
+ // token.
+ //
+ context->z->print_report(RS_ERROR, stringize() << " : syntax not recognized...");
+ break;
+ }
+
+
+}
Added: trunk/src/data/Z120/display_error.h
===================================================================
--- trunk/src/data/Z120/display_error.h (rev 0)
+++ trunk/src/data/Z120/display_error.h 2009-09-21 11:28:21 UTC (rev 349)
@@ -0,0 +1,18 @@
+#ifndef _Z120Display_H
+#define _Z120Display_H
+
+#include<antlr3.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void reportError (pANTLR3_BASE_RECOGNIZER recognizer);
+
+void display_error(struct Context* context, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Modified: trunk/tests/z120_test/z120_test42.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test42.mpr.result 2009-09-20 23:03:16 UTC (rev 348)
+++ trunk/tests/z120_test/z120_test42.mpr.result 2009-09-21 11:28:21 UTC (rev 349)
@@ -1,9 +1,9 @@
-z120_test42.mpr(11) : error 3 : , at offset 0
- near [Index: 22 (Start: 152711996-Stop: 152711997) ='in', type<58> Line: 11 LinePos:0]
- : cannot match to any predicted input...
-z120_test42.mpr(30) : error 3 : , at offset 0
- near [Index: 144 (Start: 152712273-Stop: 152712275) ='out', type<57> Line: 30 LinePos:0]
- : cannot match to any predicted input...
+z120_test42.mpr(Line: 11, Line position: 0)
+ Error 3: : cannot match to any predicted input...
+
+z120_test42.mpr(Line: 30, Line position: 0)
+ Error 3: : cannot match to any predicted input...
+
Warning 09: There is reference to nonexisted MSC
OK: z120_test42 is correct, should be correct
Modified: trunk/tests/z120_test/z120_test50.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test50.mpr.result 2009-09-20 23:03:16 UTC (rev 348)
+++ trunk/tests/z120_test/z120_test50.mpr.result 2009-09-21 11:28:21 UTC (rev 349)
@@ -1,6 +1,6 @@
-z120_test50.mpr(8) : error 3 : 1377:1: node_definition : ( initial_node | final_node | intermediate_node );, at offset 4
- near [Index: 28 (Start: 145601215-Stop: 145601218) ='NAME', type<11> Line: 8 LinePos:4]
- : cannot match to any predicted input...
+z120_test50.mpr(Line: 8, Line position: 4)
+ Error 3: : cannot match to any predicted input...
+
Warning 08: There is reference to nonexisted node
Warning 09: There is reference to nonexisted MSC
Modified: trunk/tests/z120_test/z120_test53.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test53.mpr.result 2009-09-20 23:03:16 UTC (rev 348)
+++ trunk/tests/z120_test/z120_test53.mpr.result 2009-09-21 11:28:21 UTC (rev 349)
@@ -1,6 +1,6 @@
-z120_test53.mpr(7) : error 3 : , at offset 0
- near [Index: 11 (Start: 163857081-Stop: 163857084) ='inst', type<39> Line: 7 LinePos:0]
- : cannot match to any predicted input...
+z120_test53.mpr(Line: 7, Line position: 0)
+ Error 3: : cannot match to any predicted input...
+
OK: z120_test53 is correct, should be correct
mscdocument z120_test53;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|