32 return Str.take_front(Pos - Str.begin());
35 Str = Str.drop_front(Pos - Str.begin());
41 FinishedMultiline.clear();
47 if (!Buffer.empty()) {
48 if (NextIdx < Buffer.size())
49 return std::move(Buffer[NextIdx++]);
59 if (!InProgressMultiline.empty()) {
60 if (std::optional<StringRef> MultilineEnd = parseMultiLineEnd(Line)) {
62 assert(FinishedMultiline.empty() &&
63 "At most one multi-line element can be finished at a time.");
64 FinishedMultiline.swap(InProgressMultiline);
67 return *parseElement(FinishedMultiline);
77 if (std::optional<MarkupNode> Element = parseElement(Line)) {
78 parseTextOutsideMarkup(
takeTo(Line, Element->Text.
begin()));
79 Buffer.push_back(std::move(*Element));
86 if (std::optional<StringRef> MultilineBegin = parseMultiLineBegin(Line)) {
88 parseTextOutsideMarkup(
takeTo(Line, MultilineBegin->
begin()));
97 parseTextOutsideMarkup(Line);
106 if (InProgressMultiline.empty())
108 FinishedMultiline.swap(InProgressMultiline);
109 parseTextOutsideMarkup(FinishedMultiline);
114std::optional<MarkupNode> MarkupParser::parseElement(
StringRef Line) {
117 size_t BeginPos = Line.find(
"{{{");
120 size_t EndPos = Line.find(
"}}}", BeginPos + 3);
125 Element.
Text = Line.slice(BeginPos, EndPos);
126 Line = Line.substr(EndPos);
131 std::tie(Element.
Tag, FieldsContent) =
Content.split(
':');
136 if (!FieldsContent.
empty())
138 else if (
Content.back() ==
':')
139 Element.
Fields.push_back(FieldsContent);
154void MarkupParser::parseTextOutsideMarkup(
StringRef Text) {
158 while (SGRSyntax.
match(Text, &Matches)) {
160 if (Matches.
begin()->begin() != Text.begin())
172std::optional<StringRef> MarkupParser::parseMultiLineBegin(StringRef Line) {
174 size_t BeginPos =
Line.rfind(
"{{{");
177 size_t BeginTagPos = BeginPos + 3;
181 size_t EndPos =
Line.find(
"}}}", BeginTagPos);
186 size_t EndTagPos =
Line.find(
':', BeginTagPos);
189 StringRef
Tag =
Line.slice(BeginTagPos, EndTagPos);
192 return Line.substr(BeginPos);
197std::optional<StringRef> MarkupParser::parseMultiLineEnd(StringRef Line) {
198 size_t EndPos =
Line.find(
"}}}");
201 return Line.take_front(EndPos + 3);
This file declares the log symbolizer markup data model and parser.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
size - Get the string size.
static constexpr size_t npos
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
StringSet - A wrapper for StringMap that provides set-like functionality.
bool contains(StringRef key) const
Check if the set contains the given key.
std::optional< MarkupNode > nextNode()
Returns the next node in the input sequence.
void flush()
Inform the parser of that the input stream has ended.
MarkupParser(StringSet<> MultilineTags={})
void parseLine(StringRef Line)
Parses an individual Line of input.
static MarkupNode textNode(StringRef Text)
static void advanceTo(StringRef &Str, StringRef::iterator Pos)
static const char SGRSyntaxStr[]
static StringRef takeTo(StringRef Str, StringRef::iterator Pos)
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
A node of symbolizer markup.
StringRef Text
The full text of this node in the input.
SmallVector< StringRef > Fields
If this represents an element with fields, a list of the field contents.
StringRef Tag
If this represents an element, the tag. Otherwise, empty.