You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2022/11/28 22:04:14 UTC
[royale-compiler] 03/04: ASParser: remove @ from verbatim strings to turn them into regular double-quoted strings (references #222)
This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit b6f6660570c376713f8d83f4b433b66d39096d3a
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Nov 28 13:23:55 2022 -0800
ASParser: remove @ from verbatim strings to turn them into regular double-quoted strings (references #222)
---
.../royale/compiler/internal/parsing/as/ASParser.g | 2 +-
.../compiler/internal/parsing/as/BaseASParser.java | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g b/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g
index c5a8105ae..934bdfdf7 100644
--- a/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g
+++ b/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g
@@ -2498,7 +2498,7 @@ primaryExpression returns [ExpressionNodeBase n]
| token=numericLiteral
{ n = new NumericLiteralNode(token); }
| TOKEN_LITERAL_STRING
- { n = new LiteralNode(token, LiteralType.STRING); }
+ { n = transformStringLiteral(token); }
| TOKEN_VOID_0
{ n = new LiteralNode(token, LiteralType.OBJECT); }
| TOKEN_LITERAL_REGEXP
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java
index 99fbc0b0c..01cdd12cd 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java
@@ -3101,4 +3101,21 @@ abstract class BaseASParser extends LLkParser implements IProblemReporter
{
return parsingProjectConfigVariables;
}
+
+ protected final LiteralNode transformStringLiteral(ASToken token)
+ {
+ String tokenText = token.getText();
+ if (tokenText.startsWith("@"))
+ {
+ // the only change needed is to remove the @ symbol
+ // the escape sequences are already handled for us
+ String newText = tokenText.substring(1);
+ ASToken newToken = new ASToken(ASTokenTypes.TOKEN_LITERAL_STRING, token.getStart(), token.getEnd(), token.getLine(), token.getColumn(), newText);
+ newToken.setEndLine(token.getEndLine());
+ newToken.setEndColumn(token.getEndColumn());
+ return new LiteralNode(newToken, LiteralType.STRING);
+ }
+
+ return new LiteralNode(token, LiteralType.STRING);
+ }
}