fix _not_strings for substring overlaps
This commit is contained in:
parent
02e26344ab
commit
0e48ea8ec2
4 changed files with 93 additions and 12 deletions
|
@ -429,12 +429,12 @@ private:
|
||||||
out << " | ";
|
out << " | ";
|
||||||
}
|
}
|
||||||
out << "[" << kv.first << "]";
|
out << "[" << kv.first << "]";
|
||||||
if (kv.second.is_end_of_string) {
|
if (!kv.second.children.empty()) {
|
||||||
out << " " << char_rule << "+";
|
|
||||||
} else {
|
|
||||||
out << " (";
|
out << " (";
|
||||||
visit(kv.second);
|
visit(kv.second);
|
||||||
out << ")";
|
out << ")";
|
||||||
|
} else if (kv.second.is_end_of_string) {
|
||||||
|
out << " " << char_rule << "+";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!node.children.empty()) {
|
if (!node.children.empty()) {
|
||||||
|
@ -446,7 +446,11 @@ private:
|
||||||
};
|
};
|
||||||
visit(trie);
|
visit(trie);
|
||||||
|
|
||||||
out << " )? [\"] space";
|
out << " )";
|
||||||
|
if (!trie.is_end_of_string) {
|
||||||
|
out << "?";
|
||||||
|
}
|
||||||
|
out << " [\"] space";
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,12 +142,12 @@ class SchemaConverter:
|
||||||
else:
|
else:
|
||||||
out.append(' | ')
|
out.append(' | ')
|
||||||
out.append(f'[{c}]')
|
out.append(f'[{c}]')
|
||||||
if (child.is_end_of_string):
|
if child.children:
|
||||||
out.append(f' {char_rule}+')
|
|
||||||
else:
|
|
||||||
out.append(f' (')
|
out.append(f' (')
|
||||||
visit(child)
|
visit(child)
|
||||||
out.append(')')
|
out.append(')')
|
||||||
|
elif child.is_end_of_string:
|
||||||
|
out.append(f' {char_rule}+')
|
||||||
if node.children:
|
if node.children:
|
||||||
if not first:
|
if not first:
|
||||||
out.append(' | ')
|
out.append(' | ')
|
||||||
|
|
|
@ -367,18 +367,19 @@ export class SchemaConverter {
|
||||||
for (const c of Object.keys(node.children).sort()) {
|
for (const c of Object.keys(node.children).sort()) {
|
||||||
const child = node.children[c];
|
const child = node.children[c];
|
||||||
rejects.push(c);
|
rejects.push(c);
|
||||||
if (!first) {
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
out.push(' | ');
|
out.push(' | ');
|
||||||
}
|
}
|
||||||
out.push(`[${c}]`);
|
out.push(`[${c}]`);
|
||||||
if (child.isEndOfString) {
|
if (Object.keys(child.children).length > 0) {
|
||||||
out.push(` ${charRuleName}+`);
|
|
||||||
} else {
|
|
||||||
out.push(' (');
|
out.push(' (');
|
||||||
visit(child);
|
visit(child);
|
||||||
out.push(')');
|
out.push(')');
|
||||||
|
} else if (child.isEndOfString) {
|
||||||
|
out.push(` ${charRuleName}+`);
|
||||||
}
|
}
|
||||||
first = false;
|
|
||||||
}
|
}
|
||||||
if (Object.keys(node.children).length > 0) {
|
if (Object.keys(node.children).length > 0) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
|
|
|
@ -697,6 +697,82 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
|
||||||
)"""
|
)"""
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test({
|
||||||
|
SUCCESS,
|
||||||
|
"optional props with empty name",
|
||||||
|
R"""({
|
||||||
|
"properties": {
|
||||||
|
"": {"type": "integer"},
|
||||||
|
"a": {"type": "integer"}
|
||||||
|
},
|
||||||
|
"additionalProperties": {"type": "integer"}
|
||||||
|
})""",
|
||||||
|
R"""(
|
||||||
|
-kv ::= "\"\"" space ":" space root
|
||||||
|
-rest ::= ( "," space a-kv )? a-rest
|
||||||
|
a-kv ::= "\"a\"" space ":" space integer
|
||||||
|
a-rest ::= ( "," space additional-kv )*
|
||||||
|
additional-k ::= ["] ( [a] char+ | [^"a] char* ) ["] space
|
||||||
|
additional-kv ::= additional-k ":" space integer
|
||||||
|
char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
|
||||||
|
integer ::= ("-"? integral-part) space
|
||||||
|
integral-part ::= [0] | [1-9] [0-9]{0,15}
|
||||||
|
root ::= ("-"? integral-part) space
|
||||||
|
root0 ::= "{" space (-kv -rest | a-kv a-rest | additional-kv ( "," space additional-kv )* )? "}" space
|
||||||
|
space ::= | " " | "\n" [ \t]{0,20}
|
||||||
|
)"""
|
||||||
|
});
|
||||||
|
|
||||||
|
test({
|
||||||
|
SUCCESS,
|
||||||
|
"optional props with nested names",
|
||||||
|
R"""({
|
||||||
|
"properties": {
|
||||||
|
"a": {"type": "integer"},
|
||||||
|
"aa": {"type": "integer"}
|
||||||
|
},
|
||||||
|
"additionalProperties": {"type": "integer"}
|
||||||
|
})""",
|
||||||
|
R"""(
|
||||||
|
a-kv ::= "\"a\"" space ":" space integer
|
||||||
|
a-rest ::= ( "," space aa-kv )? aa-rest
|
||||||
|
aa-kv ::= "\"aa\"" space ":" space integer
|
||||||
|
aa-rest ::= ( "," space additional-kv )*
|
||||||
|
additional-k ::= ["] ( [a] ([a] char+ | [^"a] char*) | [^"a] char* )? ["] space
|
||||||
|
additional-kv ::= additional-k ":" space integer
|
||||||
|
char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
|
||||||
|
integer ::= ("-"? integral-part) space
|
||||||
|
integral-part ::= [0] | [1-9] [0-9]{0,15}
|
||||||
|
root ::= "{" space (a-kv a-rest | aa-kv aa-rest | additional-kv ( "," space additional-kv )* )? "}" space
|
||||||
|
space ::= | " " | "\n" [ \t]{0,20}
|
||||||
|
)"""
|
||||||
|
});
|
||||||
|
|
||||||
|
test({
|
||||||
|
SUCCESS,
|
||||||
|
"optional props with common prefix",
|
||||||
|
R"""({
|
||||||
|
"properties": {
|
||||||
|
"ab": {"type": "integer"},
|
||||||
|
"ac": {"type": "integer"}
|
||||||
|
},
|
||||||
|
"additionalProperties": {"type": "integer"}
|
||||||
|
})""",
|
||||||
|
R"""(
|
||||||
|
ab-kv ::= "\"ab\"" space ":" space integer
|
||||||
|
ab-rest ::= ( "," space ac-kv )? ac-rest
|
||||||
|
ac-kv ::= "\"ac\"" space ":" space integer
|
||||||
|
ac-rest ::= ( "," space additional-kv )*
|
||||||
|
additional-k ::= ["] ( [a] ([b] char+ | [c] char+ | [^"bc] char*) | [^"a] char* )? ["] space
|
||||||
|
additional-kv ::= additional-k ":" space integer
|
||||||
|
char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
|
||||||
|
integer ::= ("-"? integral-part) space
|
||||||
|
integral-part ::= [0] | [1-9] [0-9]{0,15}
|
||||||
|
root ::= "{" space (ab-kv ab-rest | ac-kv ac-rest | additional-kv ( "," space additional-kv )* )? "}" space
|
||||||
|
space ::= | " " | "\n" [ \t]{0,20}
|
||||||
|
)"""
|
||||||
|
});
|
||||||
|
|
||||||
test({
|
test({
|
||||||
SUCCESS,
|
SUCCESS,
|
||||||
"top-level $ref",
|
"top-level $ref",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue