json: nit fixes

This commit is contained in:
ochafik 2024-03-12 04:26:47 +00:00
parent 6165c55d3a
commit bed826fa56
6 changed files with 8 additions and 8 deletions

View file

@ -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 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 $@
# $(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) # $(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
train.o: common/train.cpp common/train.h train.o: common/train.cpp common/train.h

View file

@ -461,7 +461,7 @@ class SchemaConverter:
rule += ' )' rule += ' )'
rule += ' )?' rule += ' )?'
rule += ' "}" space ' rule += ' "}" space'
return rule return rule

View file

@ -6,7 +6,7 @@ add_executable(${TARGET}
server.cpp server.cpp
utils.hpp utils.hpp
json.hpp json.hpp
httplib.h httplib.h
json-schema-to-grammar.cpp json-schema-to-grammar.cpp
json-schema-to-grammar.h json-schema-to-grammar.h
) )

View file

@ -445,7 +445,7 @@ private:
rule += " )?"; rule += " )?";
} }
rule += " \"}\" space "; rule += " \"}\" space";
return rule; return rule;
} }

View file

@ -489,7 +489,7 @@ export class SchemaConverter {
rule += ' )?'; rule += ' )?';
} }
rule += ' "}" space '; rule += ' "}" space';
return rule; return rule;
} }

View file

@ -57,14 +57,14 @@ struct TestCase {
static void run_py(const TestCase& tc) { static void run_py(const TestCase& tc) {
cerr << "# Running Python " << tc.name.c_str() << endl; cerr << "# Running Python " << tc.name.c_str() << endl;
tc.prepare(); 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"); tc.read_and_verify("Python");
} }
static void run_mjs(const TestCase& tc) { static void run_mjs(const TestCase& tc) {
cerr << "# Running MJS " << tc.name.c_str() << endl; cerr << "# Running MJS " << tc.name.c_str() << endl;
tc.prepare(); 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"); tc.read_and_verify("JavaScript");
} }
@ -290,7 +290,7 @@ int main() {
e-additionalProperties-value-item ::= "[" space string "," space number "]" space e-additionalProperties-value-item ::= "[" space string "," space number "]" space
e-kv ::= "\"e\"" space ":" space e e-kv ::= "\"e\"" space ":" space e
number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? space 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 ::= " "? space ::= " "?
string ::= "\"" ( string ::= "\"" (
[^"\\] | [^"\\] |