DSLs in perl and python (Was sobering observation)

Rustom Mody rustompmody at gmail.com
Fri Mar 18 22:07:35 EDT 2016


On Friday, March 18, 2016 at 6:52:53 PM UTC+5:30, Peter Otten wrote:
> Rustom Mody wrote:
> 
> > On Friday, March 18, 2016 at 4:17:06 AM UTC+5:30, MRAB wrote:
> >> Stick an "x" on the end of the regex: /something/x or s/old/new/x.
> > 
> > Thanks!
> > 
> > Is there somewhere a regexp 'introspection' API/capability available?
> > 
> > ie if the re looks like
> > rexp = r"""
> > # DSL (instantiation) for describing NYSE symbology
> > ^
> > (?P<scrip>	     [A-Z]*)     # The base scrip
> > (?P<serchar>	     [.+-])?     # Series type char
> > (?P<series>	     [A-Z])?     # Series
> > (?P<issuedc>	     [#])?       # issued char indicator
> > $		     		 # Thats all (there should be!)
> > """
> > 
> > I would like to know that the named-groups are
> > {scrip, serchar, series, issued}
> > without doing match/search etc
> 
> Is that a Perl or a Python question? If the latter:
> 
> >>> r = re.compile(rexp, re.VERBOSE)
> >>> r.groupindex
> {'serchar': 2, 'issuedc': 4, 'scrip': 1, 'series': 3}

Neat Thanks (and Jussi)



More information about the Python-list mailing list