diff --git a/src/backends/julia/CMakeLists.txt b/src/backends/julia/CMakeLists.txt index 212dc760..89c3bad3 100644 --- a/src/backends/julia/CMakeLists.txt +++ b/src/backends/julia/CMakeLists.txt @@ -1,31 +1,30 @@ include_directories(${Julia_INCLUDE_DIRS}) add_subdirectory(juliaserver) if(BUILD_TESTING) add_subdirectory(tests) endif(BUILD_TESTING) set(JuliaBackend_SRCS juliabackend.cpp juliasession.cpp juliaexpression.cpp juliakeywords.cpp juliahighlighter.cpp juliaextensions.cpp juliacompletionobject.cpp ) kconfig_add_kcfg_files(JuliaBackend_SRCS settings.kcfgc) ki18n_wrap_ui(JuliaBackend_SRCS settings.ui) add_backend(juliabackend ${JuliaBackend_SRCS}) target_link_libraries(cantor_juliabackend Qt5::DBus ${Julia_LIBRARY}) install(FILES juliabackend.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) -install(FILES keywords.xml DESTINATION ${KDE_INSTALL_DATADIR}/cantor/juliabackend) file(GLOB scripts "${CMAKE_CURRENT_SOURCE_DIR}/scripts/*.jl") install( FILES ${scripts} DESTINATION ${KDE_INSTALL_DATADIR}/cantor/juliabackend/scripts ) diff --git a/src/backends/julia/juliakeywords.cpp b/src/backends/julia/juliakeywords.cpp index f0a5846c..b7e29c41 100644 --- a/src/backends/julia/juliakeywords.cpp +++ b/src/backends/julia/juliakeywords.cpp @@ -1,116 +1,83 @@ /* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * --- * Copyright (C) 2016 Ivan Lakhtanov */ #include "juliakeywords.h" -#include -#include -#include -#include #include JuliaKeywords *JuliaKeywords::instance() { static JuliaKeywords *inst = 0; if (inst == 0) { inst = new JuliaKeywords(); - inst->loadFromFile(); - qSort(inst->m_keywords); - qSort(inst->m_variables); - qSort(inst->m_plotShowingCommands); + inst->loadKeywords(); } return inst; } -void JuliaKeywords::loadFromFile() +void JuliaKeywords::loadKeywords() { - //load the known keywords from an xml file - QFile file( - QStandardPaths::locate( - QStandardPaths::GenericDataLocation, - QLatin1String("cantor/juliabackend/keywords.xml") - ) - ); + // Put the keywords list in alphabetical order + m_keywords << QLatin1String("abstract") << QLatin1String("baremodule") << QLatin1String("begin") + << QLatin1String("bitstype") << QLatin1String("break") << QLatin1String("catch") << QLatin1String("const") + << QLatin1String("continue") << QLatin1String("do") << QLatin1String("elseif") << QLatin1String("else") + << QLatin1String("end") << QLatin1String("export") << QLatin1String("finally") << QLatin1String("for") + << QLatin1String("function") << QLatin1String("global") << QLatin1String("if") << QLatin1String("immutable") + << QLatin1String("import") << QLatin1String("importall") << QLatin1String("let") << QLatin1String("local") + << QLatin1String("macro") << QLatin1String("module") << QLatin1String("quote") << QLatin1String("return") + << QLatin1String("try") << QLatin1String("type") << QLatin1String("typealias") << QLatin1String("using") + << QLatin1String("while"); - if (!file.open(QIODevice::ReadOnly)) { - qWarning() << "error opening keywords.xml file. highlighting and" - << "completion won't work"; - return; - } - - QXmlStreamReader xml(&file); - - xml.readNextStartElement(); - while (xml.readNextStartElement()) { - const QStringRef name = xml.name(); - - if (name == QLatin1String("keywords") - or name == QLatin1String("variables") - or name == QLatin1String("plot_showing_commands")) { - while (xml.readNextStartElement()) { - Q_ASSERT( - xml.isStartElement() and xml.name() == QLatin1String("word") - ); + m_variables << QLatin1String("false") << QLatin1String("Inf") << QLatin1String("NaN") << QLatin1String("nothing") + << QLatin1String("true"); - const QString text = xml.readElementText(); - - if (name == QLatin1String("keywords")) { - m_keywords << text; - } else if (name == QLatin1String("variables")) { - m_variables << text; - } else if (name == QLatin1String("plot_showing_commands")) { - m_plotShowingCommands << text; - } - } - } else { - xml.skipCurrentElement(); - } - } - - if (xml.hasError()) { - qWarning() << "Error parsing keywords.xml:" << xml.errorString(); - } + m_plotShowingCommands << QLatin1String("contour") << QLatin1String("contourf") << QLatin1String("grid") + << QLatin1String("grid3d") << QLatin1String("histogram") << QLatin1String("imshow") + << QLatin1String("plot") << QLatin1String("plot3") << QLatin1String("polar") + << QLatin1String("polyline") << QLatin1String("polyline3d") << QLatin1String("polymarker") + << QLatin1String("polymarker3d") << QLatin1String("scatter") << QLatin1String("scatter3") + << QLatin1String("show") << QLatin1String("surface"); } void JuliaKeywords::addVariable(const QString &variable) { if (not m_variables.contains(variable)) { m_variables << variable; } } void JuliaKeywords::clearVariables() { m_removedVariables = m_variables; m_variables.clear(); } void JuliaKeywords::addFunction(const QString &function) { if (not m_functions.contains(function)) { m_functions << function; } } void JuliaKeywords::clearFunctions() { m_removedFunctions == m_functions; m_functions.clear(); } diff --git a/src/backends/julia/juliakeywords.h b/src/backends/julia/juliakeywords.h index d58ddd68..0d1f7eca 100644 --- a/src/backends/julia/juliakeywords.h +++ b/src/backends/julia/juliakeywords.h @@ -1,108 +1,108 @@ /* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * --- * Copyright (C) 2016 Ivan Lakhtanov */ #pragma once #include /** * Keywords storage for Julia session * * Class is implemented with singleton pattern */ class JuliaKeywords { public: /** * @return singleton instance pointer */ static JuliaKeywords *instance(); /** * @return list of Julia language predefined keywords */ const QStringList &keywords() const { return m_keywords; } /** * @return list of predefined commands, that are capable to show plot */ const QStringList &plotShowingCommands() const { return m_plotShowingCommands; } /** * @return list of known variable names */ const QStringList &variables() const { return m_variables; } /** * @return list of variables removed during the last clearVariables() call */ const QStringList &removedVariables() const { return m_removedVariables; } /** * Clears all known variables */ void clearVariables(); /** * Add new variable to the known list * * @param variable name of the variable to add */ void addVariable(const QString &variable); /** * @return list of known function names */ const QStringList &functions() const { return m_functions; } /** * @return list of functions removed during the last clearFunctions() call */ const QStringList &removedFunctions() const { return m_removedFunctions; } /** * Clears all known functions */ void clearFunctions(); /** * Add new function to the known list * * @param function name of the function to add */ void addFunction(const QString &function); private: QStringList m_keywords; //< list of predefined keywords QStringList m_plotShowingCommands; //< list of predefined plot showing cmds QStringList m_variables; //< list of variables known at the moment QStringList m_removedVariables; //< list of variables removed during cleaning QStringList m_functions; //< list of known function at the moment QStringList m_removedFunctions; //< list of functions removed during cleaning // We are hidding constructor and destructor for singleton JuliaKeywords() {} ~JuliaKeywords() {} /// Do first load of predefined stuff from keywords.xml - void loadFromFile(); + void loadKeywords(); }; diff --git a/src/backends/julia/keywords.xml b/src/backends/julia/keywords.xml deleted file mode 100644 index f8dff7e1..00000000 --- a/src/backends/julia/keywords.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - false - Inf - NaN - nothing - true - - - abstract - baremodule - begin - bitstype - break - catch - const - continue - do - elseif - else - end - export - finally - for - function - global - if - immutable - importall - import - let - local - macro - module - quote - return - try - typealias - type - using - while - - - contourf - contour - grid3d - grid - histogram - imshow - plot3 - plot - polar - polyline3d - polyline - polymarker3d - polymarker - scatter3 - scatter - show - surface - -