Skip to content

Commit

Permalink
🐛 : allow trailing coma in arrays
Browse files Browse the repository at this point in the history
also corrects object field rule, for allowing object fields to be
expressions
  • Loading branch information
juwit committed Nov 15, 2019
1 parent 7b97a5d commit a02dae8
Show file tree
Hide file tree
Showing 3 changed files with 1,835 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/antlr4/io/codeka/gaia/hcl/antlr/hcl.g4
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ variableType

type
: TYPE
| 'list'
| 'list(' type ')'
| 'map(' type ')'
| 'object' '(' object ')'
Expand All @@ -53,7 +54,7 @@ object
| '{' field+ '}'
;

field: IDENTIFIER '=' type;
field: IDENTIFIER '=' expression;

variableDescription
: 'description' '=' STRING
Expand Down Expand Up @@ -86,7 +87,7 @@ complexExpression

array
: '[' ']'
| '[' expression ( ',' expression )* ']'
| '[' expression ( ',' expression )* ','? ']'
;

index
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/io/codeka/gaia/hcl/HCLParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ void parsing_variables_shouldWork_withComplexFile() throws IOException {
assertThat(variables).hasSize(49);
}

@Test
void parsing_variables_shouldWork_withAnotherComplexFile() throws IOException {
// given
var fileContent = IOUtils.toString(new ClassPathResource("hcl/variables_aws_vpc.tf").getURL(), Charset.defaultCharset());

// when
var variables = hclParser.parseVariables(fileContent);

// then
assertThat(variables).hasSize(282);
}

@Test
void parsing_outputs_shouldWorkWithVisitor() throws IOException {
// given
Expand Down
Loading

0 comments on commit a02dae8

Please sign in to comment.