pyparsing-users Mailing List for Python parsing module (Page 31)
Brought to you by:
ptmcg
You can subscribe to this list here.
| 2004 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
(2) |
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2005 |
Jan
(2) |
Feb
|
Mar
(2) |
Apr
(12) |
May
(2) |
Jun
|
Jul
|
Aug
(12) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2006 |
Jan
(5) |
Feb
(1) |
Mar
(10) |
Apr
(3) |
May
(7) |
Jun
(2) |
Jul
(2) |
Aug
(7) |
Sep
(8) |
Oct
(17) |
Nov
|
Dec
(3) |
| 2007 |
Jan
(4) |
Feb
|
Mar
(10) |
Apr
|
May
(6) |
Jun
(11) |
Jul
(1) |
Aug
|
Sep
(19) |
Oct
(8) |
Nov
(32) |
Dec
(8) |
| 2008 |
Jan
(12) |
Feb
(6) |
Mar
(42) |
Apr
(47) |
May
(17) |
Jun
(15) |
Jul
(7) |
Aug
(2) |
Sep
(13) |
Oct
(6) |
Nov
(11) |
Dec
(3) |
| 2009 |
Jan
(2) |
Feb
(3) |
Mar
|
Apr
|
May
(11) |
Jun
(13) |
Jul
(19) |
Aug
(17) |
Sep
(8) |
Oct
(3) |
Nov
(7) |
Dec
(1) |
| 2010 |
Jan
(2) |
Feb
|
Mar
(19) |
Apr
(6) |
May
|
Jun
(2) |
Jul
|
Aug
(1) |
Sep
|
Oct
(4) |
Nov
(3) |
Dec
(2) |
| 2011 |
Jan
(4) |
Feb
|
Mar
(5) |
Apr
(1) |
May
(3) |
Jun
(8) |
Jul
(6) |
Aug
(8) |
Sep
(35) |
Oct
(1) |
Nov
(1) |
Dec
(2) |
| 2012 |
Jan
(2) |
Feb
|
Mar
(3) |
Apr
(4) |
May
|
Jun
(1) |
Jul
|
Aug
(6) |
Sep
(18) |
Oct
|
Nov
(1) |
Dec
|
| 2013 |
Jan
(7) |
Feb
(7) |
Mar
(1) |
Apr
(4) |
May
|
Jun
|
Jul
(1) |
Aug
(5) |
Sep
(3) |
Oct
(11) |
Nov
(3) |
Dec
|
| 2014 |
Jan
(3) |
Feb
(1) |
Mar
|
Apr
(6) |
May
(10) |
Jun
(4) |
Jul
|
Aug
(5) |
Sep
(2) |
Oct
(4) |
Nov
(1) |
Dec
|
| 2015 |
Jan
|
Feb
|
Mar
|
Apr
(13) |
May
(1) |
Jun
|
Jul
(2) |
Aug
|
Sep
(9) |
Oct
(2) |
Nov
(11) |
Dec
(2) |
| 2016 |
Jan
|
Feb
(3) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(4) |
| 2017 |
Jan
(2) |
Feb
(2) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(4) |
Aug
|
Sep
|
Oct
(4) |
Nov
(3) |
Dec
|
| 2018 |
Jan
(10) |
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
| 2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2024 |
Jan
|
Feb
(1) |
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
(1) |
Aug
(3) |
Sep
(1) |
Oct
(1) |
Nov
|
Dec
|
| 2025 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
|
From: Michele P. <mic...@un...> - 2005-04-28 14:39:14
|
pt...@au... wrote:
> Michele -
>
> First of all, are you sure this is a valid entry? The one example
> file I have would list this as:
>
> controls {
> inet 127.0.0.1 allow { any; }; keys { "key";};
> };
>
> instead of your version:
>
> controls {
> inet 127.0.0.1 allow { any; } keys { "key";};
> };
>
I broke my mind for search an error on my parsing strings and the
problem was a ";" !!!
>
> Pyparsing includes some debugging capabilities so you can peek into
> the parsing logic process. Try changing the two lines:
>
> simple = Group(value + ZeroOrMore(value) + ";")
> statement = Group(value + ZeroOrMore(value) + "{" +
> Optional(toplevel) + "}" + ";")
>
> to
> simple = Group(value + ZeroOrMore(value) + ";").setDebug()
> statement = Group(value + ZeroOrMore(value) + "{" +
> Optional(toplevel) + "}" + ";").setDebug()
>
> You will now start to see messages during parsing when each of these
> expressions is tried, and either succeeds or throws an exception.
>
> After you get this running, let us know what you find.
>
> -- Paul
I saw this method and I find that is very useful. I'll use it.
Thanks,
Michele
|
|
From: <pt...@au...> - 2005-04-28 13:40:41
|
Michele -
First of all, are you sure this is a valid entry? The one example
file I have would list this as:
controls {
inet 127.0.0.1 allow { any; }; keys { "key";};
};
instead of your version:
controls {
inet 127.0.0.1 allow { any; } keys { "key";};
};
Pyparsing includes some debugging capabilities so you can peek into
the parsing logic process. Try changing the two lines:
simple = Group(value + ZeroOrMore(value) + ";")
statement = Group(value + ZeroOrMore(value) + "{" +
Optional(toplevel) + "}" + ";")
to
simple = Group(value + ZeroOrMore(value) + ";").setDebug()
statement = Group(value + ZeroOrMore(value) + "{" +
Optional(toplevel) + "}" + ";").setDebug()
You will now start to see messages during parsing when each of these
expressions is tried, and either succeeds or throws an exception.
After you get this running, let us know what you find.
-- Paul
----- Original Message -----
From: Michele Petrazzo <mic...@un...>
Date: Thursday, April 28, 2005 7:32 am
Subject: [Pyparsing] Parsing DNS bind file
> I want to modify bind parsing example because it don't parse this
> data:
> controls {
> inet 127.0.0.1 allow { any; } keys { "key";};
> };
>
> If I remove these three lines, the example work well.
>
> I add the these two lines to try to parse the new data:
>
> simple_val = Group(value + '{' + OneOrMore(value + ';') + '}')
> only4ctrls = Group('controls' + value + value +
> OneOrMore(simple_val) +
> "}" + ";")
> and modified this:
>
> toplevel << OneOrMore(simple | statement | only4ctrls)
>
> but pyparsing stop when it found my new data. Can someone help me?
>
> Thanks,
> Michele
>
> A complete data can be this:
>
> key "key" {
> algorithm hmac-md5;
> secret "abcde1abcde2abcde3abcde4";
> };
>
> controls {
> inet 127.0.0.1 allow { any; } keys { "key";};
> };
>
> options {
> pid-file "/var/run/named/named.pid";
> directory "/var/named";
> forwarders {
> 62.94.0.1;
> 62.94.0.2;
> };
> notify no;
> };
>
> zone "." {
> type hint;
> file "named.ca";
> };
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Tell us your software development
plans!
> Take this survey and enter to win a one-year sub to SourceForge.net
> Plus IDC's 2005 look-ahead and a copy of this survey
> Click here to start! http://www.idcswdc.com/cgi-bin/survey?id=105hix
> _______________________________________________
> Pyparsing-users mailing list
> Pyp...@li...
> https://lists.sourceforge.net/lists/listinfo/pyparsing-users
>
|
|
From: Michele P. <mic...@un...> - 2005-04-28 12:29:57
|
I want to modify bind parsing example because it don't parse this data:
controls {
inet 127.0.0.1 allow { any; } keys { "key";};
};
If I remove these three lines, the example work well.
I add the these two lines to try to parse the new data:
simple_val = Group(value + '{' + OneOrMore(value + ';') + '}')
only4ctrls = Group('controls' + value + value + OneOrMore(simple_val) +
"}" + ";")
and modified this:
toplevel << OneOrMore(simple | statement | only4ctrls)
but pyparsing stop when it found my new data. Can someone help me?
Thanks,
Michele
A complete data can be this:
key "key" {
algorithm hmac-md5;
secret "abcde1abcde2abcde3abcde4";
};
controls {
inet 127.0.0.1 allow { any; } keys { "key";};
};
options {
pid-file "/var/run/named/named.pid";
directory "/var/named";
forwarders {
62.94.0.1;
62.94.0.2;
};
notify no;
};
zone "." {
type hint;
file "named.ca";
};
|
|
From: Michele P. <mic...@un...> - 2005-04-21 17:29:38
|
pt...@au... wrote: > Michele - > > There are 2 things happening here. One, I think you left out the > opening tags in your grammar variable 'v'; No. I have intentionally omitted the opening tag because the data that I write here not are the real data. > and two, the default form > of SkipTo() scans everything up to BUT NOT INCLUDING the target > expression. You can modify SkipTo to also consume the expression > that it is "SkipTo-ing", but I think the clearer solution is to > include the open/close tags in your grammar. Yes, I don't want to modify the SkipTo class because I want to have a script that is able to work with standard module. > > Try this: > > v = LIST + SkipTo(LIST_END) + LIST_END + \ DESCR + SkipTo(DESCR_END) > + DESCR_END > You might also want to change LIST and DESCR to use the suppress()'ed > versions, as you did for LIST_END and DESCR_END, so that they do not > appear in your output either. Then the SkipTo's should give you only > that text that is between the opening and closing tags. This not work like I want because the output is: ['fw = 1\n net = 1', ':DESCR', 'fw = Firewall\n net = Ethernet config'] but I want only: [':DESCR\n fw = Firewall\n net = Ethernet config'] All this problems because my data file is a file that can have a lot of "section" like :DESCR and its ::DESCR, but I don't know their names. In this example, I know the name of my sections "fw" and "net", only when I parse :LIST section. After, with a loop, I parse these sections, and after with the same logic with :OPT_xxx, where xxx is the name of the sections that I read into "file_names". Example: :LIST fw = 1 net = 1 ::LIST :DESCR fw = Firewall net = Ethernet config ::DESCR :fw :SITE_OPT dir = /etc/shorewall file_names = interfaces, masq, policy, rules, zones ::SITE_OPT :OPT_masq file_path = /etc/shorewall/interfaces ::OPT_interfaces :OPT_rules test = 1 ::OPT_rules :net :SITE_OPT test = 1 ::SITE_OPT ::net > > Thanks for trying pyparsing! Let me know if you have any other > questions. Thanks to you for pyparsing! It's a simple but very powerful parser tool. > > -- Paul > Michele |
|
From: Michele P. <mic...@un...> - 2005-04-21 14:27:27
|
I have a problem with the function SkipTo. With this sample code, I want
to have only a part of my data, but the function SkipTo return me all
the data. What's wrong?
Thanks,
Michele Petrazzo
Italy
This is what I need
[':DESCR\n fw = Firewall\n net = Ethernet config']
This is what pyparsing return me:
[':LIST\n fw = 1\n net = 1', '::LIST\n\n:DESCR\n fw = Firewall\n net =
Ethernet config']
data = """
:LIST
fw = 1
net = 1
::LIST
:DESCR
fw = Firewall
net = Ethernet config
::DESCR
"""
LIST = Literal(':LIST')
LIST_END = Literal('::LIST').suppress()
DESCR = Literal(':DESCR')
DESCR_END = Literal('::DESCR').suppress()
v = SkipTo(LIST_END) + SkipTo(DESCR_END)
print v.parseString(data)
|
|
From: Robert P. <rob...@gm...> - 2005-04-10 21:43:13
|
pt...@au... wrote: [snip] > should I add corresponding > instance built-ins for LineStart, LineEnd, StringStart and StringEnd? It certainly would have helped me - and they would be similar to htmlComment or restOfLine. If you think that having a variable and a class could be confusing, just extend the descriptions in the html help. -- Robert |
|
From: <pt...@au...> - 2005-04-10 20:41:07
|
----- Original Message ----- From: Robert Pollak <rob...@gm...> Date: Sunday, April 10, 2005 2:57 pm Subject: Re: How to use StringEnd? > Being a Python newbie, I wrote: > > I tried to use > > grammar = Dict( OneOrMore( Group( assignment ) ) ) + StringEnd > > I just found out that this should be StringEnd() instead. My first > stepsin a weakly typed language :) > Now the grammar matches only when all of the input is consumed. > > -- > Robert Pollak > GPG Key ID: E66BE5B1 > Robert - Well, you solved your own problem before I could check my e-mail! So, one of the things that might help (or confuse) is that I had a built-in "empty" variable before I added the Empty class, so pyparsing now includes both an "Empty" class and an "empty" instance variable. Is this more confusing, or should I add corresponding instance built-ins for LineStart, LineEnd, StringStart and StringEnd? -- Paul |
|
From: Robert P. <rob...@gm...> - 2005-04-10 19:57:50
|
Being a Python newbie, I wrote: > I tried to use > grammar = Dict( OneOrMore( Group( assignment ) ) ) + StringEnd I just found out that this should be StringEnd() instead. My first steps in a weakly typed language :) Now the grammar matches only when all of the input is consumed. -- Robert Pollak GPG Key ID: E66BE5B1 |
|
From: Robert P. <rob...@gm...> - 2005-04-10 10:15:37
|
The page <http://dir.gmane.org/gmane.comp.python.pyparsing.user> now offers different types of access to the new Gmane archive of the pyparsing-users mailing list, e.g. threaded, as blog, newsgroup or RSS feed. (The list admin could import the current Sourceforge archive to Gmane, if necessary. See <http://gmane.org/import.php>.) -- Robert Pollak GPG Key ID: E66BE5B1 |
|
From: Robert P. <rob...@gm...> - 2005-04-10 09:13:22
|
pt...@au... wrote [Re: empty lines and restOfLine comments]:
> Ok, here's an example using pyparsing's Dict. -- Paul
[snip]
> comment = Literal('/') + restOfLine
>
> lhs = Word( alphas, alphanums + "_" )
> rhs = Word( alphas, alphanums + "_." )
> EQUALS = Literal("=").suppress()
>
> assignment = LineStart() + lhs + EQUALS + rhs
>
> # use pyparsing Dict to create dict-like access to parsed results
> grammar = Dict( OneOrMore( Group( assignment ) ) )
> grammar.ignore(comment)
>
> results = grammar.parseString( testdata )
[snip]
Thank you!
When I now append a nonsense line "xxx" to testdata, this is of course
not consumed by the grammar. Since I need this case to be a parsing
error, I tried to use
grammar = Dict( OneOrMore( Group( assignment ) ) ) + StringEnd
, but this gives me (in grammar.ignore(comment)):
TypeError: unbound method ignore() must be called with StringEnd
instance as first argument (got Suppress instance instead)
.
I have not found anything useful in the pyparsing examples, neither.
So how can I ensure that the whole string is matched?
--
Robert Pollak
GPG Key ID: E66BE5B1
|
|
From: <pt...@au...> - 2005-04-01 04:03:27
|
Ok, here's an example using pyparsing's Dict. -- Paul
testdata = """
/ Flux DSS-DESIGNER, Sample Data
/ Projekt: Set 1
// HYDRAULIK & QUERPROFIL-DATEN
floin_file = set_1.floin
floab_file = set_1.floab
floout_file = floout
flores_file = flores
// REGELUNG
ctrlin_file = set_1.ctrlin
ctrlres_file = ctrl_res
"""
from pyparsing import *
comment = Literal('/') + restOfLine
lhs = Word( alphas, alphanums + "_" )
rhs = Word( alphas, alphanums + "_." )
EQUALS = Literal("=").suppress()
assignment = LineStart() + lhs + EQUALS + rhs
# use pyparsing Dict to create dict-like access to parsed results
grammar = Dict( OneOrMore( Group( assignment ) ) )
grammar.ignore(comment)
results = grammar.parseString( testdata )
# some different example syntaxes for accessing results fields
print "\nShow some different example syntaxes for accessing results like attributes, or dictionary entries"
print "results.flores_file", results.flores_file
print 'results["ctrlres_file"]', results["ctrlres_file"]
for k in results.keys():
print k,"->", results[k]
# can still access results like a list
print "\nJust list out tokens like reading a list"
for entry in results:
print entry[0], ":", entry[1]
# or convert the results to an actual Python list
print "\nOr convert the results to a real Python list"
print results.asList()
----- Original Message -----
From: Robert Pollak <rob...@gm...>
Date: Thursday, March 31, 2005 5:48 pm
Subject: [Pyparsing] Re: empty lines and restOfLine comments
> Here is an update:
> I now use the following, which works fine as long as there are no "="
> characters in the comment lines:
>
> chars = alphanums + "_" + "." + "\\"
> assignment = Word(chars) + Literal("=").suppress() + Word(chars)
>
> cfgFile = file("cfg-snippet")
>
> cfgData = "".join(cfgFile.readlines())
>
> cfgFile.close()
>
> assignments = dict([t for t,s,e in assignment.scanString(cfgData)])
>
> print assignments['floin_file']
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by Demarc:
> A global provider of Threat Management Solutions.
> Download our HomeAdmin security software for free today!
> http://www.demarc.com/Info/Sentarus/hamr30
> _______________________________________________
> Pyparsing-users mailing list
> Pyp...@li...
> https://lists.sourceforge.net/lists/listinfo/pyparsing-users
>
|
|
From: <pt...@au...> - 2005-04-01 03:50:30
|
To use restOfLine, you need to join using "\n", not "". The \n characters tell restOfLine when to stop.
I'll try to pull together a Dict example with your input data.
-- Paul
----- Original Message -----
From: Robert Pollak <rob...@gm...>
Date: Thursday, March 31, 2005 5:22 pm
Subject: [Pyparsing] empty lines and restOfLine comments
> Hello!
> I am a(nother) Python and pyparsing newbie.
> I want to use pyparsing-1.3 to parse files that look like the
> following snippet, enclosed in triple quotes:
> """
> / Flux DSS-DESIGNER, Sample Data
>
> / Projekt: Set 1
>
>
>
> // HYDRAULIK & QUERPROFIL-DATEN
>
> floin_file = set_1.floin
>
> floab_file = set_1.floab
>
>
> floout_file = floout
>
> flores_file = flores
>
>
> // REGELUNG
>
> ctrlin_file = set_1.ctrlin
>
> ctrlres_file = ctrl_res
>
> """
>
> Lines starting with a slash (comments) should be ignored.
> I have been reading (either on this list or in the sf help forum - I
> cannot find it right now) that empty lines can only be read using
> grammar.parseString("".join(inputFile.readlines())), like in the
> configParse.py example.
> But when everything is joined like this, how can the end of the
> comment lines be determined?
>
> I am currently stuck at:
> chars = alphanums + "_" + "." + "\\"
> assignment = Word(chars) + "=" + Word(chars)
> line = (assignment | restOfLine) + LineEnd
> grammar = ZeroOrMore(line)
>
> This does not even run through - I get
> Traceback (most recent call last):
> File "parseCfg.py", line 6, in ?
> line = (assignment | restOfLine) + LineEnd
> File "/usr/lib/python2.3/site-packages/pyparsing.py", line 635,
> in __add__
> return And( [ self, other ] )
> File "/usr/lib/python2.3/site-packages/pyparsing.py", line 1306,
> in __init__
> if not e.mayReturnEmpty:
> AttributeError: type object 'LineEnd' has no attribute
> 'mayReturnEmpty'
> When I just use "line = assignment | restOfLine" instead, the parser
> runs into an infinite loop on the snippet above, with or without the
> "join readlines" trick.
>
> Thank you for any help,
>
> Robert
>
> Btw, how can I use a pyparsing.Dict here to get direct access e.g. to
> myParseResult['floin_file']?
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by Demarc:
> A global provider of Threat Management Solutions.
> Download our HomeAdmin security software for free today!
> http://www.demarc.com/Info/Sentarus/hamr30
> _______________________________________________
> Pyparsing-users mailing list
> Pyp...@li...
> https://lists.sourceforge.net/lists/listinfo/pyparsing-users
>
|
|
From: Robert P. <rob...@gm...> - 2005-03-31 23:49:06
|
Here is an update:
I now use the following, which works fine as long as there are no "="
characters in the comment lines:
chars = alphanums + "_" + "." + "\\"
assignment = Word(chars) + Literal("=").suppress() + Word(chars)
cfgFile = file("cfg-snippet")
cfgData = "".join(cfgFile.readlines())
cfgFile.close()
assignments = dict([t for t,s,e in assignment.scanString(cfgData)])
print assignments['floin_file']
|
|
From: Robert P. <rob...@gm...> - 2005-03-31 23:22:45
|
Hello!
I am a(nother) Python and pyparsing newbie.
I want to use pyparsing-1.3 to parse files that look like the
following snippet, enclosed in triple quotes:
"""
/ Flux DSS-DESIGNER, Sample Data
/ Projekt: Set 1
// HYDRAULIK & QUERPROFIL-DATEN
floin_file = set_1.floin
floab_file = set_1.floab
floout_file = floout
flores_file = flores
// REGELUNG
ctrlin_file = set_1.ctrlin
ctrlres_file = ctrl_res
"""
Lines starting with a slash (comments) should be ignored.
I have been reading (either on this list or in the sf help forum - I
cannot find it right now) that empty lines can only be read using
grammar.parseString("".join(inputFile.readlines())), like in the
configParse.py example.
But when everything is joined like this, how can the end of the
comment lines be determined?
I am currently stuck at:
chars = alphanums + "_" + "." + "\\"
assignment = Word(chars) + "=" + Word(chars)
line = (assignment | restOfLine) + LineEnd
grammar = ZeroOrMore(line)
This does not even run through - I get
Traceback (most recent call last):
File "parseCfg.py", line 6, in ?
line = (assignment | restOfLine) + LineEnd
File "/usr/lib/python2.3/site-packages/pyparsing.py", line 635, in __add__
return And( [ self, other ] )
File "/usr/lib/python2.3/site-packages/pyparsing.py", line 1306, in __init__
if not e.mayReturnEmpty:
AttributeError: type object 'LineEnd' has no attribute 'mayReturnEmpty'
When I just use "line = assignment | restOfLine" instead, the parser
runs into an infinite loop on the snippet above, with or without the
"join readlines" trick.
Thank you for any help,
Robert
Btw, how can I use a pyparsing.Dict here to get direct access e.g. to
myParseResult['floin_file']?
|
|
From: Michael B. <mic...@we...> - 2005-01-19 15:31:29
|
:-) Its
esfComment = (Literal (":prol.") +
ZeroOrMore( CharsNotIn (":") | ( ":eprol" + ~Literal("."))) +
Literal (":eprol.") ).streamline ().setName("esfComment")
Michael
|
|
From: Michael B. <mic...@we...> - 2005-01-19 14:46:10
|
Hi,
I am trying to ignore the following
:prol.
lotta crap and stuff
:eprol.
esfComment = (Literal (":prol.") +
ZeroOrMore( ?????????????????????????? ) +
Literal (":eprol.") ).streamline ().setName("esfComment")
?????????????????? Stands for the question : What do I need here ?
Somewhat similar to the following _working_ example
ebnfComment = ( "(*" +
ZeroOrMore( CharsNotIn("*") | ( "*" + ~Literal(")") ) ) +
"*)" ).streamline().setName("ebnfComment")
Regards
Michael
|
|
From: Paul M. <pt...@au...> - 2004-11-14 21:07:34
|
Andy -
Welcome to pyparsing!!! This e-mail list has gotten very little activity so
far, so pretty much *everyone* is a first-timer!
Here are some comments on your grammar. You really have most things
"working", but I'd like to clear up some of the concepts that you are just a
bit off-center.
1. It is not necessary, and in some cases incorrect, to pre-declare all of
you parse expressions as Forward(). Forward() is only necessary when
creating a recursive grammar (such as an arithmetic expression, which may
contain within itself other arithmetic expressions, or lists within lists,
etc.). I can see how you would incrementally build up your grammar this way
(since your definition of procToken is built up from several other
expressions, procName, dataStmt and semi) - I do this also, sort of a
top-down definition. But pyparsing (given its Python basis) requires
bottom-up definition, so you approached this by just declaring Forwards for
the sub expressions. This is okay, but when you go the next step and start
filling in the blanks of the sub-expressions, you should move back up in the
code, and *replace* the Forward() with Literal(';') (in the case of semi,
for instance).
2. You must be careful when mixing strings and expressions. This works:
expr = Literal("proc") + ":"
This doesn't:
semi = Forward()
procToken = CaselessLiteral( "proc" ) + procName + Optional(dataStmt) +
semi
semi = ';'
The definition of procToken will reference an empty Forward(), not the
string ';'. If you are coming from C++ world, it is important to know that
in Python, '=' is *not* an operator. So you can't define special behavior
for assignment if the target is of a special class.
3. I have confused you about the meaning of delimitedList. This is *not*
for declaring a list of items in your grammar. It is a short cut for
declaring that you expect a list of items in the incoming text stream. For
example, to read in a set of integers separated by commas, such as "0, 1,
2,3,4,11,0,12", use:
integer = Word(nums)
integerList = delimitedList(integer) # ',' delimiter is the default
In your example, in which you expect one of several specific procNames, you
can try using the oneOf helper function.
procName = oneOf( "print tabulate summary" )
Or you could use the '|' operator, as in:
procName = Literal("print") | Literal("tabulate") | Literal("summary")
which actually matches your grammar definition more closely. Or do as you
did, using MatchFirst's constructor from a list:
procName = MatchFirst( [ "print", "tabulate", "summary" ] )
But all of these statements will result in the exact same grammar, since
oneOf generates a MatchFirst of the words listed in the incoming string.
In summary, your grammar is actually quite close, just the confusion over
delimitedList and the reversed order. You can try making the corrections
yourself, or glance over the following suggested version.
-- Paul
> ident = Word( alphas, alphanums )
> semi = Literal(";")
> dataStmt = CaselessLiteral( "data" ) + "=" + ident
> procName = MatchFirst( [ "print", "tabulate", "summary" ] ) # this
works, but I prefer using '|' or oneOf
> runStmt = CaselessLiteral( "run" ) + semi
> procToken = CaselessLiteral( "proc" ) + procName + Optional(dataStmt) +
semi
----- Original Message -----
From: "Andy Elvey" <and...@pa...>
To: <pyp...@li...>
Sent: Sunday, November 14, 2004 1:55 PM
Subject: [Pyparsing] Problem with grammar
> Hi all -
> I'm a first-timer here, and am having a problem with my parser.
> I'm trying to write a parser that follows the following rules -
>
> proc_statement = "proc" + procname + Optional(data_statement) +
semicolon +
> run_statement
> proc_name = "print" or "summary" or "tabulate"
> data_statement = "data" + "=" + dataset_name + semicolon
> run_statement = "run" + semicolon
>
> I am getting this error, and I have no idea why -
> Traceback (most recent call last):
> File "minisas.py", line 28, in ?
> procName = MatchFirst( delimitedList( "print", "tabulate", "summary",
> delim="," ) )
> TypeError: delimitedList() got multiple values for keyword argument
'delim'
>
> The following examples would all be legal, according to the grammar
> ( Note - the "run" does not have to be on the same line as the proc
> statement )
> *** Start of examples ***
> proc print; run;
>
> proc print data=fred; run;
>
> proc summary; run;
>
> proc summary data=mydata2; run;
>
> proc tabulate; run;
> *** End of examples ***
>
> Here is what I have so far -
> *** Start of code ***
>
> # minisas.py
> #
> # simple demo of a SAS-like language
> #
> from pyparsing import *
>
> def test( str ):
> print str,"->"
> try:
> tokens = sasgrammar.parseString( str )
> print "tokens = ", tokens
> except ParseException, err:
> print " "*err.loc + "^\n" + err.msg
> print err
> print
>
>
> # Define tokens
> sasprog = Forward()
> procName = Forward()
> semi = Forward()
> dataStmt = Forward()
> runStmt = Forward()
> ident = Forward()
> procToken = CaselessLiteral( "proc" ) + procName + Optional(dataStmt) +
semi
> procName = MatchFirst( delimitedList( "print", "tabulate", "summary",
> delim="," ) )
> dataStmt = CaselessLiteral( "data" ) + "=" + ident
> ident = Word( alphas, alphanums )
> runStmt = CaselessLiteral( "run" ) + semi
> semi = ";"
>
> # Define the grammar
> sasgrammar << sasprog
>
> # Test the grammar
> test( "proc print ; run ; " )
> test( "proc print data = fred ; run ; " )
> test( "proc contents ; run ; " )
> test( "proc contents data = mydata2 ; run ; " )
> test( "proc tabulate; " )
> test( "proc tabulate data = foo3; run ; " )
>
> *** End of code ***
>
> So, any help is very much appreciated, as I am totally lost ... :-)
> Many thanks in advance -
> - Andy
>
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: InterSystems CACHE
> FREE OODBMS DOWNLOAD - A multidimensional database that combines
> robust object and relational technologies, making it a perfect match
> for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
> _______________________________________________
> Pyparsing-users mailing list
> Pyp...@li...
> https://lists.sourceforge.net/lists/listinfo/pyparsing-users
|
|
From: Andy E. <and...@pa...> - 2004-11-14 01:58:17
|
Hi all -
I'm a first-timer here, and am having a problem with my parser.
I'm trying to write a parser that follows the following rules -
proc_statement = "proc" + procname + Optional(data_statement) + semicolon +
run_statement
proc_name = "print" or "summary" or "tabulate"
data_statement = "data" + "=" + dataset_name + semicolon
run_statement = "run" + semicolon
I am getting this error, and I have no idea why -
Traceback (most recent call last):
File "minisas.py", line 28, in ?
procName = MatchFirst( delimitedList( "print", "tabulate", "summary",
delim="," ) )
TypeError: delimitedList() got multiple values for keyword argument 'delim'
The following examples would all be legal, according to the grammar
( Note - the "run" does not have to be on the same line as the proc
statement )
*** Start of examples ***
proc print; run;
proc print data=fred; run;
proc summary; run;
proc summary data=mydata2; run;
proc tabulate; run;
*** End of examples ***
Here is what I have so far -
*** Start of code ***
# minisas.py
#
# simple demo of a SAS-like language
#
from pyparsing import *
def test( str ):
print str,"->"
try:
tokens = sasgrammar.parseString( str )
print "tokens = ", tokens
except ParseException, err:
print " "*err.loc + "^\n" + err.msg
print err
print
# Define tokens
sasprog = Forward()
procName = Forward()
semi = Forward()
dataStmt = Forward()
runStmt = Forward()
ident = Forward()
procToken = CaselessLiteral( "proc" ) + procName + Optional(dataStmt) + semi
procName = MatchFirst( delimitedList( "print", "tabulate", "summary",
delim="," ) )
dataStmt = CaselessLiteral( "data" ) + "=" + ident
ident = Word( alphas, alphanums )
runStmt = CaselessLiteral( "run" ) + semi
semi = ";"
# Define the grammar
sasgrammar << sasprog
# Test the grammar
test( "proc print ; run ; " )
test( "proc print data = fred ; run ; " )
test( "proc contents ; run ; " )
test( "proc contents data = mydata2 ; run ; " )
test( "proc tabulate; " )
test( "proc tabulate data = foo3; run ; " )
*** End of code ***
So, any help is very much appreciated, as I am totally lost ... :-)
Many thanks in advance -
- Andy
|
|
From: Carl R. <Car...@gm...> - 2004-08-12 14:20:34
|
pyp...@li... wrote: >Send Pyparsing-users mailing list submissions to > pyp...@li... > >To subscribe or unsubscribe via the World Wide Web, visit > https://lists.sourceforge.net/lists/listinfo/pyparsing-users >or, via email, send a message with subject or body 'help' to > pyp...@li... > >You can reach the person managing the list at > pyp...@li... > >When replying, please edit your Subject line so it is more specific >than "Re: Contents of Pyparsing-users digest..." > > >Today's Topics: > > 1. pyparsing 1.2.1 preview (pa...@al...) > >--__--__-- > >Message: 1 >Reply-To: <pa...@al...> >From: <pa...@al...> >To: <pyp...@li...> >Date: Wed, 11 Aug 2004 01:12:36 -0500 >Subject: [Pyparsing] pyparsing 1.2.1 preview > >SSdtIGFib3V0IHRvIHVwZGF0ZSBweXBhcnNpbmcgdG8gdmVyc2lvbiAxLjIuMSwgYW5kIEknbSBs >b29raW5nIGZvciB0ZXN0ZXJzLiAgQmVsb3cgaXMgdGhlIGNoYW5nZSBsb2cgZm9yIHRoZSBuZXcg >ZmVhdHVyZXMgaW4gMS4yLjEuDQoNClRoZSBtb3N0ICdpZmZ5JyBjaGFuZ2UgKGJ1dCBhbHNvIHRo >ZSBtb3N0IGltcG9ydGFudCAtIEkgcmVhbGx5IHdhbnQgdG8gZ2V0IHRoaXMgb25lIHJlbGVhc2Vk >IGluIHBhcnR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bmcg >dG8gZXh0cmFjdA0KICBzbGljZSwgb3IgbWFrZSBhIGNvcHkgdXNpbmcgWzpdLiAoVGhhbmtzLCBX >aWxzb24gRm93bGllISkNCiAgDQotIEZpeGVkIGJ1ZyBpbiByZXR1cm5pbmcgdG9rZW5zIGZyb20g >dW4tR3JvdXBlZCBBbmQncywgT3IncyBhbmQgDQogIE1hdGNoRmlyc3Qncywgd2hlcmUgdG9vIG1h >bnkgdG9rZW5zIHdvdWxkIGJlIGluY2x1ZGVkIGluIHRoZSByZXN1bHRzLCANCiAgY29uZm91bmRp >bmcgcGFyc2UgYWN0aW9ucyBhbmQgcmV0dXJuZWQgcmVzdWx0cy4NCiAgDQotIEFkZGVkIGEgYmVh >dXRpZnVsIGV4YW1wbGUgZm9yIHBhcnNpbmcgTW96aWxsYSBjYWxlbmRhciBmaWxlcyAoVGhhbmtz >LCANCiAgUGV0cmkgU2F2b2xhaW5lbiEpLg0KDQotIEFkZGVkIHN1cHBvcnQgZm9yIGR5bmFtaWNh >bGx5IG1vZGlmeWluZyBGb3J3YXJkIGV4cHJlc3Npb25zIGR1cmluZw0KICBwYXJzaW5nLg0KIA== > > > > >--__--__-- > >_______________________________________________ >Pyparsing-users mailing list >Pyp...@li... >https://lists.sourceforge.net/lists/listinfo/pyparsing-users > > >End of Pyparsing-users Digest > > > > Hi Paul, very interesting but i am not able to read it! :-( with kind regards Carl |
|
From: <pa...@al...> - 2004-08-11 06:09:14
|
SSdtIGFib3V0IHRvIHVwZGF0ZSBweXBhcnNpbmcgdG8gdmVyc2lvbiAxLjIuMSwgYW5kIEknbSBs b29raW5nIGZvciB0ZXN0ZXJzLiAgQmVsb3cgaXMgdGhlIGNoYW5nZSBsb2cgZm9yIHRoZSBuZXcg ZmVhdHVyZXMgaW4gMS4yLjEuDQoNClRoZSBtb3N0ICdpZmZ5JyBjaGFuZ2UgKGJ1dCBhbHNvIHRo ZSBtb3N0IGltcG9ydGFudCAtIEkgcmVhbGx5IHdhbnQgdG8gZ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BleGNlcHRpb24gd2hlbiB0cnlpbmcg dG8gZXh0cmFjdA0KICBzbGljZSwgb3IgbWFrZSBhIGNvcHkgdXNpbmcgWzpdLiAoVGhhbmtzLCBX aWxzb24gRm93bGllISkNCiAgDQotIEZpeGVkIGJ1ZyBpbiByZXR1cm5pbmcgdG9rZW5zIGZyb20g dW4tR3JvdXBlZCBBbmQncywgT3IncyBhbmQgDQogIE1hdGNoRmlyc3Qncywgd2hlcmUgdG9vIG1h bnkgdG9rZW5zIHdvdWxkIGJlIGluY2x1ZGVkIGluIHRoZSByZXN1bHRzLCANCiAgY29uZm91bmRp bmcgcGFyc2UgYWN0aW9ucyBhbmQgcmV0dXJuZWQgcmVzdWx0cy4NCiAgDQotIEFkZGVkIGEgYmVh dXRpZnVsIGV4YW1wbGUgZm9yIHBhcnNpbmcgTW96aWxsYSBjYWxlbmRhciBmaWxlcyAoVGhhbmtz LCANCiAgUGV0cmkgU2F2b2xhaW5lbiEpLg0KDQotIEFkZGVkIHN1cHBvcnQgZm9yIGR5bmFtaWNh bGx5IG1vZGlmeWluZyBGb3J3YXJkIGV4cHJlc3Npb25zIGR1cmluZw0KICBwYXJzaW5nLg0KIA== |
|
From: <ben...@id...> - 2004-05-25 08:47:22
|
Dear Open Source developer I am doing a research project on "Fun and Software Development" in which I kindly invite you to participate. You will find the online survey under http://fasd.ethz.ch/qsf/. The questionnaire consists of 53 questions and you will need about 15 minutes to complete it. With the FASD project (Fun and Software Development) we want to define the motivational significance of fun when software developers decide to engage in Open Source projects. What is special about our research project is that a similar survey is planned with software developers in commercial firms. This procedure allows the immediate comparison between the involved individuals and the conditions of production of these two development models. Thus we hope to obtain substantial new insights to the phenomenon of Open Source Development. With many thanks for your participation, Benno Luthiger PS: The results of the survey will be published under http://www.isu.unizh.ch/fuehrung/blprojects/FASD/. We have set up the mailing list fa...@we... for this study. Please see http://fasd.ethz.ch/qsf/mailinglist_en.html for registration to this mailing list. _______________________________________________________________________ Benno Luthiger Swiss Federal Institute of Technology Zurich 8092 Zurich Mail: benno.luthiger(at)id.ethz.ch _______________________________________________________________________ |
|
From: Carl K. <cmk...@gm...> - 2004-03-09 09:42:02
|
Hi, I tried to backport pyparsing-1.1.1 to work with jython-2.2a0. This jython version supports a mixture of 2.1, 2.2. (no newstyle classes i.e.) It is easy to get rid of super (__init__) and enumerate in pyparsing. However, I didn't suceed in backporting to python-2.1 features or even to jython-2.2. In my opinion this useful tool should at least support jython-2.2 if not python-2.1. Regards Carl -- +++ NEU bei GMX und erstmalig in Deutschland: TÜV-geprüfter Virenschutz +++ 100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz |