File indexing completed on 2024-05-26 11:22:06

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
0004 */
0005 
0006 #include "maximakeywords.h"
0007 
0008 #include <QDebug>
0009 
0010 #include <KSyntaxHighlighting/Repository>
0011 #include <KSyntaxHighlighting/Definition>
0012 
0013 MaximaKeywords* MaximaKeywords::instance()
0014 {
0015     static MaximaKeywords* inst=nullptr;
0016     if(inst==nullptr)
0017     {
0018         inst=new MaximaKeywords();
0019         inst->loadKeywords();
0020     }
0021 
0022     return inst;
0023 }
0024 
0025 void MaximaKeywords::loadKeywords()
0026 {
0027     KSyntaxHighlighting::Repository m_repository;
0028     KSyntaxHighlighting::Definition definition = m_repository.definitionForName(QLatin1String("Maxima"));
0029     m_keywords = definition.keywordList(QLatin1String("MaximaKeyword"));
0030     m_functions = definition.keywordList(QLatin1String("MaximaFunction"));
0031     m_variables = definition.keywordList(QLatin1String("MaximaVariable"));
0032 
0033     // This is missing in KSyntaxHighlighting.
0034     // https://phabricator.kde.org/D18714
0035     // OUTOFDATE: Remove after 5.55 KSyntaxHighlighting version
0036     m_variables << QLatin1String("%pi") << QLatin1String("%e") << QLatin1String(" %i")
0037                 << QLatin1String("%gamma") << QLatin1String("ind") << QLatin1String("inf")
0038                 << QLatin1String("infinity") << QLatin1String("minf") << QLatin1String("%phi")
0039                 << QLatin1String("und") << QLatin1String("zeroa") << QLatin1String("zerob");
0040 
0041     m_functions << QLatin1String("celine");
0042 
0043     // We use qBinarySearch with this lists
0044     std::sort(m_keywords.begin(), m_keywords.end());
0045     std::sort(m_functions.begin(), m_functions.end());
0046     std::sort(m_variables.begin(), m_variables.end());
0047 }
0048 
0049 const QStringList& MaximaKeywords::variables() const
0050 {
0051     return m_variables;
0052 }
0053 
0054 const QStringList& MaximaKeywords::functions() const
0055 {
0056     return m_functions;
0057 }
0058 
0059 const QStringList& MaximaKeywords::keywords() const
0060 {
0061     return m_keywords;
0062 }