Skip to content

GSOC 2015 Project ScadLexer

Shaina Sabarwal edited this page Aug 17, 2015 · 3 revisions

Introduction

OpenSCAD's Scintilla Editor is now having new lexer named ScadLexer that is developed by using a QScintilla class QsciLexerCustom and lexertl.

  • QsciLexerCustom class of Qscintilla has been designed specifically for writing custom lexers providing various functions for coloring and changing font of different tokens for the purpose of syntax highlighting.
  • lexertl is a lexical analysis generator written by Ben Hanson. Lexertl tool is reliable and highly flexible that generates the state machine from the defined lexer rules, and return the list of tokens, each with unique ID, that has been used by QScintilla lexer custom class to be highlighted for the purpose of syntax highlighting in the Editor.

The combination of QScintilla and lexertl worked smoothly. Also the problems such as this are solved which was causing due to using CPP lexer used by OpenSCAD's Scintilla Editor, but as ScadLexer has been written specifically for SCAD language of OpenSCAD, we have more control over it.

Syntax Highlighting

With the help of lexertl rules defined using regular expressions and QsciLexerCustom's styling functions, we were able to provide a number of syntax highlighting schemes for the Scintilla editor. Even the user can add its own color scheme by inserting a json file in ColorSchemes/Editor/ folder in OpenSCAD. https://github.com/openscad/openscad/tree/master/color-schemes/editor

Folding & Auto-Indentation.

Due to new ScadLexer, we were able to fold the code at each block start and ending with braces '{' and '}', and with square brackets '[' and ']'. The multiline comments are also get folded. The indents at each block started with '{' and ending with '}' will be inserted automatically.

Auto Scroll to Compilation error.

In case of any error, the cursor will be positioned at error position and window will be scrolled to make error mark shown in front of you.

Adding the custom toolbar iconset

Now the user can also add his own iconset by just dropping the folder of icons for dark and light theme in Images/ folder of OpenSCAD code. By putting the folder of iconset, an option with name of folder will be added automatically in Preferences' icons window, from where the user can change the toolbar icons. the The flaticons is the default iconset.

Clone this wiki locally