OpenSCAD 3D modelling language support
-
Hi,
I´m using http://www.thingiverse.com/thing:15363 Notepad++ configuration files to have context color, syntax highlight and auto completion in Notepad++ with OpenSCAD files. However those files do not allow for listing modules and functions in functions list windows. It seems from the manual that I have to create a new parser in functionList.xml. I tried to create a new parser for this language from the existing ones without success. I’m not a fluent programmer. I only need to detect the words ‘module’ and ‘function’.I added the following to functionsList.xml :
<association ext=".scad" id="OpenSCAD_file"/>
</associationMap>
<parsers>
<parser id=“OpenSCAD_file” displayName=“OpenSCAD” commentExpr=“((/*.?*)/|(//.?$))”>
<function
mainExpr=“^[\t ]*(module|function)\w+”
displayMode=“$functionName”>
<functionName>
<nameExpr expr=“[^\t(module|function)]+[\w]+”/>
</functionName>
</function>
</parser>Maybe there are some erros in this code, I don’t know. Any help is welcome. Thanks a lot.
Kind regards. -
Hello Joao,
When the possibility to link a parser_ID to a name of user-defined language was, first, added, in N++ v6.5, on October 2014, I noticed that the other method, using the extension name of user-defined files, didn’t work at all. Of course, I informed Don ( and some other guys too ) about that issue ! Refer to the first part of my post, below :
http://sourceforge.net/p/notepad-plus/discussion/331753/thread/627d7ac2/#9ff7
Unfortunately, that issue hasn’t been fixed, yet. So, Joao, in the assocciationMap node, you MUST use the only syntax :
<association userDefinedLangName="OpenSCAD" id="OpenSCAD_file"/>
By the way, you just have to create a new user-defined language with name OpenSCAD, using the extension scad. It’s no use to define the characteristics of your language, to allow your own functionList parser to work :-)
Secondly, I, slightly, changed your regexes for, both, the mainExpr and Expr items :
-
I suppose that there is, at least, one blank character, after the key words Module and Function
-
I changed the syntax
[\t ]
, with the simple\h
syntax. Indeed, the exact meaning of\h
, with the BOOST regex library, used in N++, is[\t \xA0]
( also known as an horizontal blank character ) -
In expr, I use the
\K
syntax, which allows the regex engine to forget everything located on the left of this form ! So, the exact name of the module or the function, without any possible leading blank characters, will be displayed in the FunctionList window :-)
Therefore, in the parsers node, add the lines below :
<parser id="OpenSCAD_file" displayName="OpenSCAD" commentExpr="((/*.?*)/|(//.?$))"> <function mainExpr="^\h*(module|function)\h+\w+" displayMode="$functionName"> <functionName> <nameExpr expr="^\h*(module|function)\h+\K\w+"/> </functionName> </function> </parser>
For instance, these regexes allow the detection of these four syntaxes, below :
module Test_1 function Test2 module Test3 function Test_4
Thirdly, your regex, used to detect the comments,
((/*.?*)/|(//.?$))
, is NOT a valid regular expression ! So, to define the correct regex, could you tell me the different cases of comments, in OpenSCAD language. From the general form of this regex, I presume that :-
A comment line begins with a double slash
//
-
A comment block begins, with the form
/*
and ends with the form*/
Am I right about it ?
See you soon !
Best regards,
guy038
P.S. :
Some people may think : Why couldn’t he use a lookbehind construction in expr ?
Indeed, the form below, with a positive lookbehind , seemingly, should work nice ?
<nameExpr expr="(?<=(module|function)\h+)\w+"/>
But, in the BOOST regex library, lookbehinds must represent an UNIQUE FIXED length strings. So, this regex is INVALID, for two reasons :
-
The two parts of the alternative,
(module|function)
, have a different length ( 6 characters for the string module and 8 characters for the string function ) -
The form
\h+
is NOT a fixed length string, as it stands for one or more horizontal blank character(s) !
Luckily, the
\K
syntax allows the regex engine to match :-
First, the part of the regex, located before the
\K
form -
Secondly, the part of the regex, located, after the
\K
form, which is the final regex matched !
-