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/12/06 17:13:45 UTC

[royale-compiler] branch develop updated (ee2f4768d -> b3f358240)

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 ee2f4768d A few calls to System.out.println() that should have been System.err.println()
     new 285681a5b formatter: fix missing formatting for finally
     new aa7751450 formatter: nullish coalescing operator
     new a71bff565 compiler: verbatim string tokens are now of type TOKEN_VERBATIM_STRING so that the formatter can know the difference
     new a38ac68e7 formatter: verbatim strings
     new b3f358240 formatter: tests for member access and null conditional

The 5 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:
 .../apache/royale/compiler/parsing/IASToken.java   |  3 +-
 .../royale/compiler/internal/parsing/as/ASParser.g |  4 +-
 .../compiler/internal/parsing/as/ASToken.java      |  3 +
 .../compiler/internal/parsing/as/BaseASParser.java | 21 +++----
 .../internal/parsing/as/RawASTokenizer.lex         |  7 ++-
 .../apache/royale/formatter/ASTokenFormatter.java  | 11 +++-
 .../royale/formatter/TestLogicalOperators.java     | 20 +++++++
 .../{TestXML.java => TestMemberAccess.java}        | 29 ++++------
 .../apache/royale/formatter/TestStringLiteral.java | 20 +++++++
 .../royale/formatter/TestTryCatchStatement.java    | 65 ++++++++++++++++++++++
 10 files changed, 145 insertions(+), 38 deletions(-)
 copy formatter/src/test/java/org/apache/royale/formatter/{TestXML.java => TestMemberAccess.java} (75%)


[royale-compiler] 05/05: formatter: tests for member access and null conditional

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 b3f358240fa91926c6502dac9251e66ef0529ba9
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Dec 6 09:13:08 2022 -0800

    formatter: tests for member access and null conditional
---
 .../apache/royale/formatter/TestMemberAccess.java  | 79 ++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestMemberAccess.java b/formatter/src/test/java/org/apache/royale/formatter/TestMemberAccess.java
