From 3021ef4baf3411ca4058c4e627f8ab046cdfb101 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 10 Dec 2019 10:47:02 +0100 Subject: [PATCH] Add Alarm syntax --- libnymea-app-core/scripting/codecompletion.cpp | 15 ++++++++++----- libnymea-app-core/scriptsyntaxhighlighter.cpp | 4 ++-- nymea-app/ui/magic/ScriptEditor.qml | 7 +++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/libnymea-app-core/scripting/codecompletion.cpp b/libnymea-app-core/scripting/codecompletion.cpp index 0e46e680..ec3a88a4 100644 --- a/libnymea-app-core/scripting/codecompletion.cpp +++ b/libnymea-app-core/scripting/codecompletion.cpp @@ -15,6 +15,7 @@ CodeCompletion::CodeCompletion(QObject *parent): m_classes.insert("DeviceState", ClassInfo("DeviceState", {"id", "deviceId", "stateTypeId", "stateName", "value"}, {}, {"onValueChanged"})); m_classes.insert("DeviceEvent", ClassInfo("DeviceEvent", {"id", "deviceId", "eventTypeId", "eventName"}, {}, {"onTriggered"})); m_classes.insert("Timer", ClassInfo("Timer", {"id", "interval", "running", "repeat"}, {"start", "stop"}, {"onTriggered"})); + m_classes.insert("Alarm", ClassInfo("Alarm", {"id", "time", "endTime", "weekDays", "active"}, {}, {"onTriggered", "onActiveChanged"})); m_classes.insert("PropertyAnimation", ClassInfo("PropertyAnimation", {"id", "target", "targets", "property", "properties", "value", "from", "to", "easing", "exclude", "duration", "alwaysRunToEnd", "loops", "paused", "running"}, {"start", "stop", "pause", "resume", "complete"}, {"onStarted", "onStopped", "onFinished", "onRunningChanged"})); m_classes.insert("ColorAnimation", ClassInfo("ColorAnimation", {"id", "target", "targets", "property", "properties", "value", "from", "to", "easing", "exclude", "duration", "alwaysRunToEnd", "loops", "paused", "running"}, {"start", "stop", "pause", "resume", "complete"}, {"onStarted", "onStopped", "onFinished", "onRunningChanged"})); m_classes.insert("SequentialAnimation", ClassInfo("SequentialAnimation", {"id", "alwaysRunToEnd", "loops", "paused", "running"}, {"start", "stop", "pause", "resume", "complete"}, {"onStarted", "onStopped", "onFinished", "onRunningChanged"})); @@ -22,6 +23,7 @@ CodeCompletion::CodeCompletion(QObject *parent): m_classes.insert("PauseAnimation", ClassInfo("PauseAnimation", {"id", "duration", "alwaysRunToEnd", "loops", "paused", "running"}, {"start", "stop", "pause", "resume", "complete"}, {"onStarted", "onStopped", "onFinished", "onRunningChanged"})); m_attachedClasses.insert("Component", ClassInfo("Component", {}, {}, {"onCompleted", "onDestruction", "onDestroyed"})); + m_attachedClasses.insert("Alarm", ClassInfo("Alarm", {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "AllDays"}, {}, {})); m_genericSyntax.insert("property", "property "); m_genericSyntax.insert("function", "function "); @@ -307,7 +309,7 @@ void CodeCompletion::update() return; } - QRegExp rValueExp(" *[\\.a-zA-Z0-0]+:[ a-zA-Z0-0]*"); + QRegExp rValueExp(" *[\\.a-zA-Z0-0]+[^id]:[ a-zA-Z0-0]*"); if (rValueExp.exactMatch(blockText)) { QTextCursor tmp = m_cursor; tmp.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor); @@ -387,6 +389,7 @@ void CodeCompletion::update() } } if (isImperative) { + qDebug() << "Is imperative!"; // Starting a new expression? QRegExp newExpressionExp("(.*; [a-zA-Z0-9]*| *[a-zA-Z0-9]*)"); if (newExpressionExp.exactMatch(blockText)) { @@ -471,12 +474,14 @@ CodeCompletion::BlockInfo CodeCompletion::getBlockInfo(int position) const info.end = m_document->textDocument()->find("}", position).position(); info.valid = true; - + qDebug() << "block name" << blockStart.block().text(); info.name = blockStart.block().text(); - info.name.remove(QRegExp(" *\\{")); + info.name.remove(QRegExp(" *\\{ *")); + qDebug() << "stripped klammer" << info.name; while (info.name.contains(" ")) { info.name.remove(QRegExp(".* ")); } + qDebug() << "final name" << info.name; int childBlocks = 0; while (!blockStart.isNull() && blockStart.position() < position) { @@ -501,14 +506,14 @@ CodeCompletion::BlockInfo CodeCompletion::getBlockInfo(int position) const continue; } foreach (const QString &statement, blockStart.block().text().split(";")) { - qDebug() << "Have statement" << statement; +// qDebug() << "Have statement" << statement; QStringList parts = statement.split(":"); if (parts.length() != 2) { continue; } QString propName = parts.first().trimmed(); QString propValue = parts.last().split("//").first().trimmed().remove("\""); - qDebug() << "inserting:" << propName << "->" << propValue; +// qDebug() << "inserting:" << propName << "->" << propValue; info.properties.insert(propName, propValue); } if (!blockStart.movePosition(QTextCursor::NextBlock)) { diff --git a/libnymea-app-core/scriptsyntaxhighlighter.cpp b/libnymea-app-core/scriptsyntaxhighlighter.cpp index 9bfdc686..84f088cb 100644 --- a/libnymea-app-core/scriptsyntaxhighlighter.cpp +++ b/libnymea-app-core/scriptsyntaxhighlighter.cpp @@ -142,9 +142,9 @@ void ScriptSyntaxHighlighterPrivate::update(bool dark) // String literals format.setForeground(dark ? QColor("#e64ad7") : Qt::darkGreen); rule.format = format; - rule.pattern = QRegExp("\".*\""); + rule.pattern = QRegExp("\".[^\"]*\""); highlightingRules.append(rule); - rule.pattern = QRegExp("'.*'"); + rule.pattern = QRegExp("'.[^']*'"); highlightingRules.append(rule); // comments diff --git a/nymea-app/ui/magic/ScriptEditor.qml b/nymea-app/ui/magic/ScriptEditor.qml index 9eb5f56f..69148e46 100644 --- a/nymea-app/ui/magic/ScriptEditor.qml +++ b/nymea-app/ui/magic/ScriptEditor.qml @@ -317,8 +317,11 @@ Page { var newErrorLines = [] errors.forEach( function(error) { var parts = error.split(":") - append({line: parseInt(parts[0]), column: parseInt(parts[1]), message: parts[2].trim()}) - newErrorLines.push(parseInt(parts[0])); + var line = parseInt(parts.shift()); + var col = parseInt(parts.shift()); + var message = parts.join(":").trim(); + append({line: line, column: col, message: message}) + newErrorLines.push(line); }) errorLines = newErrorLines; if (errorModel.count > 0) {