31 return Str.take_front(Pos - Str.begin());
34 Str = Str.drop_front(Pos - Str.begin());
40 FinishedMultiline.clear();
46 if (!Buffer.empty()) {
47 if (NextIdx < Buffer.size())
48 return std::move(Buffer[NextIdx++]);
58 if (!InProgressMultiline.empty()) {
59 if (std::optional<StringRef> MultilineEnd = parseMultiLineEnd(Line)) {
61 assert(FinishedMultiline.empty() &&
62 "At most one multi-line element can be finished at a time.");
63 FinishedMultiline.swap(InProgressMultiline);
66 return *parseElement(FinishedMultiline);
76 if (std::optional<MarkupNode> Element = parseElement(Line)) {
77 parseTextOutsideMarkup(
takeTo(Line, Element->Text.
begin()));
78 Buffer.push_back(std::move(*Element));
85 if (std::optional<StringRef> MultilineBegin = parseMultiLineBegin(Line)) {
87 parseTextOutsideMarkup(
takeTo(Line, MultilineBegin->
begin()));
96 parseTextOutsideMarkup(Line);
105 if (InProgressMultiline.empty())
107 FinishedMultiline.swap(InProgressMultiline);
108 parseTextOutsideMarkup(FinishedMultiline);
113std::optional<MarkupNode> MarkupParser::parseElement(
StringRef Line) {
116 size_t BeginPos = Line.find(
"{{{");
119 size_t EndPos = Line.find(
"}}}", BeginPos + 3);
124 Element.
Text = Line.slice(BeginPos, EndPos);
125 Line = Line.substr(EndPos);
130 std::tie(Element.
Tag, FieldsContent) =
Content.split(
':');
135 if (!FieldsContent.
empty())
137 else if (
Content.back() ==
':')
138 Element.
Fields.push_back(FieldsContent);
153void MarkupParser::parseTextOutsideMarkup(
StringRef Text) {
157 while (SGRSyntax.
match(Text, &Matches)) {
159 if (Matches.
begin()->begin() != Text.begin())
171std::optional<StringRef> MarkupParser::parseMultiLineBegin(StringRef Line) {
173 size_t BeginPos =
Line.rfind(
"{{{");
176 size_t BeginTagPos = BeginPos + 3;
180 size_t EndPos =
Line.find(
"}}}", BeginTagPos);
185 size_t EndTagPos =
Line.find(
':', BeginTagPos);
188 StringRef
Tag =
Line.slice(BeginTagPos, EndTagPos);
191 return Line.substr(BeginPos);
196std::optional<StringRef> MarkupParser::parseMultiLineEnd(StringRef Line) {
197 size_t EndPos =
Line.find(
"}}}");
200 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.