Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <iosfwd>
7 : #include <string>
8 :
9 : namespace Options {
10 : /// \ingroup OptionParsingGroup
11 : /// Information about the nested operations being performed by the
12 : /// parser, for use in printing errors. A default-constructed
13 : /// Context is printed as an empty string. This struct is
14 : /// primarily used as an argument to PARSE_ERROR for reporting input
15 : /// file parsing errors. Users outside of the core option parsing
16 : /// code should not need to manipulate the contents.
17 1 : struct Context {
18 0 : bool top_level{true};
19 : /// (Part of) the parsing "backtrace" printed with an error
20 1 : std::string context;
21 : /// File line number (0 based)
22 1 : int line{-1};
23 : /// File column number (0 based)
24 1 : int column{-1};
25 :
26 : /// Append a line to the context. Automatically appends a colon.
27 1 : void append(const std::string& c) { context += c + ":\n"; }
28 : };
29 :
30 0 : std::ostream& operator<<(std::ostream& s, const Context& c);
31 :
32 : } // namespace Options
|