[PATCH 2/4] perf expr: Allow comments in custom metric file

From: Jiri Olsa
Date: Mon May 11 2020 - 16:53:27 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 c6a930ed22e6..e9b294ba09fc 100644
--- a/tools/perf/util/expr.l
+++ b/tools/perf/util/expr.l
@@ -82,6 +82,8 @@ static int str(yyscan_t scanner, int token, int runtime)
%}

%x custom
+%x comment_single
+%x comment_multi

number [0-9]*\.?[0-9]+

@@ -116,6 +118,16 @@ else { return ELSE; }
#smt_on { return SMT_ON; }
{number} { return value(yyscanner); }
{symbol} { return str(yyscanner, ID, sctx->runtime); }
+
+"//" { BEGIN(comment_single); }
+<comment_single>\n { BEGIN(INITIAL); }
+<comment_single>. { }
+
+"/*" { BEGIN(comment_multi); }
+<comment_multi>"*/" { BEGIN(INITIAL); }
+<comment_multi>\n { }
+<comment_multi>. { }
+
"|" { return '|'; }
"^" { return '^'; }
"&" { return '&'; }
--
2.25.4