From bed826fa565de48e77268d0140db1b65d4389ff1 Mon Sep 17 00:00:00 2001 From: ochafik Date: Tue, 12 Mar 2024 04:26:47 +0000 Subject: [PATCH] json: nit fixes --- Makefile | 2 +- examples/json-schema-to-grammar.py | 2 +- examples/server/CMakeLists.txt | 2 +- examples/server/json-schema-to-grammar.cpp | 2 +- examples/server/public/json-schema-to-grammar.mjs | 2 +- tests/test-json-schema-to-grammar.cpp | 6 +++--- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index f828f6583..c9ec08564 100644 --- a/Makefile +++ b/Makefile @@ -656,7 +656,7 @@ grammar-parser.o: common/grammar-parser.cpp common/grammar-parser.h json-schema-to-grammar.o: examples/server/json-schema-to-grammar.cpp examples/server/json-schema-to-grammar.h $(CXX) $(CXXFLAGS) -c $< -o $@ - # $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) -DLLAMA_BUILD_JSON_SCHEMA_CONVERTER=1 + # $(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<) -DLLAMA_BUILD_JSON_SCHEMA_CONVERTER=1 # $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS) train.o: common/train.cpp common/train.h diff --git a/examples/json-schema-to-grammar.py b/examples/json-schema-to-grammar.py index cda083721..0c9b54754 100755 --- a/examples/json-schema-to-grammar.py +++ b/examples/json-schema-to-grammar.py @@ -461,7 +461,7 @@ class SchemaConverter: rule += ' )' rule += ' )?' - rule += ' "}" space ' + rule += ' "}" space' return rule diff --git a/examples/server/CMakeLists.txt b/examples/server/CMakeLists.txt index 1d42790b8..12afac3a5 100644 --- a/examples/server/CMakeLists.txt +++ b/examples/server/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable(${TARGET} server.cpp utils.hpp json.hpp - httplib.h + httplib.h json-schema-to-grammar.cpp json-schema-to-grammar.h ) diff --git a/examples/server/json-schema-to-grammar.cpp b/examples/server/json-schema-to-grammar.cpp index d0f37916c..919e26c35 100644 --- a/examples/server/json-schema-to-grammar.cpp +++ b/examples/server/json-schema-to-grammar.cpp @@ -445,7 +445,7 @@ private: rule += " )?"; } - rule += " \"}\" space "; + rule += " \"}\" space"; return rule; } diff --git a/examples/server/public/json-schema-to-grammar.mjs b/examples/server/public/json-schema-to-grammar.mjs index eea837dc8..4f921b688 100644 --- a/examples/server/public/json-schema-to-grammar.mjs +++ b/examples/server/public/json-schema-to-grammar.mjs @@ -489,7 +489,7 @@ export class SchemaConverter { rule += ' )?'; } - rule += ' "}" space '; + rule += ' "}" space'; return rule; } diff --git a/tests/test-json-schema-to-grammar.cpp b/tests/test-json-schema-to-grammar.cpp index ab8cde5bd..882ae0954 100755 --- a/tests/test-json-schema-to-grammar.cpp +++ b/tests/test-json-schema-to-grammar.cpp @@ -57,14 +57,14 @@ struct TestCase { static void run_py(const TestCase& tc) { cerr << "# Running Python " << tc.name.c_str() << endl; tc.prepare(); - std::system(("python ./examples/json-schema-to-grammar.py " + INPUT_NAME + " > " + OUT_NAME).c_str()); + assert(std::system(("python ./examples/json-schema-to-grammar.py " + INPUT_NAME + " > " + OUT_NAME).c_str()) == 0); tc.read_and_verify("Python"); } static void run_mjs(const TestCase& tc) { cerr << "# Running MJS " << tc.name.c_str() << endl; tc.prepare(); - std::system(("node ./tests/run-json-schema-to-grammar.mjs " + INPUT_NAME + " > " + OUT_NAME).c_str()); + assert(std::system(("node ./tests/run-json-schema-to-grammar.mjs " + INPUT_NAME + " > " + OUT_NAME).c_str()) == 0); tc.read_and_verify("JavaScript"); } @@ -290,7 +290,7 @@ int main() { e-additionalProperties-value-item ::= "[" space string "," space number "]" space e-kv ::= "\"e\"" space ":" space e number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? space - root ::= "{" space a-kv "," space b-kv ( "," space ( c-kv c-rest | d-kv d-rest | e-kv ) )? "}" space + root ::= "{" space a-kv "," space b-kv ( "," space ( c-kv c-rest | d-kv d-rest | e-kv ) )? "}" space space ::= " "? string ::= "\"" ( [^"\\] |