diff --git a/common/json-schema-to-grammar.cpp b/common/json-schema-to-grammar.cpp index cca69cf5b..b718851c2 100644 --- a/common/json-schema-to-grammar.cpp +++ b/common/json-schema-to-grammar.cpp @@ -125,7 +125,7 @@ static std::string replacePattern(const std::string& input, const regex& regex, return result; } -static string _format_literal(const string& literal) { +static string format_literal(const string& literal) { string escaped = replacePattern(json(literal).dump(), GRAMMAR_LITERAL_ESCAPE_RE, [&](const smatch& match) { char c = match.str()[0]; return GRAMMAR_LITERAL_ESCAPES.at(c); @@ -133,13 +133,6 @@ static string _format_literal(const string& literal) { return "\"" + escaped + "\""; } -static string _format_range_char(const string& ch) { - return replacePattern(ch, GRAMMAR_RANGE_LITERAL_ESCAPE_RE, [&](const smatch& match) { - char c = match.str()[0]; - return GRAMMAR_LITERAL_ESCAPES.at(c); - }); -} - class SchemaConverter { private: @@ -422,7 +415,7 @@ private: string prop_rule_name = visit(prop_schema, name + (name.empty() ? "" : "-") + prop_name); prop_kv_rule_names[prop_name] = _add_rule( name + (name.empty() ? "" : "-") + prop_name + "-kv", - _format_literal(prop_name) + " space \":\" space " + prop_rule_name + format_literal(prop_name) + " space \":\" space " + prop_rule_name ); if (required.find(prop_name) != required.end()) { required_props.push_back(prop_name); @@ -570,7 +563,7 @@ public: _errors.push_back("Only string constants are supported, got " + value.dump()); return ""; } - return _format_literal(value.get()); + return format_literal(value.get()); } string visit(const json& schema, const string& name) { diff --git a/examples/json-schema-to-grammar.py b/examples/json-schema-to-grammar.py index bf4ead215..9eead557f 100755 --- a/examples/json-schema-to-grammar.py +++ b/examples/json-schema-to-grammar.py @@ -65,11 +65,6 @@ class SchemaConverter: ) return f'"{escaped}"' - def _format_range_char(self, literal): - return GRAMMAR_RANGE_LITERAL_ESCAPE_RE.sub( - lambda m: GRAMMAR_LITERAL_ESCAPES.get(m.group(0)), json.dumps(literal)[1:-1] - ) - def _add_rule(self, name, rule): esc_name = INVALID_RULE_CHARS_RE.sub('-', name) if esc_name not in self._rules or self._rules[esc_name] == rule: