Created
November 29, 2022 13:35
-
-
Save kevinAlbs/86da2e539b43a6ad4720f61d9c925cce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
contents = sys.stdin.read() | |
lines = contents.splitlines () | |
inraw = False | |
rawstr = "" | |
import textwrap | |
print ("""// This is a copy of test vectors from the mongodb/mongo repository.""") | |
for line in lines: | |
match = re.match(r"\{ (.+), (.+), (.+), (.+), (.+), (.+),", line) | |
if match != None: | |
lowerBound = match.group(1) | |
upperBound = match.group(2) | |
min = match.group(3) | |
max = match.group(4) | |
sparsity = match.group(5) | |
precision = match.group(6) | |
match = re.match (r'R"\((.*)', line) | |
if match != None: | |
inraw = True | |
rawstr = '"' + match.group (1) + r'\n" ''\\''\n' | |
elif re.match (r'\)"\},', line) != None: | |
got = textwrap.dedent(""" | |
{{ | |
.lowerBound = {lowerbound}, | |
.includeLowerBound = true, | |
.upperBound = {upperbound}, | |
.includeUpperBound = true, | |
.sparsity = {sparsity}, | |
.min = OPT_DOUBLE({min}), | |
.max = OPT_DOUBLE({max}), | |
.precision = OPT_U32({precision}), | |
.expectMincoverString = {expectMincoverString} | |
}}, | |
""".format( | |
lowerbound=lowerBound, | |
upperbound=upperBound, | |
min=min, | |
max=max, | |
precision=precision, | |
sparsity=sparsity, | |
expectMincoverString=rawstr[0:-2] | |
)) | |
print(got.strip()) | |
inraw = False | |
else: | |
if inraw: | |
rawstr += ' "' + line + r'\n" ''\\''\n' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment