def test_extractnames(self): ss = "-+12354.5678E-12_aoeu" expr = parse(ss) xtor = ExtractNames() xtor.visit(expr) eq_(xtor.names, ['aoeu']) ss2 = ".02808_a123_45" expr = parse(ss2) xtor = ExtractNames() xtor.visit(expr) eq_(xtor.names, ['a123_45']) funccall = parse("foo(a, b-3+x(14), c=d+1)") xtor = ExtractNames() xtor.visit(funccall) eq_(xtor.names, ['a', 'b', 'd']) eq_(xtor.funcnames, ['foo', 'x']) power = parse("+1**2_a8") xtor = ExtractNames() xtor.visit(power) eq_(xtor.names, ['a8']) eq_(xtor.funcnames, [])
def test_char_lit_const(self): clc2 = parse("aoeu_'1202\"04''028'").subexpr[0] clc3 = parse('1_"as ""onthu\'sanetu"').subexpr[0] eq_(clc2.kind.param.name, 'aoeu') eq_(clc2.string, '1202"04\'028') eq_(clc3.kind.param.digit_string, '1') eq_(clc3.string, 'as "onthu\'sanetu')
def __init__(self, expr_str): self.expr_str = expr_str.lower() self._expr = fort_expr.parse(self.expr_str) xtor = fort_expr.ExtractNames() xtor.visit(self._expr) self.funcnames = set(xtor.funcnames) self.names = set(xtor.names).union(self.funcnames)
def _tester(tstr, res, funcs=None): expr = parse(tstr) xtor = ExtractNames() xtor.visit(expr) eq_(xtor.names, res) if funcs: eq_(xtor.funcnames, funcs)
def test_func_ref(self): ss = "foo(a, b-3+x(14), c=d+1)" expr = parse(ss)