***This is of especial interest for those who are using the pyparsing
module, and have defined grammars that make use of CaselessLiteral .***
One of the bugfix requests I recently got for pyparsing was to fix the
tokens returned by CaselessLiteral . CaselessLiteral is an interesting
special case of Literal, since it matches a large number of possible input
tokens. That is:
CaselessLiteral ("abcd")
could match abcd, abcD, abCD, abCd, etc. When parsing something like SQL, a
CaselessLiteral ('select') has even more options.
Ordinarily, the other parsing classes in pyparsing return the original
matched text from the input stream, but CaselessLiteral could make this
unwieldy - if you had something more complex like this possible grammar for
a Zork-type game:
verb = ( CaselessLiteral ("pick") | CaselessLiteral ("turn") |
CaselessLiteral ("drop") | <...and so on...> )
then the code to process the tokens would have to neutralize the case of the
input text, since it could be 'picK', 'Turn', 'DROP'. So I expect that the
first thing the calling code would do with the results would be to convert
to upcase or lowercase. Since this was so predictable, I decided to build
that into the interface, that in the case of CaselessLiteral , the input text
would *not* be returned as the matching text, but the original specifying
text string would be returned instead - after all, the caller had already
decided that case was not significant. This is how the documentation reads,
that CaselessLiteral will return as its match text the original specifying
text string.
Unfortunately, I botched it, waaaaay back pre-1.0.0, when I first put
pyparsing up on SourceForge. CaselessLiteral always returns the input text
converted to uppercase. It is still a predictably-cased string, but not as
documented. In fact, if someone were to specify CaselessLiteral ("pick") and
get returned "PICK", this could make for other problems.
So for those of you who are still reading, and who use pyparsing, and have
CaselessLiteral s in your code, and test on the returned text, what choice
would you prefer:
1. Keep the current behavior, and just change the docs.
2. Fix the current behavior to match the docs, and fix up any code that uses
it.
My personal preference is #2. We are still early in pyparsing's code life -
it has only been generally available for about 4 months - and I think it
really is the preferred way to go.
On the other hand, pyparsing has been downloaded almost 900 times from SF,
and so I want to find out if this will end up making me lots of enemies. :)
Overall, this has been a gratifying experience - I have gotten many e-mails
from people who feel this tool is easy to pick up, and fills a common need.
I want to continue in those 900 peoples' good graces, or at least as many of
them as I can.
-- Paul 1 1432
"Paul McGuire" <pt***@austin.r r._bogus_.com> wrote in message news:<ge******* ************@fe 2.texas.rr.com> ... So for those of you who are still reading, and who use pyparsing, and have CaselessLiteral s in your code, and test on the returned text, what choice would you prefer:
1. Keep the current behavior, and just change the docs. 2. Fix the current behavior to match the docs, and fix up any code that uses it.
My personal preference is #2. We are still early in pyparsing's code life - it has only been generally available for about 4 months - and I think it really is the preferred way to go.
I'm +1 on #2, i.e., change the code to match the docs.
I have a use case where the parser is acting as a "cleanup"
to the input, making it conform to a coding standard,
and CaselessLiteral working as described in the docs
would be perfect. I suppose I could make a setParseAction
that would convert it to the appropriate case, but that
would slow it down, plus I'd have to keep track of the
literal in two places (well, I suppose I could define
a name for the value and import it from my grammar and
from the code that has the parse actions, but still...).
Thanks for pyparsing.
--dang This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Lad |
last post by:
I came across pyparsing module by Paul McGuire. It seems to be nice but
I am not sure if it is the best for my need.
I need to extract some text from html page. The text is in tables and a
table can be inside another table.
Is it better and easier to use the pyparsing module or HTMLparser?
Thanks for suggestions.
La.
|
by: Bryan Olson |
last post by:
The Python slice type has one method 'indices', and reportedly:
This method takes a single integer argument /length/ and
computes information about the extended slice that the slice
object would describe if applied to a sequence of length
items. It returns a tuple of three integers; respectively
these are the /start/ and /stop/ indices and the /step/ or
stride length of the slice. Missing or out-of-bounds indices
are handled in a manner...
|
by: Richard Cornford |
last post by:
Anyone who has taken a look at the online FAQ today may have noticed
that I have updated it. The majority of the changes are the updating of
broken links and the implementation of that extensive suggestions for
re-wording provided by Michael Winter. Other changes are listed below.
Fore those interested, a zipped snapshot of the entire FAQ and notes, as
it now is, is available at:-
<URL:...
|
by: Oliver Elphick |
last post by:
The attached proposal is written primarily for Debian. Its
motivation is that the current package upgrade process is pretty flaky
and also that the current packaging does not really provide for multiple
simultaneous postmasters, which are wanted by people hosting several
database clusters.
I assume these proposals may also be of interest to Red Hat packagers.
I am copying it to the PostgreSQL list in case there are any
obvious...
|
by: astarocean |
last post by:
using pyparsing to deal with nested tables , wanna keep table's
structure and propertys .
but program was chunked with the </td> tag of inner table.
have any ideas?
here's the program
from pyparsing import *
| |
by: rh0dium |
last post by:
Hi all,
I have a file which I need to parse and I need to be able to break it
down by sections. I know it's possible but I can't seem to figure this
out.
The sections are broken by <> with one or more keywords in the <>.
What I want to do is to be able to pars a particular section of the
file. So for example I need to be able to look at the SYSLIB section.
Presumably the sections are
|
by: James J. Besemer |
last post by:
I would like to champion a proposed enhancement to Python. I describe the
basic idea below, in order to gage community interest. Right now, it's only
an idea, and I'm sure there's room for improvement. And of course it's
possible there's some serious "gotcha" I've overlooked. Thus I welcome any
and all comments.
If there's some agreement that this proposal is worth further consideration
then I'll re-submit a formal document in...
|
by: 7stud |
last post by:
To the developer:
1) I went to the pyparsing wiki to download the pyparsing module and
try it
2) At the wiki, there was no index entry in the table of contents for
Downloads. After searching around a bit, I finally discovered a tiny
link buried in some text at the top of the home page.
3) Link goes to sourceforge. At sourceforge, there was a nice, green
'download' button that stood out from the page.
4) I clicked on the download...
|
by: Paul McGuire |
last post by:
I've just uploaded to SourceForge and PyPI the latest update to
pyparsing, version 1.5.1. It has been a couple of months since
1.5.0 was released, and a number of bug-fixes and enhancements
have accumulated in SVN, so time for a release!
Here's what's new in Pyparsing 1.5.1:
- Added __dir__() methods to ParseBaseException and ParseResults,
to support new dir() behavior in Py2.6 and Py3.0. If dir() is
called on a ParseResults object,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: 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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |