[Pyparsing] Problem with grammar
Brought to you by:
ptmcg
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 |