Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Commit

Permalink
Made commas optional when declaring enums
Browse files Browse the repository at this point in the history
Related to #461
  • Loading branch information
MathieuAA committed May 12, 2020
1 parent 0504758 commit 17bec2c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/dsl/jdl_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ module.exports = class JDLParser extends CstParser {
this.RULE('enumPropList', () => {
this.SUBRULE(this.enumProp);
this.MANY(() => {
this.CONSUME(LexerTokens.COMMA);
this.OPTION(() => {
this.CONSUME(LexerTokens.COMMA);
});
this.SUBRULE1(this.enumProp);
});
});
Expand Down
67 changes: 67 additions & 0 deletions test/spec/grammar/grammar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,73 @@ entity A {
});
});
context('when parsing enums', () => {
context('with values separated by commas', () => {
let parsedEnum;

before(() => {
const content = parseFromContent(
`enum MyEnum {
FRANCE,
ENGLAND,
ICELAND
}
`
);
parsedEnum = content.enums[0];
});

it('should parse them', () => {
expect(parsedEnum).to.deep.equal({
name: 'MyEnum',
values: [
{
key: 'FRANCE'
},
{
key: 'ENGLAND'
},
{
key: 'ICELAND'
}
]
});
});
});
context('with values separated by whitespaces', () => {
let parsedEnum;

before(() => {
const content = parseFromContent(
`enum MyEnum {
FRANCE ENGLAND("aaa bbb ccc") ICELAND
GERMANY
}
`
);
parsedEnum = content.enums[0];
});

it('should parse them', () => {
expect(parsedEnum).to.deep.equal({
name: 'MyEnum',
values: [
{
key: 'FRANCE'
},
{
key: 'ENGLAND',
value: 'aaa bbb ccc'
},
{
key: 'ICELAND'
},
{
key: 'GERMANY'
}
]
});
});
});
context('without custom values', () => {
let parsedEnum;

Expand Down

0 comments on commit 17bec2c

Please sign in to comment.