1 # Matches and targets are specified using XML files.
2 # They provide the following information:
3 # - The context required by the match
4 # - The processor that actually implements the match or target
5 # - The parameters that the processor needs to evaluate the context
10 def __init__(self, file_path):
14 self.operand = "VALUE"
18 self.xmldoc = libxml2.parseFile(file_path)
20 # TODO: Check xmldoc against a schema
21 p = self.xmldoc.xpathNewContext()
23 # <context select="..."/>
24 # <rule><argument param="..."/></rule>
25 # <processor name="..."/>
27 context = p.xpathEval('//context/@select')
28 self.context = context[0].content
30 processor = p.xpathEval('//processor/@filename')
31 self.context = processor[0].content
33 name = p.xpathEval('//rule/argument/name')
34 help = p.xpathEval('//rule/argument/help')
35 target = p.xpathEval('//rule/argument/operand')
37 context = p.xpathEval('//attributes/attribute[@terminal="yes"]')
38 self.terminal = (context != [])
40 self.arguments = map(lambda (name,help,target):{'name':name.content,'help':help.content,'target':target.content}, zip(name,help,target))