Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiline conditionals #51

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## \[2.0.1] - 2020-12-24

### Changed
- Allow multiline conditional statements. Thanks @stpierre ([#51](https://github.com/amplify-education/python-hcl2/pull/51))

## \[2.0.0] - 2020-11-02

### Changed
Expand Down
2 changes: 1 addition & 1 deletion hcl2/hcl2.lark
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ identifier : /[a-zA-Z_][a-zA-Z0-9_-]*/

?expression : expr_term | operation | conditional

conditional : expression "?" expression ":" expression
conditional : expression "?" new_line_or_comment? expression new_line_or_comment? ":" new_line_or_comment? expression

?operation : unary_op | binary_op
!unary_op : ("-" | "!") expr_term
Expand Down
1 change: 1 addition & 0 deletions hcl2/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def attribute(self, args: List) -> Dict:
}

def conditional(self, args: List) -> str:
args = self.strip_new_line_tokens(args)
return "%s ? %s : %s" % (args[0], args[1], args[2])

def binary_op(self, args: List) -> str:
Expand Down
2 changes: 1 addition & 1 deletion hcl2/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Place of record for the package version"""

__version__ = "2.0.0"
__version__ = "2.0.1"
7 changes: 6 additions & 1 deletion test/helpers/terraform-config/route_table.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
resource "aws_route" "tgw" {
count = var.tgw_name == "" ? 0 : var.number_of_az
count = (
var.tgw_name == "" ?
0 :
var.number_of_az
)

route_table_id = aws_route_table.rt[count.index].id
destination_cidr_block = "10.0.0.0/8"
transit_gateway_id = data.aws_ec2_transit_gateway.tgw[0].id
Expand Down