@@ -35,6 +35,11 @@ namespace mqt::debugger {
3535
3636namespace {
3737
38+ /* *
39+ * @brief Check whether a string is non-empty and contains only digits.
40+ * @param text The string to validate.
41+ * @return True if the string is non-empty and all characters are digits.
42+ */
3843bool isDigits (const std::string& text) {
3944 if (text.empty ()) {
4045 return false ;
@@ -48,6 +53,12 @@ struct LineColumn {
4853 size_t column = 1 ;
4954};
5055
56+ /* *
57+ * @brief Compute the 1-based line and column for a given character offset.
58+ * @param code The source code to inspect.
59+ * @param offset The zero-based character offset in the source code.
60+ * @return The line and column of the offset in the source code.
61+ */
5162LineColumn lineColumnForOffset (const std::string& code, size_t offset) {
5263 LineColumn location;
5364 const auto lineStartPos = code.rfind (' \n ' , offset);
@@ -64,6 +75,13 @@ LineColumn lineColumnForOffset(const std::string& code, size_t offset) {
6475 return location;
6576}
6677
78+ /* *
79+ * @brief Compute the 1-based line and column for a target within a line.
80+ * @param code The source code to inspect.
81+ * @param instructionStart The zero-based offset of the instruction start.
82+ * @param target The target token to locate on the line.
83+ * @return The line and column of the target, or the first non-space column.
84+ */
6785LineColumn lineColumnForTarget (const std::string& code, size_t instructionStart,
6886 const std::string& target) {
6987 LineColumn location = lineColumnForOffset (code, instructionStart);
@@ -90,6 +108,14 @@ LineColumn lineColumnForTarget(const std::string& code, size_t instructionStart,
90108 return location;
91109}
92110
111+ /* *
112+ * @brief Format a parse error with line/column location information.
113+ * @param code The source code to inspect.
114+ * @param instructionStart The zero-based offset of the instruction start.
115+ * @param detail The error detail text.
116+ * @param target Optional target token to locate more precisely.
117+ * @return The formatted error string.
118+ */
93119std::string formatParseError (const std::string& code, size_t instructionStart,
94120 const std::string& detail,
95121 const std::string& target = " " ) {
@@ -98,6 +124,12 @@ std::string formatParseError(const std::string& code, size_t instructionStart,
98124 std::to_string (location.column ) + " : " + detail;
99125}
100126
127+ /* *
128+ * @brief Build an error detail string for an invalid target.
129+ * @param target The invalid target token.
130+ * @param context Additional context to append.
131+ * @return The formatted detail string.
132+ */
101133std::string invalidTargetDetail (const std::string& target,
102134 const std::string& context) {
103135 std::string detail = " Invalid target qubit " ;
@@ -107,13 +139,27 @@ std::string invalidTargetDetail(const std::string& target,
107139 return detail;
108140}
109141
142+ /* *
143+ * @brief Build an error detail string for an invalid register declaration.
144+ * @param trimmedLine The register declaration line.
145+ * @return The formatted detail string.
146+ */
110147std::string invalidRegisterDetail (const std::string& trimmedLine) {
111148 std::string detail = " Invalid register declaration " ;
112149 detail += trimmedLine;
113150 detail += " ." ;
114151 return detail;
115152}
116153
154+ /* *
155+ * @brief Validate target references against known registers and indices.
156+ * @param code The source code to inspect.
157+ * @param instructionStart The zero-based offset of the instruction start.
158+ * @param targets The target tokens to validate.
159+ * @param definedRegisters The registers defined in the current scope.
160+ * @param shadowedRegisters The shadowed register names in the current scope.
161+ * @param context Additional context to append to error messages.
162+ */
117163void validateTargets (const std::string& code, size_t instructionStart,
118164 const std::vector<std::string>& targets,
119165 const std::map<std::string, size_t >& definedRegisters,
0 commit comments