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:11 UTC

[royale-compiler] branch develop updated (2e643d2c8 -> 9d715b936)

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


    from 2e643d2c8 formatter: a few more tests
     new 00d9cb215 Add raw string literals
     new 87b4736da RawASTokenizer: verbatim strings should include backslashes instead of omitting them (references #222)
     new b6f666057 ASParser: remove @ from verbatim strings to turn them into regular double-quoted strings (references #222)
     new 9d715b936 Tests: verbatim string (references #222)

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../royale/compiler/internal/parsing/as/ASParser.g |  2 +-
 .../compiler/internal/parsing/as/BaseASParser.java | 17 ++++++++++++
 .../internal/parsing/as/RawASTokenizer.lex         | 20 +++++++++++---
 .../ASVerbatimStringTests.java}                    | 31 +++++++++++-----------
 4 files changed, 50 insertions(+), 20 deletions(-)
 copy compiler/src/test/java/{mxml/tags/MXMLStringTagTests.java => as/ASVerbatimStringTests.java} (59%)


[royale-compiler] 03/04: ASParser: remove @ from verbatim strings to turn them into regular double-quoted strings (references #222)

Posted by jo...@apache.org.
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);
+    }
 }


[royale-compiler] 02/04: RawASTokenizer: verbatim strings should include backslashes instead of omitting them (references #222)

Posted by jo...@apache.org.
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 87b4736da8787c1718352e759a61e0f45d18f97c
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Nov 28 12:44:32 2022 -0800

    RawASTokenizer: verbatim strings should include backslashes instead of omitting them (references #222)
---
 .../org/apache/royale/compiler/internal/parsing/as/RawASTokenizer.lex | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/compiler/src/main/jflex/org/apache/royale/compiler/internal/parsing/as/RawASTokenizer.lex b/compiler/src/main/jflex/org/apache/royale/compiler/internal/parsing/as/RawASTokenizer.lex
index 580c8739d..907354eda 100644
--- a/compiler/src/main/jflex/org/apache/royale/compiler/internal/parsing/as/RawASTokenizer.lex
+++ b/compiler/src/main/jflex/org/apache/royale/compiler/internal/parsing/as/RawASTokenizer.lex
@@ -347,6 +347,10 @@ REGEX_CLASS="[" ({REGEX_ESCAPE}|[^\n\r\]\\])* "]"
 	{
 		yybegin(ESCAPE_SEQUENCE);
 	}
+	else
+	{
+		continueAggregate();
+	}
 }
 
 <STRINGLITERAL> {LINE_TERMINATOR}+


[royale-compiler] 01/04: Add raw string literals

Posted by jo...@apache.org.
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 00d9cb21560f03325c0d3d91b4d3fef229933586
Author: Chris Feger <ch...@yahoo.com>
AuthorDate: Mon Nov 21 14:31:04 2022 -0700

    Add raw string literals
---
 .../compiler/internal/parsing/as/RawASTokenizer.lex      | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/compiler/src/main/jflex/org/apache/royale/compiler/internal/parsing/as/RawASTokenizer.lex b/compiler/src/main/jflex/org/apache/royale/compiler/internal/parsing/as/RawASTokenizer.lex
index d9f72faff..580c8739d 100644
--- a/compiler/src/main/jflex/org/apache/royale/compiler/internal/parsing/as/RawASTokenizer.lex
+++ b/compiler/src/main/jflex/org/apache/royale/compiler/internal/parsing/as/RawASTokenizer.lex
@@ -47,7 +47,7 @@ import org.apache.royale.compiler.constants.IASKeywordConstants;
  */
 private enum StringKind
 {
-	CHAR, STRING
+	CHAR, STRING, RAW
 }
 
 private StringKind stringKind;
@@ -312,12 +312,19 @@ REGEX_CLASS="[" ({REGEX_ESCAPE}|[^\n\r\]\\])* "]"
 	yybegin(STRINGLITERAL);
 }
 
+<YYINITIAL> "@\""
+{
+	startAggregate();
+	stringKind = StringKind.RAW;
+	yybegin(STRINGLITERAL);
+}
+
 // String handling for both double and single quoted strings
 
 <STRINGLITERAL> "\""
 {
 	continueAggregate();
-	if (stringKind == StringKind.STRING)
+	if (stringKind == StringKind.STRING || stringKind == StringKind.RAW)
 	{
 		yybegin(YYINITIAL);
 		return buildAggregateToken(TOKEN_LITERAL_STRING);
@@ -336,7 +343,10 @@ REGEX_CLASS="[" ({REGEX_ESCAPE}|[^\n\r\]\\])* "]"
 
 <STRINGLITERAL> "\\"
 {
-	yybegin(ESCAPE_SEQUENCE);
+	if (stringKind != StringKind.RAW)
+	{
+		yybegin(ESCAPE_SEQUENCE);
+	}
 }
 
 <STRINGLITERAL> {LINE_TERMINATOR}+


[royale-compiler] 04/04: Tests: verbatim string (references #222)

Posted by jo...@apache.org.
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 9d715b936b31fc61a1d6a694beae5be35c06a556
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Nov 28 13:43:15 2022 -0800

    Tests: verbatim string (references #222)
---
 .../src/test/java/as/ASVerbatimStringTests.java    | 44 ++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/compiler/src/test/java/as/ASVerbatimStringTests.java b/compiler/src/test/java/as/ASVerbatimStringTests.java
new file mode 100644
index 000000000..6b6ddc2ce
--- /dev/null
+++ b/compiler/src/test/java/as/ASVerbatimStringTests.java
@@ -0,0 +1,44 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package as;
+
+import java.io.File;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ASVerbatimStringTests extends ASFeatureTestsBase
+{
+    @Test
+    public void testRegularStringAndVerbatimString()
+    {
+        String[] testCode = new String[]
+        {
+            "var s1:String = \"regular\\tstring\";",
+            "var s2:String = @\"verbatim\\tstring\";",
+			"assertEqual('regular string', s1, 'regular\\tstring');",
+			"assertEqual('verbatim string', s2, 'verbatim\\\\tstring');",
+        };
+        String source = getAS(new String[0], new String[0], testCode, new String[0]);
+		System.err.println("*** " + source);
+
+        compileAndRun(source);
+    }
+}