Skip to content

Commit 68f4df8

Browse files
committed
Made compatibility with lark 1.0!
Compatibility was broken by lark-parser/lark@6bb9e8a
1 parent df6d2e5 commit 68f4df8

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

.github/workflows/pr_check.yml

-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ jobs:
2121
python-version: ${{ matrix.python-version }}
2222
- name: Install dependencies
2323
run: python -m pip install --upgrade "tox>=4.0.9,<5" build
24-
- name: Generate parser file
25-
run: python hcl2/parser.py
2624
- name: Build to generate the version file
2725
run: python3 -m build
2826
- name: Test with Tox

hcl2/transformer.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from collections import namedtuple
55
from typing import List, Dict, Any
66

7-
from lark import Transformer, Discard
7+
from lark.visitors import Transformer, Discard, _DiscardType
88

99
HEREDOC_PATTERN = re.compile(r'<<([a-zA-Z][a-zA-Z0-9._-]+)\n((.|\n)*?)\n\s*\1', re.S)
1010
HEREDOC_TRIM_PATTERN = re.compile(r'<<-([a-zA-Z][a-zA-Z0-9._-]+)\n((.|\n)*?)\n\s*\1', re.S)
@@ -89,14 +89,14 @@ def function_call(self, args: List) -> str:
8989
args = self.strip_new_line_tokens(args)
9090
args_str = ''
9191
if len(args) > 1:
92-
args_str = ", ".join([str(arg) for arg in args[1]])
92+
args_str = ", ".join([str(arg) for arg in args[1] if arg is not Discard])
9393
return f"{args[0]}({args_str})"
9494

9595
def arguments(self, args: List) -> List:
9696
return args
9797

98-
def new_line_and_or_comma(self, args: List) -> Discard:
99-
return Discard()
98+
def new_line_and_or_comma(self, args: List) -> _DiscardType:
99+
return Discard
100100

101101
def block(self, args: List) -> Dict:
102102
args = self.strip_new_line_tokens(args)
@@ -216,8 +216,8 @@ def heredoc_template_trim(self, args: List) -> str:
216216

217217
return '"%s"' % '\n'.join(lines)
218218

219-
def new_line_or_comment(self, args: List) -> Discard:
220-
return Discard()
219+
def new_line_or_comment(self, args: List) -> _DiscardType:
220+
return Discard
221221

222222
def for_tuple_expr(self, args: List) -> str:
223223
args = self.strip_new_line_tokens(args)
@@ -245,7 +245,7 @@ def strip_new_line_tokens(self, args: List) -> List:
245245
Remove new line and Discard tokens.
246246
The parser will sometimes include these in the tree so we need to strip them out here
247247
"""
248-
return [arg for arg in args if arg != "\n" and not isinstance(arg, Discard)]
248+
return [arg for arg in args if arg != "\n" and arg is not Discard]
249249

250250
def to_string_dollar(self, value: Any) -> Any:
251251
"""Wrap a string in ${ and }"""

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ classifiers = [
2222
"Programming Language :: Python :: 3.10",
2323
]
2424
requires-python = ">=3.7.0"
25-
dependencies = ["lark>=0.10.0,<0.11.0"]
25+
dependencies = ["lark>=1"]
2626
dynamic = ["version"]
2727

2828
[project.readme]

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Place dependencies in this file, following the distutils format:
22
# http://docs.python.org/2/distutils/setupscript.html#relationships-between-distributions-and-packages
3-
lark-parser>=0.11.0,<1.0
3+
lark>=1.1.5,<2.0

0 commit comments

Comments
 (0)