From e734d1d0e240e19c978c5ce26d171277fe3cb85a Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 10 Sep 2024 22:43:05 +0200 Subject: [PATCH] compose: Allow c-style comments in json files Useful to manager growing the collection of sequences. --- srcs/compose/compile.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/srcs/compose/compile.py b/srcs/compose/compile.py index fe4fe9f..e49196b 100644 --- a/srcs/compose/compile.py +++ b/srcs/compose/compile.py @@ -90,10 +90,17 @@ def parse_sequences_file_xkb(fname, xkb_char_extra_names): seqs.append(s) return seqs +# Basic support for comments in json files. Reads a file +def strip_cstyle_comments(inp): + def strip_line(line): + i = line.find("//") + return line[:i] + "\n" if i >= 0 else line + return "".join(map(strip_line, inp)) + # Parse from a json file containing a dictionary sequence → result string. def parse_sequences_file_json(fname): with open(fname, "r") as inp: - seqs = json.load(inp) + seqs = json.loads(strip_cstyle_comments(inp)) return list(seqs.items()) # Format of the sequences file is determined by its extension