Path: blob/main/python/pylang/src/output/comments.py
1398 views
# vim:fileencoding=utf-81# License: BSD Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>2from __python__ import hash_literals34from ast_types import AST_Exit, is_node_type567def output_comments(comments, output, nlb):8for comm in comments:9if comm.type is "comment1":10output.print("//" + comm.value + "\n")11output.indent()12elif comm.type is "comment2":13output.print("/*" + comm.value + "*/")14if nlb:15output.print("\n")16output.indent()17else:18output.space()192021def print_comments(self, output):22c = output.options.comments23if c:24start = self.start25if start and not start._comments_dumped:26start._comments_dumped = True27comments = start.comments_before28# XXX: ugly fix for https://github.com/mishoo/RapydScript2/issues/11229# if this node is `return` or `throw`, we cannot allow comments before30# the returned or thrown value.31if is_node_type(32self, AST_Exit33) and self.value and self.value.start.comments_before and self.value.start.comments_before.length > 0:34comments = (comments35or []).concat(self.value.start.comments_before)36self.value.start.comments_before = []3738if c.test:39comments = comments.filter(40lambda comment: c.test(comment.value))41elif jstype(c) is "function":42comments = comments.filter(lambda comment: c(self, comment))4344output_comments(comments, output, start.nlb)454647