From a381deb1b6be0739acbebe10ea963d007a8cbc69 Mon Sep 17 00:00:00 2001 From: ochafik Date: Wed, 1 May 2024 02:23:18 +0100 Subject: [PATCH] json: fix missing paren min/max bug --- common/json-schema-to-grammar.cpp | 2 ++ tests/test-json-schema-to-grammar.cpp | 40 ++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/common/json-schema-to-grammar.cpp b/common/json-schema-to-grammar.cpp index cdc44e0fb..ec0ebe2bd 100644 --- a/common/json-schema-to-grammar.cpp +++ b/common/json-schema-to-grammar.cpp @@ -214,6 +214,7 @@ static void _generate_min_max_int(int min_value, int max_value, std::stringstrea more_digits(sub_len, sub_len); } else { out << "[" << from[i] << "] "; + out << "("; uniform_range(from_sub, sub_nines); if (from[i] < to[i] - 1) { out << " | "; @@ -226,6 +227,7 @@ static void _generate_min_max_int(int min_value, int max_value, std::stringstrea out << " "; more_digits(sub_len, sub_len); } + out << ")"; } if (!to_reached) { out << " | "; diff --git a/tests/test-json-schema-to-grammar.cpp b/tests/test-json-schema-to-grammar.cpp index 8a58db1d1..a25cab2ee 100755 --- a/tests/test-json-schema-to-grammar.cpp +++ b/tests/test-json-schema-to-grammar.cpp @@ -233,7 +233,7 @@ static void test_all(const std::string & lang, std::function