...
 
Commits (3)
......@@ -28,7 +28,10 @@ class Parser:
return schema
def eat_whitespace(self):
self.get_token(r'(?m)\s*(--[^\r\n]*$)?\s*')
while True:
m = self.get_token(r'(?m)\s*(--[^\r\n]*$)?\s*')
if len(m.group(0)) == 0:
break
def parse_object(self, x):
x.add_type("object")
......@@ -38,9 +41,16 @@ class Parser:
if self.get_token("\}"):
return
name = None
m = self.get_token(r'([-A-Za-z_0-9]+|\/[^\/]+\/)')
if m is not None:
name = m.group(1)
else:
m = self.get_token(r'"((?:[^"\\]|\\.)+)"')
if m is not None:
name = re.sub(r'\\(.)', lambda x: x.group(1), m.group(1))
if name is not None:
c = SchemaComponent()
x.add_property(name, c)
......@@ -56,11 +66,13 @@ class Parser:
self.eat_whitespace()
if self.get_token(':'):
while True:
self.eat_whitespace()
if self.get_token('\$'):
m = self.get_token('\$\(([-a-z]+)\)')
if m is not None:
c.add_type(m.group(1));
elif self.get_token('\$'):
c.add_type("string");
elif self.get_token('\#'):
c.add_type("number");
......
......@@ -226,6 +226,7 @@ def test_short_schema():
{
nullThing?:~, -- nullable
booleanThing?:B, -- boolean
-- emailThing?:$(email)
}
""",
"output": {
......@@ -236,7 +237,10 @@ def test_short_schema():
},
"booleanThing": {
"type": "boolean",
}
},
# "emailThing": {
# "type": "email",
# }
},
"additionalProperties": False
},
......@@ -248,6 +252,36 @@ def test_short_schema():
{ "nullThing": False, "booleanThing": None },
]
},
# Name quoting
{
"input": """
{
"this is a key":$,
"this is a \\"key\\""?:$
}
""",
"output": {
"type": "object",
"properties": {
"this is a key": {
"type": "string",
},
"this is a \"key\"": {
"type": "string",
},
},
"required": [ "this is a key" ],
"additionalProperties": False
},
"valid_instances": [
{ "this is a key": "bas" },
{ "this is a key": "bas", 'this is a "key"': "blort" },
],
"invalid_instances": [
{},
]
},
]
for t in tests:
......