From 9d35c792ed05d1da4add6884378dc0fb14608555 Mon Sep 17 00:00:00 2001 From: shaina7837 Date: Tue, 17 Jun 2014 21:04:54 +0530 Subject: [PATCH] scad lexer added --- openscad.pro | 8 ++++++-- src/scadlexer.cpp | 29 +++++++++++++++++++++++++++++ src/scadlexer.h | 23 +++++++++++++++++++++++ src/scintillaeditor.cpp | 13 ++++++------- src/scintillaeditor.h | 4 +++- 5 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 src/scadlexer.cpp create mode 100644 src/scadlexer.h diff --git a/openscad.pro b/openscad.pro index 89af240b..a0270e70 100644 --- a/openscad.pro +++ b/openscad.pro @@ -289,7 +289,9 @@ HEADERS += src/typedefs.h \ \ src/AutoUpdater.h \ src/legacyeditor.h \ - src/scintillaeditor.h + src/scintillaeditor.h \ + src/scintillahighlighter.h \ + src/scadlexer.h SOURCES += src/version_check.cc \ src/ProgressWidget.cc \ @@ -374,7 +376,9 @@ SOURCES += src/version_check.cc \ src/mainwin.cc \ src/FontListDialog.cc \ src/legacyeditor.cc \ - src/scintillaeditor.cpp + src/scintillaeditor.cpp \ + src/scintillahighlighter.cpp \ + src/scadlexer.cpp # ClipperLib SOURCES += src/polyclipping/clipper.cpp diff --git a/src/scadlexer.cpp b/src/scadlexer.cpp new file mode 100644 index 00000000..3b44dac9 --- /dev/null +++ b/src/scadlexer.cpp @@ -0,0 +1,29 @@ +#include "scadlexer.h" + +ScadLexer::ScadLexer(QObject *parent) + : QsciLexerCPP(parent) +{ +} + +ScadLexer::~ScadLexer() +{ +} + +const char *ScadLexer::language() const +{ + return "SCAD"; +} + +const char *ScadLexer::keywords(int set) const +{ + if (set != 1) + return 0; + + return "abstract assert boolean break byte case catch char class " + "const continue default do double else extends final finally " + "float for future generic goto if implements import inner " + "instanceof int interface long native new null operator outer " + "package private protected public rest return short static " + "super switch synchronized this throw throws transient try var " + "void volatile while"; +} diff --git a/src/scadlexer.h b/src/scadlexer.h new file mode 100644 index 00000000..dbf344c9 --- /dev/null +++ b/src/scadlexer.h @@ -0,0 +1,23 @@ +#ifndef SCADLEXER_H +#define SCADLEXER_H + +#include + +//#include +#include + +class ScadLexer : public QsciLexerCPP +{ +public: + ScadLexer(QObject *parent); + virtual ~ScadLexer(); + const char *language() const; + const char *keywords(int set) const; + + private: + ScadLexer(const ScadLexer &); + ScadLexer &operator=(const ScadLexer &); + +}; + +#endif // SCADLEXER_H diff --git a/src/scintillaeditor.cpp b/src/scintillaeditor.cpp index a152dcbe..c7b81786 100644 --- a/src/scintillaeditor.cpp +++ b/src/scintillaeditor.cpp @@ -1,9 +1,10 @@ #include #include #include -#include +#include "scadlexer.h" #include "scintillaeditor.h" #include "parsersettings.h" +#include "Preferences.h" ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent) { @@ -18,10 +19,10 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent) qsci->indicatorDefine(QsciScintilla::RoundBoxIndicator, indicatorNumber); qsci->markerDefine(QsciScintilla::Circle, markerNumber); qsci->setMarkerBackgroundColor(QColor(255, 0, 0, 100), markerNumber); + highlighter = new ScintillaHighlighter(this); initFont(); initMargin(); initLexer(); - } void ScintillaEditor::indentSelection() { @@ -69,7 +70,7 @@ void ScintillaEditor::unhighlightLastError() void ScintillaEditor::setHighlightScheme(const QString &name) { - + highlighter->assignFormatsToTokens(name); } void ScintillaEditor::insertPlainText(const QString &text) @@ -138,8 +139,6 @@ void ScintillaEditor::onTextChanged() void ScintillaEditor::initLexer() { - QsciLexerCPP *lexer = new QsciLexerCPP(); - lexer->setDefaultFont(qsci->font()); - lexer->setFoldComments(true); - qsci->setLexer(lexer); + ScadLexer *lexer = new ScadLexer(this); + qsci->setLexer(lexer); } diff --git a/src/scintillaeditor.h b/src/scintillaeditor.h index efdb259c..b99df4bb 100644 --- a/src/scintillaeditor.h +++ b/src/scintillaeditor.h @@ -6,7 +6,7 @@ #include #include #include -#include "highlighter.h" +#include "scintillahighlighter.h" #include "editor.h" class ScintillaEditor : public EditorInterface @@ -18,6 +18,7 @@ public: void initFont(); void initMargin(); void initLexer(); + //QsciDocument *document() { return qsci->document();} public slots: void zoomIn(); @@ -41,6 +42,7 @@ private: QVBoxLayout *scintillaLayout; const int indicatorNumber = 1; const int markerNumber = 2; + ScintillaHighlighter *highlighter; }; #endif // SCINTILLAEDITOR_H