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 8: Line 8:
  
 
==Background Information==
 
==Background Information==
*Computer Science Engineering student at Guru Nanak Dev Engineering College, Ludhiana, Punjab, India. Presently studying in 4th year.
+
*Computer Science Engineering student at Guru Nanak Dev Engineering College, Ludhina, Punjab, India. Presently studying in 4th year.
*I have worked in C++, Qt, Wt, HTML, CSS, Javascript, Ruby on rails, flex and Bison and Wordpress.
+
*I have worked in are C++, Qt, Wt, HTML, CSS, Javascript, Ruby on rails, flex and Bison and Wordpress.
 
*Have worked with OpenSCAD in 2014 on project UI Brushup of OpenSCAD that was about enhancing the interface for users of OpenSCAD by adding QScintilla Editor and its various features, Toolbars with small 2D icons. Options to choose color scheme of the solid models, and launching screen of OpenSCAD.  
 
*Have worked with OpenSCAD in 2014 on project UI Brushup of OpenSCAD that was about enhancing the interface for users of OpenSCAD by adding QScintilla Editor and its various features, Toolbars with small 2D icons. Options to choose color scheme of the solid models, and launching screen of OpenSCAD.  
 +
*Also interested in front end development. Recently developed a wordpress theme for language learning institure - Global Careers. Some screenshots are:
 
*I am active member of Linux User Group, Ludhiana where the students are made aware about the open source technologies and motivated to contribute in them.
 
*I am active member of Linux User Group, Ludhiana where the students are made aware about the open source technologies and motivated to contribute in them.
  
Line 16: Line 17:
  
 
===Title: SCAD lexer for QScintilla Editor===
 
===Title: SCAD lexer for QScintilla Editor===
This project aims to make lexer specifically for SCAD language. Currently, QScintilla is using CPP lexer, which cause syntax problem as CPP language is very large as compared to SCAD language of OpenSCAD. With this, some scintilla and GUI related issues will also be solved.
+
This project aims to make lexer specifically for SCAD language. Currently, QScintilla is using CPP lexer, which cause syntax problem as CPP language is very large as compared to SCAD language of OpenSCAD. With this, some scintilla related issues will also be solved.
  
 
'''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.
+
QScintilla library has a class QsciLexerCustom which can be used as a base 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 and its virtual functions will be redefined to make lexer for SCAD language.
This  will be inherited by our new class for Scad lexer and its virtual functions will be redefined.
 
  
 
'''Defining style index for SCAD language'''
 
'''Defining style index for SCAD language'''
 
SCAD language includes various categories of keywords including mathematical functions, solid primitives as defined: http://www.openscad.org/cheatsheet/ ,Operators, Numbers, Comments - single line as well as multiline, single quoted and double quoted strings, parenthesis and variable names.
 
SCAD language includes various categories of keywords including mathematical functions, solid primitives as defined: http://www.openscad.org/cheatsheet/ ,Operators, Numbers, Comments - single line as well as multiline, single quoted and double quoted strings, parenthesis and variable names.
The lexer firstly requires to index the styles of different keywords for the purpose of syntax highlighting using functions of qsciLexerCustom.
+
The lexer firtly requires to index the styles for the purpose of syntax highlighting using functions of qsciLexerCustom.
This indexing can be done using an enum as
 
<code>
 
enum {
 
        Default = 0
 
        Keyword = 1
 
        Comment = 2
 
        Operator = 3
 
}
 
</code>
 
  
 
'''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
+
Different functions for highlighting of keywords, operators, numbers, mathematical functions etc will be defined in the lexer which will be using their respective style (as defined in the index) for coloring and setting fonts.  
Writing lexer for SCAD language will solve such problems.
+
A demo for keyword highlighting is: https://gist.github.com/shaina7837/a172752b717e7fe7ec14
For this, different functions for highlighting of keywords, operators, numbers, mathematical functions etc will be defined in the lexer. <br />
 
For Example <br />
 
<code>
 
void highlightKeywords(const QString &source, int start){
 
    foreach(QString word, keywordsList) {    //iterate keywords
 
        if(source.contains(word)) {
 
int p = source.count(word);    // consider joining
 
            int index = 0;    // begin to consider the indices
 
            while(p != 0) {
 
                int begin = source.indexOf(word, index);    //consider an index entry
 
                index = begin+1;    //give point of reference for next iteration
 
                startStyling(start + begin);    //begin to style with an index entry
 
                setStyling(word.length(), Keyword);    //for the length of a given style word.length Keyword
 
                startStyling(start + begin);    //finish styling
 
                p--;
 
            }
 
        }
 
    }
 
}
 
 
 
</code>
 
As shown, the function is using respective style index 'Keyword' for styling.
 
The complete DEMO for keyword highlighting is: https://github.com/shaina7837/Scad-Lexer-demo
 
  
 
'''Different Color scheme'''
 
'''Different Color scheme'''
Not every color suits to everyone. People like to have choices specially in case of colors, so it is very important to have different color schemes as options in preferences to be selected by the user. This feature helps to improve the usability of software a lot.
+
A number of different color schemes for users to be selected in preferences will be defined. In code, it will require checking the selected scheme and define style index accordingly.
It will require checking the selected scheme and define style index accordingly.
 
  
 
'''Issue #1108 Customizable Icon set'''
 
'''Issue #1108 Customizable Icon set'''
Line 71: Line 38:
  
 
'''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'''
 
As presently, qscintilla uses CPP lexer, so it takes the whole line as preprocessor directive, started with #. With writing lexer specifically for SCAD language, this problem will be tackled.
 
As presently, qscintilla uses CPP lexer, so it takes the whole line as preprocessor directive, started with #. With writing lexer specifically for SCAD language, this problem will be tackled.
 
'''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.
 
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.
 
 
  
 
'''Issue #1075 Add multi-line, nested list '[' ']' indentation and tree folding to QScintilla Editor'''
 
'''Issue #1075 Add multi-line, nested list '[' ']' indentation and tree folding to QScintilla Editor'''
Line 86: Line 48:
 
'''Issue #915 Scintilla Editor issues'''
 
'''Issue #915 Scintilla Editor issues'''
 
The remaining issues such as auto scroll to error line after compilation, convert tab into spaces and highlighting the folded region will be solved.
 
The remaining issues such as auto scroll to error line after compilation, convert tab into spaces and highlighting the folded region will be solved.
 +
 +
  
 
==MILESTONES==
 
==MILESTONES==
Line 123: Line 87:
 
'''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 123:
  
 
===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 129:
  
 
==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)