Editing User:Shainasabarwal/ScadLexer for ScintillaEditor

From BRL-CAD

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 19: Line 19:
  
 
'''QsciLexerCustom inherited lexer'''
 
'''QsciLexerCustom inherited lexer'''
In my project UI brushup of OpenSCAD, I added QScintilla editor and used its CPP lexer class QsciLexerCPP for syntax highlighting. It worked fine. But after testing, some issues arises as SCAD is small and simple language as compared to CPP. In this project, we found the solution of the problem - Writing a lexer specifically for SCAD language.
+
In my project UI brushup of OpenSCAD, I added QScintilla editor and used its CPP lexer class QsciLexerCPP for syntax highlighting and it worked fine. But after testing, some issues arises as SCAD is small and simple language as compared to CPP. But in this project, we found the solution of the problem - Writing a lexer specifically for SCAD language.
 
QScintilla library has a class QsciLexerCustom (http://pyqt.sourceforge.net/Docs/QScintilla2/classQsciLexerCustom.html) which can be used as a base class for new language lexers. The advantage of using this class is that it doesn't require to make any change in QScintilla code or to re-compile it.  
 
QScintilla library has a class QsciLexerCustom (http://pyqt.sourceforge.net/Docs/QScintilla2/classQsciLexerCustom.html) which can be used as a base class for new language lexers. The advantage of using this class is that it doesn't require to make any change in QScintilla code or to re-compile it.  
This  will be inherited by our new class for Scad lexer and its virtual functions will be redefined.
+
This  will be inherited and its virtual functions will be redefined to make lexer for SCAD language.
  
 
'''Defining style index for SCAD language'''
 
'''Defining style index for SCAD language'''
Line 37: Line 37:
  
 
'''Syntax Highlighting'''
 
'''Syntax Highlighting'''
Syntax highlighting is very important feature of an editor as it improves the readability of the code and context of text. QScintilla editor in OpenSCAD as used CPP lexer, caused problems in highlighting as https://github.com/openscad/openscad/issues/1172
+
Syntax highlighting is very important feature of an editor as it improves the readability of the code and context of text. QScintilla editor in OpenSCAD as used CPP lexer caused problem in highlighting as https://github.com/openscad/openscad/issues/1172 Writing lexer for SCAD language will solve such problems.
Writing lexer for SCAD language will solve such problems.
 
 
For this, different functions for highlighting of keywords, operators, numbers, mathematical functions etc will be defined in the lexer. <br />
 
For this, different functions for highlighting of keywords, operators, numbers, mathematical functions etc will be defined in the lexer. <br />
 
For Example <br />
 
For Example <br />
 
<code>
 
<code>
void highlightKeywords(const QString &source, int start){
+
this is it
     foreach(QString word, keywordsList) {   //iterate keywords
+
void highlightKeywords(const QString &source, int start)
         if(source.contains(word)) {
+
{
int p = source.count(word);   // consider joining
+
     foreach(QString word, keywordsList) {
             int index = 0;   // begin to consider the indices
+
         if(source.contains(word)){
             while(p != 0) {
+
            int p = source.count(word);
                 int begin = source.indexOf(word, index);   //consider an index entry
+
             int index = 0;
                 index = begin+1;   //give point of reference for next iteration
+
             while(p!=0){
                 startStyling(start + begin);   //begin to style with an index entry
+
                 int begin = source.indexOf(word, index);
                 setStyling(word.length(), Keyword);   //for the length of a given style word.length Keyword
+
                 index = begin + 1;
                 startStyling(start + begin);   //finish styling
+
                 startStyling(start + begin);
 +
                 setStyling(word.length(), Keyword);
 +
                 startStyling(start + begin);
 
                 p--;
 
                 p--;
            }
+
          }
        }
+
      }
 
     }
 
     }
}
+
}
 
 
 
</code>
 
</code>
As shown, the function is using respective style index 'Keyword' for styling.
+
As shown, these functions will be using their respective style (as defined in the index) for coloring and setting fonts.  
The complete DEMO for keyword highlighting is: https://github.com/shaina7837/Scad-Lexer-demo
+
A demo for keyword highlighting is: https://gist.github.com/shaina7837/a172752b717e7fe7ec14
  
 
'''Different Color scheme'''
 
'''Different Color scheme'''
Line 71: Line 71:
  
 
'''Issue #1056 Toolbar Buttons'''
 
'''Issue #1056 Toolbar Buttons'''
Toolbars requires more icons as demanded here https://github.com/openscad/openscad/issues/1056
+
Toolbars requires more icons as demanded in this.  
  
 
'''Issue #1172 Syntax highlighting: # affects the whole line'''
 
'''Issue #1172 Syntax highlighting: # affects the whole line'''
Line 78: Line 78:
 
'''Issue #905 AutoComplete/ Calltips for QScintilla Editor'''
 
'''Issue #905 AutoComplete/ Calltips for QScintilla Editor'''
 
Many times, a programmer makes mistakes while writing syntax which can cause irritable errors and reduce productivity. In this case, auto completion or call tips helps a lot, which is considered as a great feature of an editor.
 
Many times, a programmer makes mistakes while writing syntax which can cause irritable errors and reduce productivity. In this case, auto completion or call tips helps a lot, which is considered as a great feature of an editor.
As a first step, only the functions defined in the scad language will be added to be shown in call tips. Further after the feedback of the community, names of the modules related to current project can be added.
+
As a first step, only the functions defined in the scad language will be added to be shown in call tips. Further on the feedback of the community, names of the modules related to current project can be added.
  
  
Line 123: Line 123:
 
'''Week 8(13 july)'''
 
'''Week 8(13 july)'''
 
*Solve scintilla related issues listed in issue #915
 
*Solve scintilla related issues listed in issue #915
*Add autocomplete feature solving issue #905
+
 
 
'''Week 9, 10(20 july)'''
 
'''Week 9, 10(20 july)'''
 
*Find a way to fetch icons from a icons file rather than directly coded in mainwin.cc
 
*Find a way to fetch icons from a icons file rather than directly coded in mainwin.cc
Line 159: Line 159:
  
 
===Code Review===
 
===Code Review===
I already has commit access to openscad respository at https://github.com/openscad/openscad. I will push my code in separate branch of same repository and send pull request so that mentors can review my code and then merge it up in master branch after testing.
+
I already has commit access to openscad respository at https://github.com/openscad/openscad. I will push my code in separate branch of same repository and send pull request so that mentors and review my code and then merge it up in master branch after complete testing.
  
 
==Why OpenSCAD?==
 
==Why OpenSCAD?==
Line 165: Line 165:
  
 
==Why SCAD lexer project?==
 
==Why SCAD lexer project?==
I came up with this idea of adding scad lexer as gsoc project, because last time, I, in my project 'UI brushup of OpenSCAD' used QsciLexerCPP as a base class for SCAD lexer class. But as the CPP is very large language as compared to SCAD so it is causing various issues, which I came to know later. In this year, I want to solve all those issues by writing a lexer specifically for scad lexer.
+
I came up with this idea of adding scad lexer as gsoc project, because last time, I in my project 'UI brushup of OpenSCAD' and used QsciLexerCPP as a base class for SCAD language. But as the CPP is very large language as compared to SCAD so it is causing various issue, which I came to know later. In this year, I want to solve all those issues by adding a lexer specifically for scad lexer.  
  
 
==Why Me?==
 
==Why Me?==
 
As we have very less number of women in technical study as compared to men, I want to be the part of technical community and spread awareness about women in tech in our society. I learnt a lot being the part of this community and want to contribute more through this program and afterwards. I also shared idea of improving the website of OpenSCAD but that couldn't be the part of this project, so I have plans to do so after completion of this project.
 
As we have very less number of women in technical study as compared to men, I want to be the part of technical community and spread awareness about women in tech in our society. I learnt a lot being the part of this community and want to contribute more through this program and afterwards. I also shared idea of improving the website of OpenSCAD but that couldn't be the part of this project, so I have plans to do so after completion of this project.

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)