|
From: <ma...@us...> - 2010-12-08 20:34:56
|
Revision: 1006
http://scstudio.svn.sourceforge.net/scstudio/?rev=1006&view=rev
Author: madzin
Date: 2010-12-08 20:34:49 +0000 (Wed, 08 Dec 2010)
Log Message:
-----------
Add lexer error handling and comment recognition.
Modified Paths:
--------------
trunk/src/data/Z120/Context.cpp
trunk/src/data/Z120/Context.h
trunk/src/data/Z120/Context_Impl.h
trunk/src/data/Z120/Z120.g
trunk/src/data/Z120/display_error.cpp
trunk/src/data/Z120/display_error.h
trunk/src/data/Z120/z120_save.cpp
trunk/tests/z120_test/CMakeLists.txt
trunk/tests/z120_test/z120_test01.mpr.result
trunk/tests/z120_test/z120_test02.mpr.result
Added Paths:
-----------
trunk/tests/z120_test/z120_test90.mpr
trunk/tests/z120_test/z120_test90.mpr.result
Modified: trunk/src/data/Z120/Context.cpp
===================================================================
--- trunk/src/data/Z120/Context.cpp 2010-12-08 16:18:24 UTC (rev 1005)
+++ trunk/src/data/Z120/Context.cpp 2010-12-08 20:34:49 UTC (rev 1006)
@@ -1640,6 +1640,39 @@
context->time_second = time_relation_type;
}
+void add_global_comment(struct Context* context, char* text)
+{
+ std::string complete = text;
+
+ complete = complete.substr(complete.find("'")+1, complete.size());
+ complete = complete.substr(0, complete.rfind("'"));
+
+ CommentPtr comment = new Comment(TOWSTRING(complete));
+
+ if(context->myBmsc != NULL)
+ context->myBmsc->add_comment(comment);
+
+ if(context->myHmsc != NULL)
+ context->myHmsc->add_comment(comment);
+}
+
+void add_element_comment(struct Context* context, char* text)
+{
+ std::string complete = text;
+
+ complete = complete.substr(complete.find("'")+1, complete.size());
+ complete = complete.substr(0, complete.rfind("'"));
+
+ CommentPtr comment = new Comment(TOWSTRING(complete));
+
+ if(context->myBmsc != NULL && context->current_event != NULL)
+ context->current_event->add_comment(comment);
+
+ if(context->myHmsc != NULL && context->current_node != NULL)
+ context->current_node->add_comment(comment);
+
+}
+
#endif
// $Id$
Modified: trunk/src/data/Z120/Context.h
===================================================================
--- trunk/src/data/Z120/Context.h 2010-12-08 16:18:24 UTC (rev 1005)
+++ trunk/src/data/Z120/Context.h 2010-12-08 20:34:49 UTC (rev 1006)
@@ -161,6 +161,12 @@
void set_second_time_rel_kind_fun(struct Context* context, enum time_relation_kind kind);
+
+//Comment
+void add_global_comment(struct Context* context, char* text);
+
+void add_element_comment(struct Context* context, char* text);
+
#ifdef __cplusplus
}
#endif
Modified: trunk/src/data/Z120/Context_Impl.h
===================================================================
--- trunk/src/data/Z120/Context_Impl.h 2010-12-08 16:18:24 UTC (rev 1005)
+++ trunk/src/data/Z120/Context_Impl.h 2010-12-08 20:34:49 UTC (rev 1006)
@@ -139,7 +139,6 @@
~Context() {}
};
-
void create_future_connections_fun(struct Context* context, SuccessorNode* succ);
#endif // _Context_Impl_
Modified: trunk/src/data/Z120/Z120.g
===================================================================
--- trunk/src/data/Z120/Z120.g 2010-12-08 16:18:24 UTC (rev 1005)
+++ trunk/src/data/Z120/Z120.g 2010-12-08 20:34:49 UTC (rev 1006)
@@ -30,31 +30,53 @@
k=3;
}
-@header
+@lexer::includes
{
#include "data/Z120/Context.h"
#include "data/Z120/display_error.h"
- void scstudio_error_reporting(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames);
+ struct s_Z120* printer;
+ void scstudio_lexer_error_reporting(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames);
}
-@members
+@lexer::apifuncs
{
- struct Context* context;
+ RECOGNIZER->displayRecognitionError = &scstudio_lexer_error_reporting;
+}
- void scstudio_error_reporting(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
+@lexer::members
+{
+ void scstudio_lexer_error_reporting(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
{
- display_error(context, recognizer, tokenNames);
+ lexer_error(printer, recognizer, tokenNames);
}
}
+@parser::includes
+{
+ #include "data/Z120/Context.h"
+ #include "data/Z120/display_error.h"
+ #include "data/Z120/Z120Lexer.h"
+
+ void scstudio_error_reporting(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames);
+}
+
@parser::apifuncs
{
- RECOGNIZER->reportError = &reportError;
+// RECOGNIZER->reportError = &reportError;
RECOGNIZER->displayRecognitionError = &scstudio_error_reporting;
}
+@members
+{
+ struct Context* context;
+ void scstudio_error_reporting(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
+ {
+ display_error(context, recognizer, tokenNames);
+ }
+}
+
/*
* removed due to: Z120.g:40:1: syntax error: antlr: Z120.g:40:1: unexpected token: tokens
tokens
@@ -152,10 +174,12 @@
comment:
'comment' Character_String
+ {add_element_comment(context, (char*) $Character_String.text->chars);}
;
text_definition:
'text' Character_String end
+ {add_global_comment(context, (char*) $Character_String.text->chars);}
;
NOTE:
@@ -172,10 +196,10 @@
textual_msc_file [struct s_Z120* my_z120] returns [struct s_Msc** my_msc]:
{
context = new_context();
+ printer = my_z120;
+
if(my_z120 != NULL)
- {
add_z_fun(context, $my_z120);
- }
}
(document_head)? (message_sequence_chart)*
{
Modified: trunk/src/data/Z120/display_error.cpp
===================================================================
--- trunk/src/data/Z120/display_error.cpp 2010-12-08 16:18:24 UTC (rev 1005)
+++ trunk/src/data/Z120/display_error.cpp 2010-12-08 20:34:49 UTC (rev 1006)
@@ -231,4 +231,30 @@
context->z->print_report(RS_ERROR, report);
}
+void lexer_error(struct s_Z120* z, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
+{
+ Z120* printer = static_cast<Z120*> (z);
+ stringize report;
+
+ pANTLR3_LEXER lexer;
+ pANTLR3_EXCEPTION ex;
+ pANTLR3_STRING ftext;
+
+ lexer = (pANTLR3_LEXER)(recognizer->super);
+ ex = lexer->rec->state->exception;
+
+ // See if there is a 'filename' we can use
+ if(ex->name == NULL)
+ report << "-unknown source-[";
+ else
+ {
+ ftext = ex->streamName->to8(ex->streamName);
+ report << (char*) ftext->chars << "[";
+ }
+
+ report << recognizer->state->exception->line << "," << ex->charPositionInLine+1 << "]: Lexer error";
+
+ printer->print_report(RS_ERROR, report);
+}
+
// $Id$
Modified: trunk/src/data/Z120/display_error.h
===================================================================
--- trunk/src/data/Z120/display_error.h 2010-12-08 16:18:24 UTC (rev 1005)
+++ trunk/src/data/Z120/display_error.h 2010-12-08 20:34:49 UTC (rev 1006)
@@ -11,6 +11,8 @@
void display_error(struct Context* context, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames);
+void lexer_error(struct s_Z120* z, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames);
+
#ifdef __cplusplus
}
#endif
Modified: trunk/src/data/Z120/z120_save.cpp
===================================================================
--- trunk/src/data/Z120/z120_save.cpp 2010-12-08 16:18:24 UTC (rev 1005)
+++ trunk/src/data/Z120/z120_save.cpp 2010-12-08 20:34:49 UTC (rev 1006)
@@ -215,8 +215,17 @@
if(*pos == '\'')
{
- // double the apostrophe
- os << "''";
+ if((pos == value.m_text.begin() && *(pos+1) != '\'')
+ || (pos == value.m_text.end() && *(pos-1) != '\'')
+ || (*(pos+1) != '\'' && *(pos-1) != '\''))
+ {
+//TODO print warning that the comment is not valid
+// print_report(RS_WARNING, stringize() << L"Comment text \"" << TOWSTRING(value) << L"\" is not allowed");
+
+ // double the apostrophe
+ os << "''";
+ }
+
was_replacement = false;
}
else if(*pos == '\r')
@@ -445,8 +454,6 @@
print_element_attributes(stream, bmsc);
stream << "msc " << VALID_NAME(bmsc->get_label()) << ";" << std::endl;
- // print global comments
- print_texts(stream, bmsc);
// declare instances
for(InstancePtrList::const_iterator ipos = bmsc->get_instances().begin();
@@ -455,6 +462,9 @@
stream << "inst " << VALID_NAME((*ipos)->get_label()) << ";" << std::endl;
}
+ // print global comments
+ print_texts(stream, bmsc);
+
// define instances
for(InstancePtrList::const_iterator ipos = bmsc->get_instances().begin();
ipos != bmsc->get_instances().end(); ipos++)
Modified: trunk/tests/z120_test/CMakeLists.txt
===================================================================
--- trunk/tests/z120_test/CMakeLists.txt 2010-12-08 16:18:24 UTC (rev 1005)
+++ trunk/tests/z120_test/CMakeLists.txt 2010-12-08 20:34:49 UTC (rev 1006)
@@ -97,6 +97,7 @@
ADD_Z120_TEST(z120_test87.mpr 1)
ADD_Z120_TEST(z120_test88.mpr 1)
ADD_Z120_TEST(z120_test89.mpr 1)
+ADD_Z120_TEST(z120_test90.mpr 1)
ADD_Z120_TEST(z120_time01.mpr 1)
ADD_Z120_TEST(z120_time02.mpr 1)
Modified: trunk/tests/z120_test/z120_test01.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test01.mpr.result 2010-12-08 16:18:24 UTC (rev 1005)
+++ trunk/tests/z120_test/z120_test01.mpr.result 2010-12-08 20:34:49 UTC (rev 1006)
@@ -5,6 +5,7 @@
msc z120_test01;
inst ONE;
inst TWO;
+text 'Comment';
ONE: instance;
in LEFT,0 from found;
out NAME,1 to TWO;
Modified: trunk/tests/z120_test/z120_test02.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test02.mpr.result 2010-12-08 16:18:24 UTC (rev 1005)
+++ trunk/tests/z120_test/z120_test02.mpr.result 2010-12-08 20:34:49 UTC (rev 1006)
@@ -3,6 +3,7 @@
mscdocument z120_test02;
msc z120_test02;
+text 'Comment';
initial connect L0;
L0: connect L1, L2;
L1: condition STATE1 connect L3;
Added: trunk/tests/z120_test/z120_test90.mpr
===================================================================
--- trunk/tests/z120_test/z120_test90.mpr (rev 0)
+++ trunk/tests/z120_test/z120_test90.mpr 2010-12-08 20:34:49 UTC (rev 1006)
@@ -0,0 +1,21 @@
+mscdocument Drawing5;
+msc Page_1;
+inst a;
+inst c;
+inst b;
+text 'text';
+a: instance;
+out 1,0 to b;
+in 4,1 from b;
+endinstance;
+c: instance;
+in 2,2 from b;
+out 3,3 to b;
+endinstance;
+b: instance;
+in 1,0 from a comment 'Event ';
+out 2,2 to c;
+in 3,3 from c;
+out 4,1 to a;
+endinstance;
+endmsc;
Added: trunk/tests/z120_test/z120_test90.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test90.mpr.result (rev 0)
+++ trunk/tests/z120_test/z120_test90.mpr.result 2010-12-08 20:34:49 UTC (rev 1006)
@@ -0,0 +1,23 @@
+OK: z120_test90 is correct, should be correct
+
+mscdocument z120_test90;
+msc Page_1;
+inst a;
+inst c;
+inst b;
+text 'text';
+a: instance;
+out 1,0 to b;
+in 4,1 from b;
+endinstance;
+c: instance;
+in 2,2 from b;
+out 3,3 to b;
+endinstance;
+b: instance;
+in 1,0 from a comment 'Event ';
+out 2,2 to c;
+in 3,3 from c;
+out 4,1 to a;
+endinstance;
+endmsc;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|