forked from extern/Unexpected-Keyboard
compose: Allow c-style comments in json files
Useful to manager growing the collection of sequences.
This commit is contained in:
parent
c57ae83bfa
commit
e734d1d0e2
@ -90,10 +90,17 @@ def parse_sequences_file_xkb(fname, xkb_char_extra_names):
|
|||||||
seqs.append(s)
|
seqs.append(s)
|
||||||
return seqs
|
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.
|
# Parse from a json file containing a dictionary sequence → result string.
|
||||||
def parse_sequences_file_json(fname):
|
def parse_sequences_file_json(fname):
|
||||||
with open(fname, "r") as inp:
|
with open(fname, "r") as inp:
|
||||||
seqs = json.load(inp)
|
seqs = json.loads(strip_cstyle_comments(inp))
|
||||||
return list(seqs.items())
|
return list(seqs.items())
|
||||||
|
|
||||||
# Format of the sequences file is determined by its extension
|
# Format of the sequences file is determined by its extension
|
||||||
|
Loading…
Reference in New Issue
Block a user