def testVariable(self): actual = grammar.getRule('variable') self.assertIsNotNone(actual) self.assertEqual(len(actual), 3) typeNode = actual[0] nameNode = actual[1] handleNode = actual[2] self.assertEqual(typeNode.name, 'type') self.assertEqual(len(typeNode.childs), 1) altNode = typeNode.childs[0] self.assertEqual(len(altNode.childs), 2) self.assertEqual(altNode.childs[0].value, 'var') self.assertEqual(altNode.childs[1].name, 'type')
def testType(self): expected = mt.ParamNode('type') altNode = mt.AltNode() altNode.childs.append(mt.NamedNode('array_type')) altNode.childs.append(mt.NamedNode('simple_type')) expected.childs.append(altNode) actual = grammar.getRule('type') self.assertIsNotNone(actual) self.assertEqual(len(actual), 1) typeNode = actual[0] self.assertEqual(len(typeNode.childs), 3) self.assertEqual(typeNode.childs[0].name, 'dict_type') self.assertEqual(typeNode.childs[1].name, 'array_type') self.assertEqual(typeNode.childs[2].name, 'simple_type')
def match(self, leftIndex, rightIndex, source): """ Take named rule. """ nodes = grammar.getRule(self.name) return matchNodes(nodes, leftIndex, rightIndex, source)