def value(self): """Value of the literal (`float`).""" float_str = first_token(self._node).spelling # Remove any C-specific suffix (f, F, l, L) so we can use Python's # float constructor to parse the string. float_str = re.sub(r'^(.*)[fFlL]$', r'\1', float_str) return float(float_str)
def value(self): """Value of the literal (`int`).""" if not any(self._node.get_tokens()): return None int_str = first_token(self._node).spelling # Remove any C-specific suffix (u, U, l, L, ll, LL) so we can use # Python's int constructor to parse the string. int_str = re.sub(r'^(.*?)(ll|LL|[uUlL])$', r'\1', int_str) if int_str.lower().startswith('0x'): return int(int_str, 16) return int(int_str)
def value(self): """Value of the literal (`str`).""" # Strip the leading and ending quotes ('). return first_token(self._node).spelling[1:-1]
def value(self): """Value of the literal (`str`).""" # Remove a wide-string-literal prefix (L, if any) and strip the leading # and ending quotes ("). return re.sub(r'L?"(.*)"', r'\1', first_token(self._node).spelling)
def test_returns_first_token(self): expr_node = self.get_expr('1 + 2', 'int')._node self.assertEqual(first_token(expr_node).spelling, '1')