virtuald/pyhcl

Multiple ply.lex warnings when you load HCL

Closed this issue · 2 comments

This started in pyhcl 0.3.0 and is also present in pyhcl 0.3.1. I get a long list of warnings when I run hcl.loads()

I believe it's related to the implementation of the parser using ply. The source code of ply.lex refers to the error at these points: https://github.com/dabeaz/ply/blob/master/ply/lex.py#L1010-L1012

WARNING: No error rule is defined for exclusive state 'stringdollar'
WARNING: No ignore rule is defined for exclusive state 'stringdollar'
WARNING: No error rule is defined for exclusive state 'heredoc'
WARNING: No ignore rule is defined for exclusive state 'heredoc'
WARNING: No error rule is defined for exclusive state 'string'
WARNING: No ignore rule is defined for exclusive state 'string'
WARNING: No error rule is defined for exclusive state 'stringdollar'
WARNING: No ignore rule is defined for exclusive state 'stringdollar'
WARNING: No error rule is defined for exclusive state 'heredoc'
WARNING: No ignore rule is defined for exclusive state 'heredoc'
WARNING: No error rule is defined for exclusive state 'string'

This is the HCL that I'm loading

resource "aws_db_instance" "foo" {
  storage_encrypted = "True"
  tags {
    Platform = "${var.platform}"
    Name = "foo"
    Owner = "bar"
  }
}

resource "aws_instance" "foo" {
  ebs_block_device {
    encrypted = "True"
  }

  tags {
    Platform = "${var.platform}"
    Name = "bar"
    Owner = "bar"
  }

}

@scottbelden any ideas?

I noticed this as well and have been meaning to make a PR. It can be solved by changing https://github.com/virtuald/pyhcl/blob/master/src/hcl/lexer.py#L222 from:

self.lex = lex.lex(module=self, debug=False, reflags=(re.UNICODE | re.MULTILINE))

to:

self.lex = lex.lex(module=self, debug=False, reflags=(re.UNICODE | re.MULTILINE), errorlog=lex.NullLogger())

I'm not sure if there are any other side effects but I agree that the warnings are annoying.