LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-18-2022, 04:58 AM   #1
Faki
Member
 
Registered: Oct 2021
Posts: 574

Rep: Reputation: Disabled
regex expressions for matching elisp syntactic structures


Regarding elisp, are there any regex expressions users would find useful to for matching syntactic structures?
 
Old 04-18-2022, 05:18 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
without examples, samples hard to say anything. What are you exactly looking for (I mean what kind of regex do you need)? What do you want to achieve?
 
Old 04-18-2022, 05:59 AM   #3
Faki
Member
 
Registered: Oct 2021
Posts: 574

Original Poster
Rep: Reputation: Disabled
For instance, I would like a regex expression that matches the following elisp syntactic structures - functions with (defun, (lambda, and (defmacro.
 
Old 04-18-2022, 08:15 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
I posted you already: www.regex101.com
You can easily test and check your patterns against your sample text. Do not need to wait for anybody.
What did you try so far? Where did you stuck? Which language do you want to use for it? What is your goal at all? (What should be the outcome?)
 
1 members found this post helpful.
Old 04-18-2022, 09:21 AM   #5
Faki
Member
 
Registered: Oct 2021
Posts: 574

Original Poster
Rep: Reputation: Disabled
Am trying to determine the Cyclomatic Complexity on a file or a region of elisp code. By counting the maximum number of nested s-exp.
 
Old 04-18-2022, 01:53 PM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
You can't use regex for that, no.

I'd write a program for this. Initialize a variable at zero. Parse the file one character at a time. Each time you see an opening paren, increment the variable. Each time you see a closing paren, decrement it. Keep track of the largest value of the variable, and at the end you'll have the value you want. This will work for valid code.

Last edited by dugan; 04-19-2022 at 09:26 AM.
 
Old 04-19-2022, 12:20 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by dugan View Post
You can't use regex for that, no.

I'd write a program for this. Initialize a variable at zero. Parse the file one character at a time. Each time you see an opening parent, increment the variable. Each time you see a closing paren, decrement it. Keep track of the largest value of the variable, and at the end you'll have the value you want. This will work for valid code.
Yes, you should check if the code is syntactically correct and valid, otherwise it is pointless. But I think it is already implemented somewhere, so do not need to do/reinvent it again, just look for an acceptable solution on the net (actually I do not need it so I did not check it).
 
Old 04-19-2022, 09:24 AM   #8
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
I know of this for Python:

https://pypi.org/project/mccabe/
 
Old 04-19-2022, 06:26 PM   #9
Faki
Member
 
Registered: Oct 2021
Posts: 574

Original Poster
Rep: Reputation: Disabled
Could something similar to mccabe work on elisp code?
 
  


Reply

Tags
regex



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
[SOLVED] Learning RegEx? Regular Expressions davejjj Programming 5 11-08-2011 03:20 PM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
LXer: RegEx Buddy--A Simple Way to Create Regular Expressions LXer Syndicated Linux News 0 02-15-2009 02:01 AM
regular expressions in perl-get amount of matching digits baddah Programming 3 06-27-2007 09:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration