DSL design (was DSLs in perl and python)
Rustom Mody
rustompmody at gmail.com
Tue Mar 29 09:28:30 EDT 2016
On Saturday, March 19, 2016 at 7:37:52 AM UTC+5:30, Rustom Mody wrote:
> 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)
Thanks once again to Peter and Jussi.
With that groupindex pointer, this tiny dsl for re's is here
https://github.com/rusimody/redsl
[How BTW did you folks go about unearth that groupindex?? Dont see it in docs]
Comments welcome.
If people have comments on the python thats fine -- specifically if something
does not work, is unclear etc.
I am however more specifically interested in the DSL-design --
Can one clean/spruce that up?
More information about the Python-list
mailing list