Skip to content

Commit

Permalink
Optimize heredoc regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
htorianik-amplify committed Jan 10, 2023
1 parent 0b02a28 commit 5c7e361
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions hcl2/hcl2.lark
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ tuple : "[" (new_line_or_comment? expression (new_line_or_comment? "," new_line_
object : "{" new_line_or_comment? (object_elem (new_line_and_or_comma object_elem )* new_line_and_or_comma?)? "}"
object_elem : (identifier | expression) ("=" | ":") expression

heredoc_template : /<<(?P<heredoc>[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)*?\n*\s*(?P=heredoc)/
heredoc_template_trim : /<<-(?P<heredoc_trim>[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)*?\n*\s*(?P=heredoc_trim)/
heredoc_template : /<<(?P<heredoc>[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)*?\s*(?P=heredoc)/
heredoc_template_trim : /<<-(?P<heredoc_trim>[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)*?\s*(?P=heredoc_trim)/

function_call : identifier "(" new_line_or_comment? arguments? new_line_or_comment? ")"
arguments : (expression (new_line_or_comment? "," new_line_or_comment? expression)* ("," | "...")? new_line_or_comment?)
Expand Down
4 changes: 2 additions & 2 deletions hcl2/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from lark.visitors import Transformer, Discard, _DiscardType

HEREDOC_PATTERN = re.compile(r"<<([a-zA-Z][a-zA-Z0-9._-]+)\n((.|\n)*?)\n*\s*\1", re.S)
HEREDOC_PATTERN = re.compile(r"<<([a-zA-Z][a-zA-Z0-9._-]+)\n((.|\n)*?)\s*\1", re.S)
HEREDOC_TRIM_PATTERN = re.compile(
r"<<-([a-zA-Z][a-zA-Z0-9._-]+)\n((.|\n)*?)\n*\s*\1", re.S
r"<<-([a-zA-Z][a-zA-Z0-9._-]+)\n((.|\n)*?)\s*\1", re.S
)

Attribute = namedtuple("Attribute", ("key", "value"))
Expand Down

0 comments on commit 5c7e361

Please sign in to comment.