|
4 | 4 | from collections import namedtuple
|
5 | 5 | from typing import List, Dict, Any
|
6 | 6 |
|
7 |
| -from lark import Transformer, Discard |
| 7 | +from lark.visitors import Transformer, Discard, _DiscardType |
8 | 8 |
|
9 | 9 | HEREDOC_PATTERN = re.compile(r'<<([a-zA-Z][a-zA-Z0-9._-]+)\n((.|\n)*?)\n\s*\1', re.S)
|
10 | 10 | 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:
|
89 | 89 | args = self.strip_new_line_tokens(args)
|
90 | 90 | args_str = ''
|
91 | 91 | 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]) |
93 | 93 | return f"{args[0]}({args_str})"
|
94 | 94 |
|
95 | 95 | def arguments(self, args: List) -> List:
|
96 | 96 | return args
|
97 | 97 |
|
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 |
100 | 100 |
|
101 | 101 | def block(self, args: List) -> Dict:
|
102 | 102 | args = self.strip_new_line_tokens(args)
|
@@ -216,8 +216,8 @@ def heredoc_template_trim(self, args: List) -> str:
|
216 | 216 |
|
217 | 217 | return '"%s"' % '\n'.join(lines)
|
218 | 218 |
|
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 |
221 | 221 |
|
222 | 222 | def for_tuple_expr(self, args: List) -> str:
|
223 | 223 | args = self.strip_new_line_tokens(args)
|
@@ -245,7 +245,7 @@ def strip_new_line_tokens(self, args: List) -> List:
|
245 | 245 | Remove new line and Discard tokens.
|
246 | 246 | The parser will sometimes include these in the tree so we need to strip them out here
|
247 | 247 | """
|
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] |
249 | 249 |
|
250 | 250 | def to_string_dollar(self, value: Any) -> Any:
|
251 | 251 | """Wrap a string in ${ and }"""
|
|
0 commit comments