sqs1.py
Go to the documentation of this file.
00001 #!c:/python26/python.exe
00002 #
00003 # first sample using rule
00004 #
00005 import sys
00006 import rocon_uri.rule_parser as rule_parser
00007 #
00008 # we define the rule as a list of (sub)rules
00009 #
00010 # r"\S"*   means regular expression specifying 
00011 #          any character except blank 
00012 rule=['sqs  ::=  parms  fileid ', 
00013       'parms::=  r"\S"* ',        
00014       'fileid::= r"\S"* ']        
00015 #
00016 # we concatenate arguments ... as words
00017 parms=' '.join(sys.argv[1:])
00018 #
00019 # we make the parsing 
00020 cmp=rule_parser.rp.match(rule,parms)
00021 # 
00022 #as re module, if the result object is None, 
00023 # the parsing is unsuccessful
00024 if cmp==None:
00025         print "Error in parsing:"   
00026 else:
00027     #
00028     # now, to get values from parsing, 
00029     # we use rule names as parser arguments.
00030     # cmp.sqs    will contain input parameters
00031     # cmp.parms  will contain string to locate
00032     # cmp.fileid will contain fileid to search in
00033         try:
00034                 id=open(cmp.fileid)
00035                 for l in id.readlines():
00036                         if l.find(cmp.parms)>-1: 
00037                                 print l[:-1]
00038         except Exception,e:
00039                 print e
00040         else:
00041                 id.close()
00042 


rocon_ebnf
Author(s): LParis
autogenerated on Fri May 2 2014 10:35:48