Skip to content

Commit

Permalink
Allowing for trailing dollars and percent signs in String literals (#…
Browse files Browse the repository at this point in the history
…4625)

* Allowing for trailing dollars and percent signs in String literals

* licenseFormat

* Apply suggestions from code review

* Apply suggestions from code review

* Organize imports to minimize diff

* Apply suggestions from code review

---------

Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
mccartney and timtebeek authored Oct 29, 2024
1 parent d130ebf commit 6ba5a6d
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 257 deletions.
6 changes: 4 additions & 2 deletions rewrite-hcl/src/main/antlr/HCLLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ TemplateStringLiteral

TemplateStringLiteralChar
: ~[\n\r%$"]
| '$' ~[{]
| '%' ~[{]
| '$' '$'
| '$' {_input.LA(1) != '{'}?
| '%' '%'
| '%' {_input.LA(1) != '{'}?
| EscapeSequence
;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -3240,8 +3240,8 @@ public final TemplateInterpolationContext templateInterpolation() throws Recogni
return _localctx;
}

@Override
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
@Override
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
case 6:
return expression_sempred((ExpressionContext)_localctx, predIndex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1509,8 +1509,8 @@ public final IndexesContext indexes() throws RecognitionException {
return _localctx;
}

@Override
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
@Override
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
case 7:
return binaryExpression_sempred((BinaryExpressionContext)_localctx, predIndex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,22 @@ void quoteEscaping() {
);
}

@ExpectedToFail
@Test
void escapingTheDollarSign() {
// https://github.com/hashicorp/hcl2/blob/master/hcl/hclsyntax/spec.md#template-literals
// The interpolation and directive introductions are escaped by doubling their leading characters. The ${
// sequence is escaped as $${ and the %{ sequence is escaped as %%{.
rewriteRun(
hcl(
"""
locals {
something = "Not a template/expression, just escaping $${somethingElse}."
}
"""
)
);
}

@Issue("https://github.com/openrewrite/rewrite/issues/4613")
@Test
void trailingDollarSign() {
Expand Down

0 comments on commit 6ba5a6d

Please sign in to comment.