def convert_leaf(self, grammar, type, value, prefix, start_pos): # print('leaf', repr(value), token.tok_name[type]) if type == tokenize.NAME: if value in grammar.keywords: if value in ('def', 'class', 'lambda'): self._scope_names_stack.append({}) return pt.Keyword(self.position_modifier, value, start_pos, prefix) else: name = pt.Name(self.position_modifier, value, start_pos, prefix) # Keep a listing of all used names arr = self._used_names.setdefault(name.value, []) arr.append(name) arr = self._scope_names_stack[-1].setdefault(name.value, []) arr.append(name) return name elif type == STRING: return pt.String(self.position_modifier, value, start_pos, prefix) elif type == NUMBER: return pt.Number(self.position_modifier, value, start_pos, prefix) elif type == NEWLINE: return pt.Newline(self.position_modifier, value, start_pos, prefix) elif type == INDENT: return pt.Indent(self.position_modifier, value, start_pos, prefix) elif type == DEDENT: return pt.Dedent(self.position_modifier, value, start_pos, prefix) elif type == ENDMARKER: return pt.EndMarker(self.position_modifier, value, start_pos, prefix) else: return pt.Operator(self.position_modifier, value, start_pos, prefix)
def convert_leaf(self, grammar, type, value, prefix, start_pos): #print('leaf', value, pytree.type_repr(type)) if type == tokenize.NAME: if value in grammar.keywords: if value in ('def', 'class', 'lambda'): self._scope_names_stack.append({}) return pt.Keyword(self.position_modifier, value, start_pos, prefix) else: name = pt.Name(self.position_modifier, value, start_pos, prefix) # Keep a listing of all used names arr = self._used_names.setdefault(name.value, []) arr.append(name) arr = self._scope_names_stack[-1].setdefault(name.value, []) arr.append(name) return name elif type == STRING: return pt.String(self.position_modifier, value, start_pos, prefix) elif type == NUMBER: return pt.Number(self.position_modifier, value, start_pos, prefix) elif type in (NEWLINE, ENDMARKER): return pt.Whitespace(self.position_modifier, value, start_pos, prefix) else: return pt.Operator(self.position_modifier, value, start_pos, prefix)
def convert_leaf(self, grammar, type, value, prefix, start_pos): # print('leaf', repr(value), token.tok_name[type]) if type == tokenize.NAME: if value in grammar.keywords: return pt.Keyword(value, start_pos, prefix) else: name = pt.Name(value, start_pos, prefix) # Keep a listing of all used names arr = self._used_names.setdefault(name.value, []) arr.append(name) return name elif type == STRING: return pt.String(value, start_pos, prefix) elif type == NUMBER: return pt.Number(value, start_pos, prefix) elif type == NEWLINE: return pt.Newline(value, start_pos, prefix) elif type == ENDMARKER: return pt.EndMarker(value, start_pos, prefix) else: return pt.Operator(value, start_pos, prefix)