new file mode 100644
index 000000000..2d2460b8b
--- /dev/null
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestMemberAccess.java
@@ -0,0 +1,79 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 org.apache.royale.formatter;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class TestMemberAccess extends BaseFormatterTests {
+	@Test
+	public void testMemberAccess() {
+		FormatterSettings settings = new FormatterSettings();
+		ASTokenFormatter formatter = new ASTokenFormatter(settings);
+		String result = formatter.format("file.as",
+		// @formatter:off
+			"this.that;",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"this.that;",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testMemberAccessWithNewLine() {
+		FormatterSettings settings = new FormatterSettings();
+		settings.insertSpaces = false;
+		ASTokenFormatter formatter = new ASTokenFormatter(settings);
+		String result = formatter.format("file.as",
+		// @formatter:off
+			"this\n.that;",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"this\n\t.that;",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testNullConditionalWithNewLine() {
+		FormatterSettings settings = new FormatterSettings();
+		settings.insertSpaces = false;
+		ASTokenFormatter formatter = new ASTokenFormatter(settings);
+		String result = formatter.format("file.as",
+		// @formatter:off
+			"this\n?.that;",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"this\n\t?.that;",
+				// @formatter:on
+				result);
+	}
+}


[royale-compiler] 01/05: formatter: fix missing formatting for finally

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 285681a5b9e56614a65e300909014c2eeaf3d7c5
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Dec 6 08:44:04 2022 -0800

    formatter: fix missing formatting for finally
---
 .../apache/royale/formatter/ASTokenFormatter.java  |  3 +-
 .../royale/formatter/TestTryCatchStatement.java    | 65 ++++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
index 56e3be77d..903c0d4f6 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
@@ -722,7 +722,8 @@ public class ASTokenFormatter extends BaseTokenFormatter {
 						}
 						break;
 					}
-					case ASTokenTypes.TOKEN_KEYWORD_TRY: {
+					case ASTokenTypes.TOKEN_KEYWORD_TRY:
+					case ASTokenTypes.TOKEN_KEYWORD_FINALLY: {
 						blockStack.add(new BlockStackItem(token));
 						if (!skipWhitespaceBeforeSemicolon) {
 							requiredSpace = true;
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestTryCatchStatement.java b/formatter/src/test/java/org/apache/royale/formatter/TestTryCatchStatement.java
index 5f139cb64..9c906dbbd 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestTryCatchStatement.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestTryCatchStatement.java
@@ -244,4 +244,69 @@ public class TestTryCatchStatement extends BaseFormatterTests {
 				// @formatter:on
 				result);
 	}
+	@Test
+	public void testPlaceOpenBraceOnNewLineWithEmptyBlockWithFinally() {
+		FormatterSettings settings = new FormatterSettings();
+		settings.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		settings.placeOpenBraceOnNewLine = true;
+		settings.insertSpaces = false;
+		ASTokenFormatter formatter = new ASTokenFormatter(settings);
+		String result = formatter.format("file.as",
+		// @formatter:off
+			"try {\n" +
+			"}\n" +
+			"catch (e:Object) {\n" +
+			"}\n" +
+			"finally {\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"try\n" +
+				"{\n" +
+				"}\n" +
+				"catch (e:Object)\n" +
+				"{\n" +
+				"}\n" +
+				"finally\n" +
+				"{\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
+
+	@Test
+	public void testDisablePlaceOpenBraceOnNewLineWithEmptyBlockWithFinally() {
+		FormatterSettings settings = new FormatterSettings();
+		settings.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		settings.placeOpenBraceOnNewLine = false;
+		settings.insertSpaces = false;
+		ASTokenFormatter formatter = new ASTokenFormatter(settings);
+		String result = formatter.format("file.as",
+		// @formatter:off
+			"try\n" +
+			"{\n" +
+			"}\n" +
+			"catch (e:Object)\n" +
+			"{\n" +
+			"}\n" +
+			"finally\n" +
+			"{\n" +
+			"}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"try {\n" +
+				"}\n" +
+				"catch (e:Object) {\n" +
+				"}\n" +
+				"finally {\n" +
+				"}",
+				// @formatter:on
+				result);
+	}
 }


[royale-compiler] 04/05: formatter: verbatim strings

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 a38ac68e7566d65a3513106553d272e82ffa4fca
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Dec 6 09:08:19 2022 -0800

    formatter: verbatim strings
---
 .../apache/royale/formatter/ASTokenFormatter.java    |  6 ++++--
 .../apache/royale/formatter/TestStringLiteral.java   | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
index 0ae559168..3513d2d38 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
@@ -1133,7 +1133,7 @@ public class ASTokenFormatter extends BaseTokenFormatter {
 					return formatMultiLineComment(token.getText());
 				}
 				case ASTokenTypes.TOKEN_LITERAL_STRING: {
-					return formatLiteralString(token.getText());
+					return formatLiteralString(token);
 				}
 				case ASTokenTypes.TOKEN_SEMICOLON: {
 					if (skipFormatting) {
@@ -1232,7 +1232,9 @@ public class ASTokenFormatter extends BaseTokenFormatter {
 		return comment;
 	}
 
-	private String formatLiteralString(String string) {
+	private String formatLiteralString(IASToken token) {
+		String string = token.getText();
+		System.err.println("*** " + string);
 		String charsToEscape = "\b\t\n\f\r\\";
 		String escapeChars = "btnfr\\";
 		int escapeIndex = -1;
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestStringLiteral.java b/formatter/src/test/java/org/apache/royale/formatter/TestStringLiteral.java
index 4e8a85c63..90b64b65c 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestStringLiteral.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestStringLiteral.java
@@ -143,4 +143,24 @@ public class TestStringLiteral extends BaseFormatterTests {
 				// @formatter:on
 				result);
 	}
+
+	@Test
+	public void testVerbatimDoubleQuoteWithBackslash() {
+		FormatterSettings settings = new FormatterSettings();
+		settings.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		settings.placeOpenBraceOnNewLine = true;
+		settings.insertSpaces = false;
+		ASTokenFormatter formatter = new ASTokenFormatter(settings);
+		String result = formatter.format("file.as",
+		// @formatter:off
+			"@\"\\\";",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+		"@\"\\\";",
+				// @formatter:on
+				result);
+	}
 }


[royale-compiler] 03/05: compiler: verbatim string tokens are now of type TOKEN_VERBATIM_STRING so that the formatter can know the difference

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 a71bff565c7853ca9a416118202b0856e8b32f45
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Dec 6 09:08:07 2022 -0800

    compiler: verbatim string tokens are now of type TOKEN_VERBATIM_STRING so that the formatter can know the difference
    
    It still results in the same LiteralNode in the AST. This is purely at the token level.
---
 .../apache/royale/compiler/parsing/IASToken.java    |  3 ++-
 .../royale/compiler/internal/parsing/as/ASParser.g  |  4 +++-
 .../compiler/internal/parsing/as/ASToken.java       |  3 +++
 .../compiler/internal/parsing/as/BaseASParser.java  | 21 ++++++++-------------
 .../compiler/internal/parsing/as/RawASTokenizer.lex |  7 ++++++-
 5 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/parsing/IASToken.java b/compiler-common/src/main/java/org/apache/royale/compiler/parsing/IASToken.java
index d2ba7d317..c41d3ed8c 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/parsing/IASToken.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/parsing/IASToken.java
@@ -60,7 +60,8 @@ public interface IASToken extends ICMToken, ISourceLocation
         COLON,
         DEFAULT_XML_STATEMENT,
         UNKNOWN,
-        INCLUDE
+        INCLUDE,
+        VERBATIM_STRING
     }
 
     /**
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 90432099a..00a2b8084 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,8 +2498,10 @@ primaryExpression returns [ExpressionNodeBase n]
         { n = LanguageIdentifierNode.buildThis(token); }
     |   token=numericLiteral
         { n = new NumericLiteralNode(token); }
+    |   TOKEN_VERBATIM_STRING
+        { n = transformRawString(token); }
     |   TOKEN_LITERAL_STRING
-        { n = transformStringLiteral(token); }
+        { n = new LiteralNode(token, LiteralType.STRING); }
     |   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/ASToken.java b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ASToken.java
index de34ff3f8..11df97b41 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ASToken.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ASToken.java
@@ -433,6 +433,7 @@ public class ASToken extends TokenBase implements IASToken, ASTokenTypes
             case TOKEN_LITERAL_HEX_NUMBER:
             case TOKEN_LITERAL_REGEXP:
             case TOKEN_LITERAL_STRING:
+            case TOKEN_VERBATIM_STRING:
             case TOKEN_LITERAL_XMLLIST:
             case TOKEN_E4X_XMLLIST_CLOSE:
                 return true;
@@ -937,6 +938,8 @@ public class ASToken extends TokenBase implements IASToken, ASTokenTypes
                 return ASTokenKind.SCOPE_CLOSE;
             case TOKEN_BLOCK_OPEN:
                 return ASTokenKind.SCOPE_OPEN;
+            case TOKEN_VERBATIM_STRING:
+                return ASTokenKind.VERBATIM_STRING;
             case TOKEN_LITERAL_STRING:
                 return ASTokenKind.STRING_LITERAL;
             case TOKEN_LITERAL_NUMBER:
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 9a647b3da..7174b62f4 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
@@ -3112,21 +3112,16 @@ abstract class BaseASParser extends LLkParser implements IProblemReporter
         return parsingProjectConfigVariables;
     }
 
-    protected final LiteralNode transformStringLiteral(ASToken token)
+    protected final LiteralNode transformRawString(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);
+        // 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_VERBATIM_STRING, token.getStart(), token.getEnd(), token.getLine(), token.getColumn(), newText);
+        newToken.setEndLine(token.getEndLine());
+        newToken.setEndColumn(token.getEndColumn());
+        return new LiteralNode(newToken, LiteralType.STRING);
     }
 
     private final ExpressionNodeBase transformNullishCoalescingExpression(ExpressionNodeBase left, ASToken op, ExpressionNodeBase right)
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 e4a0eee83..ff925c878 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
@@ -324,11 +324,16 @@ REGEX_CLASS="[" ({REGEX_ESCAPE}|[^\n\r\]\\])* "]"
 <STRINGLITERAL> "\""
 {
 	continueAggregate();
-	if (stringKind == StringKind.STRING || stringKind == StringKind.RAW)
+	if (stringKind == StringKind.STRING)
 	{
 		yybegin(YYINITIAL);
 		return buildAggregateToken(TOKEN_LITERAL_STRING);
 	}
+	else if (stringKind == StringKind.RAW)
+	{
+		yybegin(YYINITIAL);
+		return buildAggregateToken(TOKEN_VERBATIM_STRING);
+	}
 }
 
 <STRINGLITERAL> "'"


[royale-compiler] 02/05: formatter: nullish coalescing operator

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 aa775145095fccc63dc77b3d70eaffa4565a9cd3
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Dec 6 08:46:57 2022 -0800

    formatter: nullish coalescing operator
---
 .../apache/royale/formatter/ASTokenFormatter.java    |  2 ++
 .../royale/formatter/TestLogicalOperators.java       | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
index 903c0d4f6..0ae559168 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
@@ -385,6 +385,7 @@ public class ASTokenFormatter extends BaseTokenFormatter {
 					case ASTokenTypes.TOKEN_OPERATOR_BITWISE_XOR:
 					case ASTokenTypes.TOKEN_OPERATOR_LOGICAL_AND:
 					case ASTokenTypes.TOKEN_OPERATOR_LOGICAL_OR:
+					case ASTokenTypes.TOKEN_OPERATOR_NULLISH_COALESCING:
 					case ASTokenTypes.TOKEN_OPERATOR_PLUS_ASSIGNMENT:
 					case ASTokenTypes.TOKEN_OPERATOR_MINUS_ASSIGNMENT:
 					case ASTokenTypes.TOKEN_OPERATOR_MULTIPLICATION_ASSIGNMENT:
@@ -869,6 +870,7 @@ public class ASTokenFormatter extends BaseTokenFormatter {
 					case ASTokenTypes.TOKEN_OPERATOR_BITWISE_XOR:
 					case ASTokenTypes.TOKEN_OPERATOR_LOGICAL_AND:
 					case ASTokenTypes.TOKEN_OPERATOR_LOGICAL_OR:
+					case ASTokenTypes.TOKEN_OPERATOR_NULLISH_COALESCING:
 					case ASTokenTypes.TOKEN_OPERATOR_PLUS_ASSIGNMENT:
 					case ASTokenTypes.TOKEN_OPERATOR_MINUS_ASSIGNMENT:
 					case ASTokenTypes.TOKEN_OPERATOR_MULTIPLICATION_ASSIGNMENT:
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestLogicalOperators.java b/formatter/src/test/java/org/apache/royale/formatter/TestLogicalOperators.java
index dcf6e03e1..2839ddc2e 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestLogicalOperators.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestLogicalOperators.java
@@ -123,4 +123,24 @@ public class TestLogicalOperators extends BaseFormatterTests {
 				// @formatter:on
 				result);
 	}
+
+	@Test
+	public void testNullishCoalescingOperator() {
+		FormatterSettings settings = new FormatterSettings();
+		settings.insertSpaceBeforeAndAfterBinaryOperators = true;
+		settings.placeOpenBraceOnNewLine = true;
+		settings.insertSpaces = false;
+		ASTokenFormatter formatter = new ASTokenFormatter(settings);
+		String result = formatter.format("file.as",
+		// @formatter:off
+			"a??b;",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+				"a ?? b;",
+				// @formatter:on
+				result);
+	}
 }