Skip to content
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.3.13 (2019-06-25)
------------------
* Updated for terraform v0.12 syntax

0.2.1 (2016-04-14)
------------------
* Fixes for mutliple configuration blocks with same name
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ The grammar and many of the tests/fixtures were copied/ported from the
golang parser into pyhcl. All releases are tested with a variety of
python versions from Python 2.7 onward.

This version has been modified to work with terraform 0.12 syntax.
It should be backward compatible with earlier versions.
It doesn't cover every situation. See discussion in pull request:
https://github.com/virtuald/pyhcl/pull/57

Installation
============

Expand Down
63 changes: 59 additions & 4 deletions src/hcl/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,28 @@ class Lexer(object):
'IDENTIFIER',
'EQUAL',
'STRING',
'ADD',
'MINUS',
'MULTIPLY',
'DIVIDE',
'LEFTBRACE',
'RIGHTBRACE',
'LEFTBRACKET',
'RIGHTBRACKET',
'PERIOD',
'EPLUS',
'EMINUS',
'LEFTPAREN',
'RIGHTPAREN',
'QMARK',
'COLON',
'ASTERISK_PERIOD',
'GT',
'LT',
'EQ',
'NE',
'LE',
'GE',
)

states = (
Expand All @@ -63,7 +77,7 @@ def t_EMINUS(self, t):
return t

def t_EPLUS(self, t):
r'(?<=\d|\.)[eE]\+?'
r'(?<=\d)[eE]\+?|(?<=\d\.)[eE]\+?'
return t

def t_FLOAT(self, t):
Expand Down Expand Up @@ -91,6 +105,42 @@ def t_COMMA(self, t):
r','
return t

def t_QMARK(self, t):
r'\?'
return t

def t_COLON(self, t):
r':'
return t

def t_ASTERISK_PERIOD(self, t):
r'\*\.'
return t

def t_GT(self, t):
r'(?<!>)>(?!>|=)'
return t

def t_LT(self, t):
r'(?<!<)<(?!<|=)'
return t

def t_EQ(self, t):
r'=='
return t

def t_NE(self, t):
r'!='
return t

def t_LE(self, t):
r'<='
return t

def t_GE(self, t):
r'>='
return t

def t_IDENTIFIER(self, t):
r'[^\W\d][\w.-]*'
t.value = text_type(t.value)
Expand Down Expand Up @@ -259,13 +309,12 @@ def t_heredoc_eof(self, t):
t_tabbedheredoc_ignoring = t_heredoc_ignoring
t_tabbedheredoc_eof = t_heredoc_eof

t_EQUAL = r'='
t_MINUS = r'-'

t_LEFTBRACE = r'\{'
t_RIGHTBRACE = r'\}'
t_LEFTBRACKET = r'\['
t_RIGHTBRACKET = r'\]'
t_LEFTPAREN = r'\('
t_RIGHTPAREN = r'\)'

def t_COMMENT(self, t):
r'(\#|(//)).*'
Expand All @@ -283,6 +332,12 @@ def t_newline(self, t):

t_ignore = ' \t\r\f\v'

t_EQUAL = r'(?<!=)=(?!=)'
t_ADD = r'\+'
t_MINUS = r'-'
t_MULTIPLY = r'\*'
t_DIVIDE = r'/'

# Error handling rule
def t_error(self, t):
if t.value.startswith('/*'):
Expand Down
Loading