Skip to content

Commit

Permalink
Merge pull request #1 from deaz/sequence-dictionary-whitespaces
Browse files Browse the repository at this point in the history
Add support for whitespaces in sequence and dictionary declarations
  • Loading branch information
aikoven authored Jan 16, 2018
2 parents d616eb9 + 1736d0d commit ab59da9
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 9 deletions.
11 changes: 11 additions & 0 deletions fixtures/dictionary.ice
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

module A {
struct Struct {};

dictionary <string, Struct> StructMap;
dictionary
<string, Struct> StructMap2;
dictionary <string, Struct> StructMap3; // there is a tab between `dictionary` and `<`
dictionary<string, Struct> StructMap4;
};
11 changes: 11 additions & 0 deletions fixtures/sequence.ice
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

module A {
struct Struct {};

sequence <Struct> StructSeq;
sequence
<Struct> StructSeq2;
sequence <Struct> StructSeq3; // there is a tab between `sequence` and `<`
sequence<Struct> StructSeq4;
};
120 changes: 120 additions & 0 deletions src/__snapshots__/slice.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19502,6 +19502,68 @@ Object {
}
`;

exports[`Slices dictionary.ice 1`] = `
Object {
"globalMetadata": undefined,
"includes": undefined,
"modules": Array [
Object {
"content": Array [
Object {
"doc": undefined,
"fields": Array [],
"local": undefined,
"metadata": undefined,
"name": "Struct",
"type": "struct",
},
Object {
"doc": undefined,
"keyType": "string",
"local": undefined,
"metadata": undefined,
"name": "StructMap",
"type": "dictionary",
"valueType": "Struct",
},
Object {
"doc": undefined,
"keyType": "string",
"local": undefined,
"metadata": undefined,
"name": "StructMap2",
"type": "dictionary",
"valueType": "Struct",
},
Object {
"doc": undefined,
"keyType": "string",
"local": undefined,
"metadata": undefined,
"name": "StructMap3",
"type": "dictionary",
"valueType": "Struct",
},
Object {
"doc": undefined,
"keyType": "string",
"local": undefined,
"metadata": undefined,
"name": "StructMap4",
"type": "dictionary",
"valueType": "Struct",
},
],
"doc": undefined,
"metadata": undefined,
"name": "A",
"type": "module",
},
],
"pragmaOnce": true,
}
`;

exports[`Slices optional-return-type.ice 1`] = `
Object {
"globalMetadata": undefined,
Expand Down Expand Up @@ -19540,3 +19602,61 @@ Object {
"pragmaOnce": true,
}
`;

exports[`Slices sequence.ice 1`] = `
Object {
"globalMetadata": undefined,
"includes": undefined,
"modules": Array [
Object {
"content": Array [
Object {
"doc": undefined,
"fields": Array [],
"local": undefined,
"metadata": undefined,
"name": "Struct",
"type": "struct",
},
Object {
"dataType": "Struct",
"doc": undefined,
"local": undefined,
"metadata": undefined,
"name": "StructSeq",
"type": "sequence",
},
Object {
"dataType": "Struct",
"doc": undefined,
"local": undefined,
"metadata": undefined,
"name": "StructSeq2",
"type": "sequence",
},
Object {
"dataType": "Struct",
"doc": undefined,
"local": undefined,
"metadata": undefined,
"name": "StructSeq3",
"type": "sequence",
},
Object {
"dataType": "Struct",
"doc": undefined,
"local": undefined,
"metadata": undefined,
"name": "StructSeq4",
"type": "sequence",
},
],
"doc": undefined,
"metadata": undefined,
"name": "A",
"type": "module",
},
],
"pragmaOnce": true,
}
`;
6 changes: 3 additions & 3 deletions src/slice.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Slice {
EnumElement = identifier EnumValue?
EnumValue = "=" (decimalIntegerLiteral | typeId)

SequenceDeclaration = Metadata? localModifier? "sequence<" dataType ">" identifier ";"
SequenceDeclaration = Metadata? localModifier? "sequence" "<" dataType ">" identifier ";"

DictionaryDeclaration = Metadata? localModifier? "dictionary<" dataType "," dataType ">" identifier ";"
DictionaryDeclaration = Metadata? localModifier? "dictionary" "<" dataType "," dataType ">" identifier ";"

ConstDeclaration = "const" dataType identifier DefaultValue ";"

Expand Down Expand Up @@ -155,4 +155,4 @@ Slice {
| "exception" | "local" | "short"

primitiveType = "bool" | "string" | "byte" | "int" | "long" | "float" | "double" | "short"
}
}
14 changes: 8 additions & 6 deletions src/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,11 @@ const sliceSemantics = sliceGrammar.createSemantics().addOperation('toJson', {
metadataNode,
localModifierNode,
t1,
dataTypeNode,
t2,
identifierNode,
dataTypeNode,
t3,
identifierNode,
t4,
): types.SequenceDeclaration {
const [metadata] = metadataNode.toJson();
const [local] = localModifierNode.toJson();
Expand All @@ -350,12 +351,13 @@ const sliceSemantics = sliceGrammar.createSemantics().addOperation('toJson', {
metadataNode,
localModifierNode,
t1,
keyTypeNode,
t2,
valueTypeNode,
keyTypeNode,
t3,
identifierNode,
valueTypeNode,
t4,
identifierNode,
t5,
): types.DictionaryDeclaration {
const [metadata] = metadataNode.toJson();
const [local] = localModifierNode.toJson();
Expand Down Expand Up @@ -494,4 +496,4 @@ export function parse(source: string): types.SliceSource {
}

return sliceSemantics(res).toJson();
}
}

0 comments on commit ab59da9

Please sign in to comment.