Hello, I'm using a tool (PLY) which apparently expects the tokens to
be created using r''
But because one token is a rather complex regular expression, I want
to create the regular expression programmaticall y.
How can I generate a string and then create something of the same type
that the r'' function does?
Concretely, in the program below, consonant is not the same type as
t_NAME, but I assume that it needs to be for PLY to use it for
tokenizing:
import re
t_NAME = r'[a-zA-Z_][a-zA-Z0-9_]*'
guttural = 'kh?|gh?|\"n'
palatal = '(?:chh?|jh?|\~ n)'
cerebral = '\.(?:th?|dh?|n )'
dental = '(?:th?|dh?|n)'
semivowel = '[yrlv]'
sibilant = '[\"\.]?s'
aspirant = 'h'
consonant = re.compile('|'. join([guttural , palatal , cerebral ,
dental , semivowel , sibilant , aspirant]))
print consonant
print t_NAME 3 1266
Oh my god, how embarrassing. the r'' notation is to create raw string
<http://www.swc.scipy.o rg/lec/glossary.html#g def-raw_string>
I thought it was some form of blessing a string into a regular
expression class.
Terrence Brannon wrote:
Hello, I'm using a tool (PLY) which apparently expects the tokens to
be created using r''
But because one token is a rather complex regular expression, I want
to create the regular expression programmaticall y.
How can I generate a string and then create something of the same type
that the r'' function does?
r'' is an alternative syntax for string literals that affects how escape
sequences are interpreted; there's no separate string type for strings
created by this syntax.
</F>
On Thu, Aug 28, 2008 at 12:23 PM, Terrence Brannon <me******@gmail .comwrote:
Hello, I'm using a tool (PLY) which apparently expects the tokens to
be created using r''
But because one token is a rather complex regular expression, I want
to create the regular expression programmaticall y.
How can I generate a string and then create something of the same type
that the r'' function does?
The "r" prefix isn't a function or a type, it's merely a special
literal syntax for strings that's handy when you're writing regexes
and therefore have to deal with another level of backslash escaping.
See the second to last paragraph of http://docs.python.org/ref/strings.html for more info.
Regards,
Chris
>
Concretely, in the program below, consonant is not the same type as
t_NAME, but I assume that it needs to be for PLY to use it for
tokenizing:
import re
t_NAME = r'[a-zA-Z_][a-zA-Z0-9_]*'
guttural = 'kh?|gh?|\"n'
palatal = '(?:chh?|jh?|\~ n)'
cerebral = '\.(?:th?|dh?|n )'
dental = '(?:th?|dh?|n)'
semivowel = '[yrlv]'
sibilant = '[\"\.]?s'
aspirant = 'h'
consonant = re.compile('|'. join([guttural , palatal , cerebral ,
dental , semivowel , sibilant , aspirant]))
print consonant
print t_NAME
-- http://mail.python.org/mailman/listinfo/python-list This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Markus Dehmann |
last post by:
I have a big class that contains code like this (the code is automatically
generated according to some configuration):
if(str == "name1"){
do;
something;
name1_specific;
}else if(str == "name2"){
do;
something;
|
by: Dieter Vanderelst |
last post by:
Dear all,
I'm currently comparing Python versus Perl to use in a project that
involved a lot of text processing. I'm trying to determine what the most
efficient language would be for our purposes. I have to admit that,
although I'm very familiar with Python, I'm complete Perl noob (and I
hope to stay one) which is reflected in my questions.
I know that the web offers a lot of resources on Python/Perl
differences. But I couldn't find a...
|
by: Joshua D. Drake |
last post by:
Hello,
I think the below just about says it all:
http://www.commandprompt.com/images/mammoth_versus_dolphin_500.jpg
Sincerely,
Joshua Drake
|
by: Andrew Robinson |
last post by:
I need to create a shared static field for use within a number of different
classes. Which one should I be using or are they all really the same thing?
public class Widget
{
private Widget() {}
public static string DataField = string.Empty;
}
versus
|
by: bob |
last post by:
Hello,
I use Microsoft Visual C++ .NET (version 7.1.3088)
Sometimes (with big codes?) when I get a compile error and click on the error, the cursor is placed next to the wrong piece of code. The line number in the error message and that of the cursor do match but the real error is somewhere else.
The same I get when debugging my code, the piece of code the cursor is at is no way the code that is actually debugged.
This is very frustating!...
| |
by: wong_powah |
last post by:
#include <vector>
#include <iostream>
using std::cout;
using std::vector;
enum {DATASIZE = 20};
typedef unsigned char data_t;
|
by: aj |
last post by:
DB2 8.2 LUW FP14
Is there any real difference between
select blahblahblah... where blah IN (select blah......)
versus
select blahblahblah... where blah = ANY (select blah.....)
versus
select blahblahblah... where exists (select blah.....)
Is one more ANSI than another? Which is most portable?
|
by: stupid48 |
last post by:
Ok,
I'm just a server guy with a bit a VS 2005 experience. I know that
you can deploy asp.net apps either compiled or not compiled. My
developer says that he prefers not to compile. I have to ask about
the pro's and con's of both. I'm especially concerned about
performance of each and the security pros and cons of each. Does
anyone have a theory on this and\or a link to a site that I can read?
Thanks very much and sorry if this...
|
by: KW |
last post by:
I have an application that runs in any of Access 2000 thru Access 2007
to accommodate my customers' various environments. I implemented code
to call a function that uses the LoadCustomUI method to load in my
custom ribbon for Access 2007. This function is called only when the
check for running Access version 12 or higher is true.
Everything works like I want in Access 2007. The problem is when I
compile it on Access 2000,2002,2003,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |