diff --git a/packages/openstep.parse/__tests__/index.test.ts b/packages/openstep.parse/__tests__/index.test.ts index 6e37bb1..56a7ae1 100644 --- a/packages/openstep.parse/__tests__/index.test.ts +++ b/packages/openstep.parse/__tests__/index.test.ts @@ -52,6 +52,17 @@ describe('openstep:parse', () => { }); describe('array', () => { + it('parses empty arrays', () => { + expect(parse('()')).toStrictEqual([]); + expect( + parse(` +{ + classes = ( + ); +}`) + ).toStrictEqual({ classes: [] }); + }); + it('parses string arrays', () => { expect(parse('("a", "b", "c")')).toStrictEqual(['a', 'b', 'c']); expect(parse('(a, b, c)')).toStrictEqual(['a', 'b', 'c']); @@ -62,6 +73,13 @@ describe('openstep:parse', () => { describe('dict', () => { it('parses empty dicts', () => { expect(parse('{}')).toStrictEqual({}); + expect( + parse(` +{ + classes = { + }; +}`) + ).toStrictEqual({ classes: {} }); }); it('parses dicts', () => { diff --git a/packages/openstep.parse/src/index.ts b/packages/openstep.parse/src/index.ts index 7f1b2a9..c7914f8 100644 --- a/packages/openstep.parse/src/index.ts +++ b/packages/openstep.parse/src/index.ts @@ -87,6 +87,12 @@ const consumeValue = (input: string): [Value, string] => { case '{': result = {}; + [, input] = consumeWhitespaceAndComments(input); + if (input.charAt(0) === '}') { + [, input] = consumeToken(input, '}'); + break; + } + while (input.charAt(0) !== '}') { let key: Value, value: Value; [key, input] = consumeValue(input); @@ -113,6 +119,12 @@ const consumeValue = (input: string): [Value, string] => { case '(': result = []; + [, input] = consumeWhitespaceAndComments(input); + if (input.charAt(0) === ')') { + [, input] = consumeToken(input, ')'); + break; + } + while (input.charAt(0) !== ')') { let value: Value, token: string | null; [value, input] = consumeValue(input); @@ -131,9 +143,14 @@ const consumeValue = (input: string): [Value, string] => { [, input] = consumeToken(input, ')'); break; case '<': - let array = new Uint8Array(); let hexString = ''; + [, input] = consumeWhitespaceAndComments(input); + if (input.charAt(0) === '>') { + [, input] = consumeToken(input, '>'); + break; + } + while (input.charAt(0) !== '>') { const digit = input.charAt(0); input = input.substr(1);