3 ms·
Why would you grep for the emoji? The actual pattern you want to match is the standard format of the error message that proceeds it, which hasn’t changed in eon
by db48x 2y ago
Why would you grep for the emoji? The actual pattern you want to match is the standard format of the error message that proceeds it, which hasn’t changed in eons:
my $line = "infinite-loop-linked-list.c:30:10: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]";
grammar gcc {
token filename { <-[:]>+ };
token linenumber { \d+ };
token colnumber { \d+ };
token severity { info|warning|error };
token message { .* $$ };
regex diagnostic { <filename>
[\:] <linenumber>
[\:] <colnumber>
[\:]\s <severity>
[\:]\s <message>
};
token TOP { <diagnostic> };
}
say gcc.parse($line);
which when run produces the obvious output:
「infinite-loop-linked-list.c:30:10: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]」
diagnostic => 「infinite-loop-linked-list.c:30:10: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]」
filename => 「infinite-loop-linked-list.c」
linenumber => 「30」
colnumber => 「10」
severity => 「warning」
message => 「infinite loop [CWE-835] [-Wanalyzer-infinite-loop]」
I’ll leave handling filenames containing colons as an exercise for the reader.
The emoji just focus the reader’s eye on the most critical line of the explanation.