diff --git a/src/backends/lua/luahighlighter.cpp b/src/backends/lua/luahighlighter.cpp index 3a6bec70..28c78a18 100644 --- a/src/backends/lua/luahighlighter.cpp +++ b/src/backends/lua/luahighlighter.cpp @@ -1,39 +1,39 @@ /* 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) 2014 Lucas Hermann Negri */ #include "luahighlighter.h" #include "luahelper.h" LuaHighlighter::LuaHighlighter(QObject* parent): DefaultHighlighter(parent) { addFunctions( luahelper_functions() ); addKeywords ( luahelper_keywords() ); addVariables( luahelper_variables() ); addRule(QRegExp(QLatin1String("[A-Za-z0-9_]+(?=\\()")) , functionFormat()); - addRule(QRegExp(QLatin1String("\".*\"")) , stringFormat()); - addRule(QRegExp(QLatin1String("'.*'")) , stringFormat()); + addRule(QRegExp(QLatin1String("\"[^\"]*\"")) , stringFormat()); + addRule(QRegExp(QLatin1String("'[^\'].*'")) , stringFormat()); addRule(QRegExp(QLatin1String("--[^\n]*")) , commentFormat()); // did not add support for the multiline comment or multiline string } LuaHighlighter::~LuaHighlighter() { } diff --git a/src/backends/octave/octavehighlighter.cpp b/src/backends/octave/octavehighlighter.cpp index f3a8b3a9..24fa09c4 100644 --- a/src/backends/octave/octavehighlighter.cpp +++ b/src/backends/octave/octavehighlighter.cpp @@ -1,127 +1,127 @@ /* Copyright (C) 2010 Miha Čančula 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. */ #include "octavehighlighter.h" #include "result.h" #include "session.h" #include OctaveHighlighter::OctaveHighlighter(QObject* parent, Cantor::Session* session): DefaultHighlighter(parent), m_session(session) { updateFunctions(); updateVariables(); m_operators << QLatin1String("+") << QLatin1String("-") << QLatin1String("*") << QLatin1String("/") << QLatin1String(".+") << QLatin1String(".-") << QLatin1String(".*") << QLatin1String("./") << QLatin1String("="); m_operators << QLatin1String("or") << QLatin1String("and") << QLatin1String("xor") << QLatin1String("not"); m_operators << QLatin1String("||") << QLatin1String("&&") << QLatin1String("=="); addRules(m_operators, operatorFormat()); m_keywords << QLatin1String("function") << QLatin1String("endfunction"); m_keywords << QLatin1String("for") << QLatin1String("endfor"); m_keywords << QLatin1String("while") << QLatin1String("endwhile"); m_keywords << QLatin1String("if") << QLatin1String("endif") << QLatin1String("else") << QLatin1String("elseif"); m_keywords << QLatin1String("switch") << QLatin1String("case") << QLatin1String("otherwise") << QLatin1String("endswitch"); m_keywords << QLatin1String("end"); addKeywords(m_keywords); - addRule(QRegExp(QLatin1String("\".*\"")), stringFormat()); - addRule(QRegExp(QLatin1String("'.*'")), stringFormat()); + addRule(QRegExp(QLatin1String("\"[^\"]*\"")), stringFormat()); + addRule(QRegExp(QLatin1String("'[^']*'")), stringFormat()); rehighlight(); } OctaveHighlighter::~OctaveHighlighter() { } void OctaveHighlighter::updateFunctions() { m_functionsExpr = m_session->evaluateExpression(QLatin1String("completion_matches('')")); connect(m_functionsExpr, &Cantor::Expression::statusChanged, this, &OctaveHighlighter::receiveFunctions); } void OctaveHighlighter::updateVariables() { m_varsExpr = m_session->evaluateExpression(QLatin1String("who")); connect(m_varsExpr, &Cantor::Expression::statusChanged, this, &OctaveHighlighter::receiveVariables); } void OctaveHighlighter::receiveFunctions() { qDebug(); if (m_functionsExpr->status() != Cantor::Expression::Done || !m_functionsExpr->result()) { return; } QStringList names = m_functionsExpr->result()->toHtml().split(QLatin1String("
\n")); QLatin1String under("__"); while (!names.first().contains(under)) { names.removeFirst(); } while (names.first().contains(under)) { names.removeFirst(); } int i = names.indexOf(QLatin1String("zlim")); // Currently the last function alphabetically while (i > 0 && i < names.size() && names.at(i).startsWith(QLatin1Char('z'))) { // Check if there are more functions after zlim i++; } names.erase(names.begin() + i, names.end()); qDebug() << "Received" << names.size() << "functions"; addFunctions(names); // The list of functions from completion_matches('') includes keywords and variables too, so we have to re-add them addVariables(m_variables); addKeywords(m_keywords); rehighlight(); } void OctaveHighlighter::receiveVariables() { if (m_varsExpr->status() != Cantor::Expression::Done || !m_varsExpr->result()) { return; } QString res = m_varsExpr->result()->toHtml(); res.replace(QLatin1String("
"),QLatin1String(" ")); res.remove(0, res.indexOf(QLatin1Char('\n'))); res.remove(QLatin1Char('\n')); res = res.trimmed(); m_variables.clear(); foreach ( const QString& var, res.split(QLatin1Char(' '), QString::SkipEmptyParts)) { m_variables << var.trimmed(); } qDebug() << "Received" << m_variables.size() << "variables"; addVariables(m_variables); rehighlight(); } diff --git a/src/backends/sage/sagehighlighter.cpp b/src/backends/sage/sagehighlighter.cpp index 0b3c3a0d..cb259268 100644 --- a/src/backends/sage/sagehighlighter.cpp +++ b/src/backends/sage/sagehighlighter.cpp @@ -1,83 +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) 2009 Alexander Rieder */ #include "sagehighlighter.h" #include "sagekeywords.h" #include SageHighlighter::SageHighlighter(QObject* parent) : Cantor::DefaultHighlighter(parent) { addRule(QRegExp(QLatin1String("[A-Za-z0-9_]+(?=\\()")), functionFormat()); QStringList keywords; //Preprocessor keywords = SageKeywords::instance()->keywords(); //specialvars keywords << QLatin1String("None") << QLatin1String("self") << QLatin1String("True") << QLatin1String("true") << QLatin1String("False") << QLatin1String("false") << QLatin1String("NotImplemented") << QLatin1String("Ellipsis"); addKeywords(keywords); QStringList builtinFunctions; builtinFunctions << QLatin1String("__future__") << QLatin1String("__import__") << QLatin1String("__name__") << QLatin1String("abs") << QLatin1String("all") << QLatin1String("any") << QLatin1String("apply") << QLatin1String("basestring") << QLatin1String("bool") << QLatin1String("buffer") << QLatin1String("callable") << QLatin1String("chr") << QLatin1String("classmethod") << QLatin1String("cmp") << QLatin1String("coerce") << QLatin1String("compile") << QLatin1String("complex") << QLatin1String("delattr") << QLatin1String("dict") << QLatin1String("dir") << QLatin1String("divmod") << QLatin1String("enumerate") << QLatin1String("eval") << QLatin1String("execfile") << QLatin1String("file") << QLatin1String("filter") << QLatin1String("float") << QLatin1String("frozenset") << QLatin1String("getattr") << QLatin1String("globals") << QLatin1String("hasattr") << QLatin1String("hash") << QLatin1String("hex") << QLatin1String("id") << QLatin1String("input") << QLatin1String("int") << QLatin1String("intern") << QLatin1String("isinstance") << QLatin1String("issubclass") << QLatin1String("iter") << QLatin1String("len") << QLatin1String("list") << QLatin1String("locals") << QLatin1String("long") << QLatin1String("map") << QLatin1String("max") << QLatin1String("min") << QLatin1String("object") << QLatin1String("oct") << QLatin1String("open") << QLatin1String("ord") << QLatin1String("pow") << QLatin1String("property") << QLatin1String("range") << QLatin1String("raw_input") << QLatin1String("reduce") << QLatin1String("reload") << QLatin1String("repr") << QLatin1String("reversed") << QLatin1String("round") << QLatin1String("set") << QLatin1String("setattr") << QLatin1String("slice") << QLatin1String("sorted") << QLatin1String("staticmethod") << QLatin1String("str") << QLatin1String("sum") << QLatin1String("super") << QLatin1String("tuple") << QLatin1String("type") << QLatin1String("unichr") << QLatin1String("unicode") << QLatin1String("vars") << QLatin1String("xrange") << QLatin1String("zip"); addRules(builtinFunctions, functionFormat()); addRule(QRegExp(QLatin1String("\\S*[a-zA-Z\\-\\_]+\\S*\\.(?!\\d)")), objectFormat()); QStringList exceptionPatterns; exceptionPatterns<< QLatin1String("ArithmeticError") << QLatin1String("AssertionError") << QLatin1String("AttributeError") << QLatin1String("BaseException") << QLatin1String("DeprecationWarning") << QLatin1String("EnvironmentError") << QLatin1String("EOFError") << QLatin1String("Exception") << QLatin1String("FloatingPointError") << QLatin1String("FutureWarning") << QLatin1String("GeneratorExit") << QLatin1String("IOError") << QLatin1String("ImportError") << QLatin1String("ImportWarning") << QLatin1String("IndexError") << QLatin1String("KeyError") << QLatin1String("KeyboardInterrupt") << QLatin1String("LookupError") << QLatin1String("MemoryError") << QLatin1String("NameError") << QLatin1String("NotImplementedError") << QLatin1String("OSError") << QLatin1String("OverflowError") << QLatin1String("PendingDeprecationWarning") << QLatin1String("ReferenceError") << QLatin1String("RuntimeError") << QLatin1String("RuntimeWarning") << QLatin1String("StandardError") << QLatin1String("StopIteration") << QLatin1String("SyntaxError") << QLatin1String("SyntaxWarning") << QLatin1String("SystemError") << QLatin1String("SystemExit") << QLatin1String("TypeError") << QLatin1String("UnboundLocalError") << QLatin1String("UserWarning") << QLatin1String("UnicodeError") << QLatin1String("UnicodeWarning") << QLatin1String("UnicodeEncodeError") << QLatin1String("UnicodeDecodeError") << QLatin1String("UnicodeTranslateError") << QLatin1String("ValueError") << QLatin1String("Warning") << QLatin1String("WindowsError") << QLatin1String("ZeroDivisionError"); addRules(exceptionPatterns, objectFormat()); - addRule(QRegExp(QLatin1String("\".*\"")), stringFormat()); - addRule(QRegExp(QLatin1String("'.*'")), stringFormat()); + addRule(QRegExp(QLatin1String("\"[^\"]*\"")), stringFormat()); + addRule(QRegExp(QLatin1String("'[^']*'")), stringFormat()); addRule(QRegExp(QLatin1String("#[^\n]*")), commentFormat()); } SageHighlighter::~SageHighlighter() { } diff --git a/src/backends/scilab/scilabhighlighter.cpp b/src/backends/scilab/scilabhighlighter.cpp index 826f62ed..8cc8b572 100644 --- a/src/backends/scilab/scilabhighlighter.cpp +++ b/src/backends/scilab/scilabhighlighter.cpp @@ -1,110 +1,110 @@ /* 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) 2011 Filipe Saraiva */ #include "scilabhighlighter.h" #include "scilabkeywords.h" #include #include ScilabHighlighter::ScilabHighlighter(QObject* parent) : Cantor::DefaultHighlighter(parent) { qDebug() << "ScilabHighlighter construtor"; addRule(QRegExp(QLatin1String("\\b[A-Za-z0-9_]+(?=\\()")), functionFormat()); //Code highlighting the different keywords addKeywords(ScilabKeywords::instance()->keywords()); addRule(QLatin1String("FIXME"), commentFormat()); addRule(QLatin1String("TODO"), commentFormat()); addFunctions(ScilabKeywords::instance()->functions()); addVariables(ScilabKeywords::instance()->variables()); - addRule(QRegExp(QLatin1String("\".*\"")), stringFormat()); - addRule(QRegExp(QLatin1String("'.*'")), stringFormat()); + addRule(QRegExp(QLatin1String("\"[^\"]*\"")), stringFormat()); + addRule(QRegExp(QLatin1String("'[^']*'")), stringFormat()); addRule(QRegExp(QLatin1String("//[^\n]*")), commentFormat()); commentStartExpression = QRegExp(QLatin1String("/\\*")); commentEndExpression = QRegExp(QLatin1String("\\*/")); } ScilabHighlighter::~ScilabHighlighter() { } void ScilabHighlighter::highlightBlock(const QString& text) { qDebug() << "ScilabHighlighter::highlightBlock"; qDebug() << "text: " << text; if (skipHighlighting(text)){ qDebug() << "skipHighlighting(" << text << " ) " << "== true"; return; } //Do some backend independent highlighting (brackets etc.) DefaultHighlighter::highlightBlock(text); setCurrentBlockState(0); int startIndex = 0; if (previousBlockState() != 1) startIndex = commentStartExpression.indexIn(text); while (startIndex >= 0){ int endIndex = commentEndExpression.indexIn(text, startIndex); int commentLength; if (endIndex == -1){ setCurrentBlockState(1); commentLength = text.length() - startIndex; } else { commentLength = endIndex - startIndex + commentEndExpression.matchedLength(); } setFormat(startIndex, commentLength, commentFormat()); startIndex = commentStartExpression.indexIn(text, startIndex + commentLength); } } void ScilabHighlighter::addVariableHighlight() { addVariables(ScilabKeywords::instance()->variables()); rehighlight(); } void ScilabHighlighter::updateHighlight() { qDebug(); addVariables(ScilabKeywords::instance()->variables()); addKeywords(ScilabKeywords::instance()->keywords()); addFunctions(ScilabKeywords::instance()->functions()); rehighlight(); } QString ScilabHighlighter::nonSeparatingCharacters() const { qDebug() << "ScilabHighlighter::nonSeparatingCharacters() function"; return QLatin1String("[%]"); }