Author Topic: Get rid of comments (Using NP++ or VLIDE)  (Read 12673 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #30 on: December 18, 2017, 07:42:02 PM »
lol, while I could solve that I'm not going to encourage horrible coding style.  :police:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #31 on: December 19, 2017, 02:47:37 PM »
Here's another way:
Code: [Select]
(defun stripcomments ( lsp / des rgx rtn str tmp )
    (if (setq des (open lsp "r"))
        (progn
            (while (setq str (read-line des)) (setq tmp (vl-list* "\n" str tmp)))
            (close des)
            (cond
                (   (null (setq rgx (vlax-create-object "vbscript.regexp")))
                    (prompt "\nUnable to interface with RegEx object.")
                )
                (   (vl-catch-all-error-p
                        (setq rtn
                            (vl-catch-all-apply
                               '(lambda ( )
                                    (vlax-put-property rgx 'global actrue)
                                    (vlax-put-property rgx 'multiline actrue)
                                    (vlax-put-property rgx 'pattern "(\"(?:[^\\\\\"]|\\\\.)*\")|(?:;\\|[\\S\\s]+?\\|;)|(?:;[^\\n]*)")
                                    (vlax-invoke rgx 'replace (apply 'strcat (reverse tmp)) "$1")
                                )
                            )
                        )
                    )
                    (prompt (strcat "\nError: " (vl-catch-all-error-message rtn)))
                )
                (   (princ rtn)   )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #32 on: December 20, 2017, 08:45:30 AM »
Great job MP and Lee Mac!
I should have included "{Challenge}" in the topic's name, since it looks like one.



Here's another way:
...

Approach, what exactly I had in mind:


If its possible with regular expressions, then by knowing the correct expression one could do it in a lisp routine through the regexp object and process that certain .lsp file. (as a regex dummy, just asking: anyone about to try?)


So thanks Lee, really apreciate this one!  :yay!:

I have two (offtopic) questions, though:
  • Whats the general use of regular expressions? Is it somewhat a very powerful wcmatch function?
  • How/where one can visualise/test the regex pattern, so it works as expected?

The regex dummy asking, hope you don't mind (or anyone if could answer).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #33 on: December 20, 2017, 10:47:56 AM »
There are a glut of regex testers -- regexstorm is not bad.

Note that in lisp backslashes and quotes etc. have to escaped, so a regex pattern like this:

("(?:[^\\"]|\\.)*")|(?:;\|[\S\s]+?\|;)|(?:;[^\n]*)

That is testable in a tool like regexstorm needs to look like this in lisp:

(\"(?:[^\\\\\"]|\\\\.)*\")|(?:;\\|[\\S\\s]+?\\|;)|(?:;[^\\n]*)

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #34 on: December 20, 2017, 11:22:44 AM »
Thanks MP, your comment here will help me solve this regex mystery till the end of 2017.
BTW every time I use something, my head associates the first type of problem/technique/solution with the guy(s) who helped me there(or introduced), i.e.:
  (<getridofcomments> MP LeeMac) (<regex> MP)
So I just carved these additional associations in my brain.  :crazy2:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #35 on: December 20, 2017, 11:43:39 AM »
Ha, you're most welcome.

In case it wasn't obvious the regexstorm site has a reasonable regex reference.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #36 on: December 20, 2017, 12:09:08 PM »
So overall a regex pattern like this, is something like a very powerful pattern-string-search function. And can be used to manipulate these certain fragments like replacing/removing them.

Does that sound like a valid general use of regular expressions?  :thinking:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #37 on: December 20, 2017, 12:20:42 PM »
Quote from: Dale Fugier (author of DOSLib)
A regular expression is a string that describes a match pattern. The match pattern provides a template that can be used to test another string, the search string, for a matching sub-string. In its simplest form, the match pattern string is just a sequence of characters that must be matched. For example, the pattern "fred" matches this exact sequence of characters and only this sequence. More sophisticated regular expressions can match against items such as file names, path names, and Internet URLs. Thus, the RegExp object is frequently used to validate data for correct form and syntax.

source
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #38 on: December 20, 2017, 12:41:06 PM »
Thanks again, Michael - I think all the stuff you posted will be enough. :)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #39 on: December 20, 2017, 01:05:43 PM »
:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #40 on: December 20, 2017, 01:23:35 PM »
Where RegEx testers are concerned, I've found RegExr to be good.

This is also amazing.  :-)

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #41 on: December 20, 2017, 01:46:56 PM »
This is also amazing.  :-)

At a first glance this book looks really enjoyable to read!
Thank you, Lee! :)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #42 on: December 20, 2017, 02:07:19 PM »
This is also amazing.  :-)

At a first glance this book looks really enjoyable to read!
Thank you, Lee! :)

You're most welcome - the 'book' is more a PDF of a slideshow, and is therefore best viewed in an appropriate PDF viewer by scrolling through with the pages fitting the full screen, so that you can see the 'animations'.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Get rid of comments (Using NP++ or VLIDE)
« Reply #43 on: December 20, 2017, 02:24:49 PM »
You're most welcome - the 'book' is more a PDF of a slideshow, and is therefore best viewed in an appropriate PDF viewer by scrolling through with the pages fitting the full screen, so that you can see the 'animations'.

Yes I initially viewed it in the way you describe it - seems that its made for lecturing purposes.

For me its just amazing how good you are at so many aspects, so almost every time I browse some of your codes brings up the question: how?
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg