graastein Posted October 3, 2006 Report Share Posted October 3, 2006 Hello Is it possible to remove the comment like the one on the screenshot? Remove everything from /* untiltil */ I'm going to use the text to run a state machine. And also let the user make comments in the "code" And a second question: It it possible to color the comment when viewed on the screen? Like on the second screenshot? (The text in green) Quote Link to comment
LAVA 1.0 Content Posted October 3, 2006 Report Share Posted October 3, 2006 HelloIs it possible to remove the comment like the one on the screenshot? Remove everything from /* untiltil */ I'm going to use the text to run a state machine. And also let the user make comments in the "code" Use match reguar expression node and cofigure it so that it matches the things you want to remove. Then run it in a loop as long as it matches something. To learn regular expressions check this very good web site. Quote Link to comment
jaegen Posted October 3, 2006 Report Share Posted October 3, 2006 And a second question: It it possible to color the comment when viewed on the screen? Like on the second screenshot? (The text in green) Your second question (syntax highlighting) made me wonder - has anyone successfully developed a syntax-highlighting text control in LabVIEW? Scintilla is an editor component used in a whole bunch of open source text-based projects. There is an ActiveX control wrapper for it here - has anyone used this? I downloaded it and tried it briefly, but using it wasn't as intuitive as I thought it would be, and I don't have time to pour through the documentation right now. Of course, a LabVIEW application which includes a C/C++ (or any text-based language, for that matter) syntax highlighter is probably the last thing most of us LabVIEW freaks would ever want to see :laugh: , but this could actually be useful (our big project includes a scripting component, for which a syntax highlighting editor could be useful). ... On second thought, maybe building a LV-based IDE for text-based source code editing (like SciTE, CodeBlocks, Dev-C++, Jedit, etc.) would be a great marketing tool for LV Jaegen Quote Link to comment
LAVA 1.0 Content Posted October 3, 2006 Report Share Posted October 3, 2006 Your second question (syntax highlighting) made me wonder - has anyone successfully developed a syntax-highlighting text control in LabVIEW? Not a complete editor, but you certainly can do a lot programatically with colors and fonts, see the PJM Blog post HERE Quote Link to comment
graastein Posted October 3, 2006 Author Report Share Posted October 3, 2006 Thanks guys I worked it out with the "Search and Replace String" function. The regular expression to remove CSS-style comments is : \/\*[^*]*\*+([^/][^*]*\*+)*\/ :ninja: Attached my solution. Haven’t looked at the colored text yet. Will post my findings there too:) Download File:post-3560-1159946324.vi (For LabVIEW 8.0) Quote Link to comment
Mellroth Posted October 4, 2006 Report Share Posted October 4, 2006 Hi, I just took a quick look at your solution, and I think you can make this even easier. 1. Enable "Replace All" option and skip the loop. 2. remove the \ to cancel special interpretation of / (at the beginning and at the end of the search string) I made a quick implementation to colorize your comments, to give you an idea how it can be done. Hope it works Download File:post-5958-1159977170.vi /J Edit: I updated the attachment so that it is saved in LV8 instead of LV8.20, sorry... Thanks guys I worked it out with the "Search and Replace String" function.The regular expression to remove CSS-style comments is : /\*[^*]*\*/ :ninja: Quote Link to comment
bsvingen Posted October 4, 2006 Report Share Posted October 4, 2006 I made a quick implementation to colorize your comments, to give you an idea how it can be done.Hope it works /J That was pritty darn cool :thumbup: Quote Link to comment
graastein Posted October 4, 2006 Author Report Share Posted October 4, 2006 Hi,I just took a quick look at your solution, and I think you can make this even easier. 1. Enable "Replace All" option and skip the loop. 2. remove the \ to cancel special interpretation of / (at the beginning and at the end of the search string) I made a quick implementation to colorize your comments, to give you an idea how it can be done. Hope it works Download File:post-5958-1159977170.vi /J Edit: I updated the attachment so that it is saved in LV8 instead of LV8.20, sorry... Fantastic :thumbup: yes that made my code easier Your color the comments vi worked great when run once, but I'm aiming at updating the colouring when typing. Maybe an event structure is the way to go. But as you see in my attachment it constantly marks all the text, and then the user deletes what he has already typed in. Download File:post-3560-1159979520.vi Quote Link to comment
Mellroth Posted October 4, 2006 Report Share Posted October 4, 2006 The problem is that you have to set the selection in order to set color. After the loop is done, set the text selection to the next write position. If you are going to edit a lot of text, you will have to come up with a clever scheme to reduce updates, timing maybe? Download File:post-5958-1159980405.vi /J Fantastic :thumbup: yes that made my code easier Your color the comments vi worked great when run once, but I'm aiming at updating the colouring when typing. Maybe an event structure is the way to go. But as you see in my attachment it constantly marks all the text, and then the user deletes what he has already typed in. Quote Link to comment
graastein Posted October 4, 2006 Author Report Share Posted October 4, 2006 The problem is that you have to set the selection in order to set color. After the loop is done, set the text selection to the next write position. If you are going to edit a lot of text, you will have to come up with a clever scheme to reduce updates, timing maybe? Download File:post-5958-1159980405.vi /J Yes, maybe something like a countdown after each value change before updating, and each new valuechange resets the countdown. Quote Link to comment
Mike Ashe Posted October 24, 2006 Report Share Posted October 24, 2006 These are all nice. Since there are still a lot of people and projects using LabVIEW 7.1, it might be nice to repost in 7.x. Quote Link to comment
Adam Kemp Posted October 24, 2006 Report Share Posted October 24, 2006 I'm glad people are using the regular expression features. It makes me happy. Here's another regexp that may or may not perform better (I'll leave benchmarks as an exercise to the reader) : \/\*([^*]|(\*(?!\/)))*\*\/ It says "match /*, followed by a non-* or a * that is not followed by /, followed by /*". The ?! is a "negative lookahead" match. You can find more info the "definitive" reference for Perl-Compatible regular expressions here: http://www.perl.com/doc/manual/html/pod/perlre.html These are all nice. Since there are still a lot of people and projects using LabVIEW 7.1, it might be nice to repost in 7.x. The regular expression feature was added in 8.0. If you want to do this in a pre-8.0 version of LabVIEW, then you'll have to write a simple parser to strip comments. Not that this would be a terrible thing. Regular expressions are great for simplicity of code and for writing validation code, etc., but they're usually very inefficient. For simple parsing problems (like this one), a well-written straight-through parse routine would perform far better. In fact, if this application is likely to deal with large amounts of text, then I would recommend rewriting the parser for performance reasons. Just be careful to get it right. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.