Coverage for trlc/location_md.py: 93%
13 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-08-12 05:01 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-08-12 05:01 +0000
1#!/usr/bin/env python3
2#
3# TRLC - Treat Requirements Like Code
4# Copyright (C) 2026 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
5#
6# This file is part of the TRLC Python Reference Implementation.
7#
8# TRLC is free software: you can redistribute it and/or modify it
9# under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# TRLC is distributed in the hope that it will be useful, but WITHOUT
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16# License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with TRLC. If not, see <https://www.gnu.org/licenses/>.
21"""Location helpers used by the Markdown lexer."""
23from trlc.errors import Location
24from trlc.lexer import TRLC_Lexer
27class MD_Location(Location):
28 """Location for markdown-emitted STRING tokens.
30 Carries the raw string value and exposes ``text()`` so nested lexers can
31 treat markdown strings like regular TRLC string literals.
32 """
34 def __init__(
35 self,
36 file_name,
37 line_no,
38 col_no,
39 token_text="",
40 mh=None,
41 ):
42 super().__init__(file_name, line_no, col_no)
43 self._token_text = token_text
44 self._full_text = f'"""{self._token_text}"""'
46 # Nested_Lexer.source_location() expects these Source_Reference-like
47 # attributes to exist on string literal locations.
48 if mh is not None: 48 ↛ exitline 48 didn't return from function '__init__' because the condition on line 48 was always true
49 self.lexer = TRLC_Lexer(mh, file_name, self._full_text)
50 self.start_pos = 0
51 self.end_pos = len(self._full_text) - 1
53 def text(self):
54 return self._full_text