Debian Codegraph @

Source/Parser/FunctionalJAVACC/COWL2FunctionalJAVACCOntologyStreamParser.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "COWL2FunctionalJAVACCOntologyStreamParser.h"
22
23
24 namespace Konclude {
25
26 namespace Parser {
27
28 namespace FunctionalJAVACC {
29
30
31 COWL2FunctionalJAVACCOntologyStreamParser::COWL2FunctionalJAVACCOntologyStreamParser(COntologyBuilder* ontologyBuilder) : mOntologyBuilder(ontologyBuilder) {
32 mError = false;
33 mParsingError = false;
34 }
35
36
37 bool COWL2FunctionalJAVACCOntologyStreamParser::parseOntology(const QString& fileString) {
38 QFile file(fileString);
39 mError = false;
40 if (file.open(QIODevice::ReadOnly)) {
41 mError = !parseOntology(&file);
42 file.close();
43 } else {
44 mError = true;
45 mErrorString = QString("File '%1' does not exist or cannot be opened.").arg(fileString);
46 }
47 return !mError;
48 }
49
50 bool COWL2FunctionalJAVACCOntologyStreamParser::parseOntology(QIODevice* ioDevice) {
51 mStreamReader = new CQtIODeviceStreamReader(ioDevice);
52 mCharStream = new CharStream(mStreamReader);
53 mTokenManager = new COWL2FunctionalStyleParserTokenManager(mCharStream);
54 mErrorHandler = new COWL2FunctionalStyleParserErrorHandler();
55 mParser = new CConcreteOWL2FunctionalStyleParser(mOntologyBuilder,mTokenManager);
56 mParser->setErrorHandler(mErrorHandler);
57 mParser->ontologyDocument();
58 mError = mParsingError = mErrorHandler->hasError();
59 mErrorString = mParsingErrorString = mErrorHandler->getErrorString();
60 if (!mError && mTokenManager->hasLexicalError()) {
61 mError = mParsingError = true;
62 mErrorString = mParsingErrorString = QString("Lexical error encountered");
63 }
64 delete mParser;
65 return !mParsingError;
66 }
67
68
69 QString COWL2FunctionalJAVACCOntologyStreamParser::getParsingErrorString() {
70 return mParsingErrorString;
71 }
72
73 bool COWL2FunctionalJAVACCOntologyStreamParser::hasParsingError() {
74 return mParsingError;
75 }
76
77 QString COWL2FunctionalJAVACCOntologyStreamParser::getErrorString() {
78 return mErrorString;
79 }
80
81 bool COWL2FunctionalJAVACCOntologyStreamParser::hasError() {
82 return mError;
83 }
84
85
86 }; // end namespace FunctionalJAVACC
87
88 }; // end namespace Parser
89
90 }; // end namespace Konclude