INNER CODE UNIT · Python
find_line_number
bsilverthorn/maccarone · src/maccarone/preprocessor.py:105
def find_line_number(text: str, pos: int):
#<<find the line number of the given char position>>
return text.count('\n', 0, pos) + 1
#<</>>
class RawSourceVisitor(NodeVisitor):
def __init__(self, raw_source: str, block_at_line: Optional[int] = None):
self._raw_source = raw_source
self._block_at_line = block_at_line
def generic_visit(self, node: Node, visited_children: List[Node]):
return visited_children or node
def visit_maccarone(self, node: Node, visited_children: list):
(first_source, chunks) = visited_children
return [first_source] + list(chain(*chunks))