[PATCH 2/3] perf expr: Allow comments in custom metric file
From: Jiri Olsa
Date: Tue Apr 21 2020 - 14:14:12 EST
Adding support to use comments within the custom metric file
with both the shell '# ... ' and C '/* ... */ styles.
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/expr.l | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tools/perf/util/expr.l b/tools/perf/util/expr.l
index 5561c360cd27..99547182ef79 100644
--- a/tools/perf/util/expr.l
+++ b/tools/perf/util/expr.l
@@ -69,6 +69,8 @@ static int str(yyscan_t scanner, int token)
%}
%x custom
+%x comment_C
+%x comment_sh
number [0-9]+
@@ -103,6 +105,16 @@ else { return ELSE; }
#smt_on { return SMT_ON; }
{number} { return value(yyscanner, 10); }
{symbol} { return str(yyscanner, ID); }
+
+"/*" { BEGIN(comment_C); }
+<comment_C>"*/" { BEGIN(INITIAL); }
+<comment_C>\n { }
+<comment_C>. { }
+
+"#" { BEGIN(comment_sh); }
+<comment_sh>\n { BEGIN(INITIAL); }
+<comment_sh>. { }
+
"|" { return '|'; }
"^" { return '^'; }
"&" { return '&'; }
--
2.25.3