summaryrefslogtreecommitdiffstats
path: root/vhdlparser
diff options
context:
space:
mode:
authorAndreas Regel <andreas.regel@newayselectronics.com>2018-05-28 11:12:22 (GMT)
committerAndreas Regel <andreas.regel@newayselectronics.com>2018-05-28 11:12:22 (GMT)
commite7fe7109421e75b75c7f8d50dd0e1c165b880eea (patch)
tree12a1a0410e689bacdcbce5541c6c1b2386379011 /vhdlparser
parent9f7406d151e4f5d021558e97f5d87a0d9cacecf9 (diff)
parent63696c08425fc1662c5e76280e3cc74fb3769d80 (diff)
downloadDoxygen-e7fe7109421e75b75c7f8d50dd0e1c165b880eea.zip
Doxygen-e7fe7109421e75b75c7f8d50dd0e1c165b880eea.tar.gz
Doxygen-e7fe7109421e75b75c7f8d50dd0e1c165b880eea.tar.bz2
Merge branch 'master' into vhdl-localization
# Conflicts: # src/translator.h
Diffstat (limited to 'vhdlparser')
-rw-r--r--vhdlparser/ErrorHandler.h2
-rw-r--r--vhdlparser/Makefile42
-rw-r--r--vhdlparser/ParseException.cc2
-rw-r--r--vhdlparser/ParseException.h2
-rw-r--r--vhdlparser/VhdlParserErrorHandler.hpp27
-rw-r--r--vhdlparser/VhdlParserIF.cpp2
-rw-r--r--vhdlparser/vhdlstring.h8
7 files changed, 71 insertions, 14 deletions
diff --git a/vhdlparser/ErrorHandler.h b/vhdlparser/ErrorHandler.h
index 55286b4..7500a5f 100644
--- a/vhdlparser/ErrorHandler.h
+++ b/vhdlparser/ErrorHandler.h
@@ -30,7 +30,7 @@ JAVACC_SIMPLE_STRING addUnicodeEscapes(JAVACC_STRING_TYPE str);
// Called when the parser cannot continue parsing.
// last - the last token successfully parsed.
// unexpected - the token at which the error occurs.
- // production - the production in which this error occurrs.
+ // production - the production in which this error occurs.
virtual void handleParseError(Token *last, Token *unexpected, JAVACC_SIMPLE_STRING production, VhdlParser *parser) {
error_count++;
fprintf(stderr, "Encountered: %s at: %d:%d while parsing: %s\n", addUnicodeEscapes(unexpected->image).c_str(), unexpected->beginLine, unexpected->beginColumn, production.c_str());
diff --git a/vhdlparser/Makefile b/vhdlparser/Makefile
index 4725470..84bdccf 100644
--- a/vhdlparser/Makefile
+++ b/vhdlparser/Makefile
@@ -7,16 +7,48 @@
# for any purpose. It is provided "as is" without express or implied warranty.
# See the GNU General Public License for more details.
#
-# Documents produced by Doxygen are derivative works derived from the
+# Documents produced by doxygen are derivative works derived from the
# input used in their production; they are not affected by this license.
#
-regenerate:
- rm -f CharStream.cc CharStream.h ErrorHandler.h ParseException.cc ParseException.h \
+#
+# Files generated by javacc
+#
+GEN_FILES=CharStream.cc CharStream.h ErrorHandler.h ParseException.cc ParseException.h \
Token.cc Token.h TokenManager.h TokenMgrError.cc TokenMgrError.h VhdlParser.cc VhdlParser.h \
VhdlParserConstants.h VhdlParserTokenManager.cc VhdlParserTokenManager.h \
JavaCC.h
- javacc vhdlparser.jj
- cp JavaCC.h.in JavaCC.h
+#
+# Generate parser (default target)
+#
+# when generating the parser with debug options it will look like:
+# make JAVACC_FLAGS=-debug_parser
+# or
+# make JAVACC_FLAGS="-debug_parser -debug_lookahead"
+#
+# Available debug options:
+# -debug_parser
+# -debug_token_manager
+# -debug_lookahead
+#
+# For other javacc settings / options consult the documentation of javacc.
+
+regenerate:
+ @rm -f $(GEN_FILES)
+ @javacc $(JAVACC_FLAGS) vhdlparser.jj
+ @cp JavaCC.h.in JavaCC.h
+
+#
+# reset the generated files back to their versions from git.
+#
+
+reset_gen_files:
+ @rm -f $(GEN_FILES)
+ @git checkout $(GEN_FILES)
+
+help:
+ @echo "Targets:"
+ @echo " regenerate (default)"
+ @echo " reset_gen_files"
FORCE:
diff --git a/vhdlparser/ParseException.cc b/vhdlparser/ParseException.cc
index 31ee7a3..99649af 100644
--- a/vhdlparser/ParseException.cc
+++ b/vhdlparser/ParseException.cc
@@ -53,7 +53,7 @@ namespace parser {
/**
* This is the last token that has been consumed successfully. If
* this object has been created due to a parse error, the token
- * followng this token will (therefore) be the first error token.
+ * following this token will (therefore) be the first error token.
*/
Token currentToken;
diff --git a/vhdlparser/ParseException.h b/vhdlparser/ParseException.h
index 1f3a3dc..b025912 100644
--- a/vhdlparser/ParseException.h
+++ b/vhdlparser/ParseException.h
@@ -50,7 +50,7 @@ class ParseException {
/**
* This is the last token that has been consumed successfully. If
* this object has been created due to a parse error, the token
- * followng this token will (therefore) be the first error token.
+ * following this token will (therefore) be the first error token.
*/
Token currentToken;
diff --git a/vhdlparser/VhdlParserErrorHandler.hpp b/vhdlparser/VhdlParserErrorHandler.hpp
index d98f029..9576ce6 100644
--- a/vhdlparser/VhdlParserErrorHandler.hpp
+++ b/vhdlparser/VhdlParserErrorHandler.hpp
@@ -7,32 +7,47 @@
#include "VhdlParser.h"
#include "ErrorHandler.h"
#include "vhdlstring.h"
+#include "message.h"
+
+const char *getVhdlFileName(void);
namespace vhdl { namespace parser {
-class VhdlErrorHandler: public ErrorHandler
+class VhdlErrorHandler: public ErrorHandler
{
- virtual void handleUnexpectedToken(int expectedKind, JAVACC_STRING_TYPE expectedToken, Token *actual, VhdlParser *parser)
+ virtual void handleUnexpectedToken(int expectedKind, JAVACC_STRING_TYPE expectedToken, Token *actual, VhdlParser *parser)
{
- fprintf(stderr,"\n\n syntax error at line: %d : %s\n", actual->beginLine,actual->image.data());
+ warn(getVhdlFileName(),actual->beginLine,"syntax error '%s'",actual->image.data());
error_count++;
throw std::exception();
}
- virtual void handleParseError(Token *last, Token *unexpected, JAVACC_SIMPLE_STRING production, VhdlParser *parser)
+ virtual void handleParseError(Token *last, Token *unexpected, JAVACC_SIMPLE_STRING production, VhdlParser *parser)
{
- fprintf(stderr,"\n\n unexpected token at line: %d %s\n", last->beginLine,unexpected->image.data());
+ warn(getVhdlFileName(),last->beginLine,"unexpected token: '%s'", unexpected->image.data());
error_count++;
throw std::exception();
}
virtual void handleOtherError(JAVACC_STRING_TYPE message, VhdlParser *parser)
{
- fprintf(stderr, "\n\n unexpected error: %s\n", (char*)message.c_str());
+ warn(getVhdlFileName(), -1, "unexpected error: '%s'", (char*)message.c_str());
error_count++;
throw std::exception();
}
};
+
+class VhdlTokenManagerErrorHandler: public TokenManagerErrorHandler {
+ virtual void lexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, JAVACC_STRING_TYPE errorAfter, JAVACC_CHAR_TYPE curChar, VhdlParserTokenManager* token_manager)
+ {
+ warn(getVhdlFileName(),errorLine,"Lexical error, Encountered: '%c' after: '%s'",curChar, (EOFSeen? "EOF" : (const char*)errorAfter.c_str()));
+ }
+
+ virtual void lexicalError(JAVACC_STRING_TYPE errorMessage, VhdlParserTokenManager* token_manager)
+ {
+ warn(getVhdlFileName(),-1,"Unknown error: '%s'", (char*)errorMessage.c_str());
+ }
+ };
}
}
diff --git a/vhdlparser/VhdlParserIF.cpp b/vhdlparser/VhdlParserIF.cpp
index f9f689b..3a6746f 100644
--- a/vhdlparser/VhdlParserIF.cpp
+++ b/vhdlparser/VhdlParserIF.cpp
@@ -14,6 +14,8 @@ void VhdlParserIF::parseVhdlfile(const char* inputBuffer,bool inLine)
JAVACC_STRING_TYPE s =inputBuffer;
CharStream *stream = new CharStream(s.c_str(), (int)s.size(), 1, 1);
VhdlParserTokenManager *tokenManager = new VhdlParserTokenManager(stream);
+ VhdlTokenManagerErrorHandler *myTokErr=new VhdlTokenManagerErrorHandler();
+ tokenManager->setErrorHandler(myTokErr);
myParser=new VhdlParser(tokenManager);
VhdlErrorHandler *myErr=new VhdlErrorHandler();
myParser->setErrorHandler(myErr);
diff --git a/vhdlparser/vhdlstring.h b/vhdlparser/vhdlstring.h
index fde6ce4..4c64440 100644
--- a/vhdlparser/vhdlstring.h
+++ b/vhdlparser/vhdlstring.h
@@ -9,6 +9,7 @@
/** @brief Minimal string class with std::string like behaviour that fulfills the JavaCC
* string requirements.
*/
+
class VhdlString
{
public:
@@ -93,6 +94,8 @@ class VhdlString
void clear() { free(m_str); init(); }
VhdlString &operator+=(char c) { char s[2]; s[0]=c; s[1]=0; return append(s); }
VhdlString &operator+=(const char *s) { return append(s); }
+ VhdlString &operator+=(VhdlString s) { return append(s); }
+ VhdlString operator+ (const char *s) { return append(s); }
private:
void init() { m_str=(char*)calloc(1,1); m_len=0; }
@@ -100,4 +103,9 @@ class VhdlString
int m_len;
};
+// declare it static otherwise we will get:
+// multiple definition of `operator+(char const*, VhdlString)'
+// as we are in an include file
+static VhdlString operator+ (const char *s, VhdlString v) { return VhdlString(s).append(v); }
+
#endif