def generate_vim(filename,error_checking): output_filename = strip_filename(filename) + '.vim' print 'Generating vim file %s\n' % output_filename ah = Autohighlight(filename) ah.parse() outputter = VimOutputter(error_checking) open(output_filename,'w').write(ah.output(outputter))
def generate_emacs(filename): import os.path output_filename = strip_filename(filename) + '.el' ah = Autohighlight(filename) ah.parse() outputter = EmacsOutputter(os.path.basename(strip_filename(filename))) open(output_filename,'w').write(ah.output(outputter)) print "Wrote %s\n" % output_filename
class AhTestContexts(unittest.TestCase): def setUp(self): global test1file self.ah = Autohighlight(StringIO(test1file)) self.ah.parse() def testGetContextsForQ(self): gsd = self.ah.GlobalSymbolDict expected = [Context(Set([gsd['a'],gsd['d']]),gsd['q'],Set([gsd['t']])), \ Context(Set([gsd['a'],gsd['d']]),gsd['q'],Set([gsd['s']])) ] contexts = gsd['q'].get_contexts() self.assertEqual(contexts, expected, "Contexts for %s are not as expected:\n%s\n%s" % ('q',contexts,expected))
class AhTestContexts(unittest.TestCase): def setUp(self): global test1file self.ah = Autohighlight(StringIO(test1file)) self.ah.parse() def testGetContextsForIdn(self): gsd = self.ah.GlobalSymbolDict expected = [Context(Set([gsd["'OF'"]]),gsd['idn'],Set([gsd["'='"]])), \ Context(Set([gsd["':'"]]),gsd['idn'],Set([gsd["'='"]])) ] symbol = gsd['idn'] contexts = symbol.get_contexts() self.assertEqual(contexts, expected, "Contexts for %s are not as expected:\n%s\n%s" % ('t',contexts,expected))
class AhTestContexts(unittest.TestCase): def setUp(self): global test1file self.ah = Autohighlight(StringIO(test1file)) self.ah.parse() def testGetContextsForT(self): gsd = self.ah.GlobalSymbolDict expected = [Context(Set([gsd["x"]]),gsd['t'],Set([gsd["','"]])) ] contexts = gsd['t'].get_contexts() self.assertEqual(contexts, expected, "Contexts for %s are not as expected:\n%s\n%s" % ('t',contexts,expected)) def testGetRegexesForT(self): gsd = self.ah.GlobalSymbolDict #expected = [Context(Set([gsd["x"]]),gsd['t'],Set([gsd["','"]])) ] left_expected = Set('\\,','\\(') right_expected = Set('\\,') for sym in self.ah.GlobalSymbolDict.values(): sym.GlobalSymbolDict = gsd contexts = gsd['t'].get_contexts() left_regex = contexts[0].getLeftRegexes() self.assertEqual(left_regex, left_expected, "Left regex for %s is not as left_expected:\n%s\n%s" % ('t',left_regex,left_expected)) right_regex = contexts[0].getRightRegexes() self.assertEqual(right_regex, right_expected, "Right regex for %s is not as expected:\n%s\n%s" % ('t',right_regex,right_expected)) self.assertEqual(contexts[0].getMiddleRegexes(), Set('t')) def testGetContextsForX(self): gsd = self.ah.GlobalSymbolDict symbol = gsd['x'] expected = [Context(Set([gsd["'('"]]),gsd['x'],Set([gsd["')'"]])), \ Context(Set([gsd["'('"]]),gsd['x'],Set([gsd["t"]])) ] contexts = symbol.get_contexts() self.assertEqual(contexts, expected, "Contexts for %s are not as expected:\n%s\n%s" % (symbol.defining_token.text,contexts,expected)) def testGetContextsForProductionForX(self): gsd = self.ah.GlobalSymbolDict symbol = gsd['x'] symbol.GlobalSymbolDict = gsd expected = [ Context(Set([gsd["'('"]]),gsd['x'],Set([gsd["t"]])) ] contexts = symbol.get_contexts_for_production(symbol.productions[0]) self.assertEqual(contexts, expected, "Contexts for production 0 for %s are not as expected:\n%s\n%s" % (symbol.defining_token.text,contexts,expected))