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 2025/10/15 21:27:14 UTC

(royale-compiler) branch develop updated (c544fdcc7 -> 1422cba7b)

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 c544fdcc7 JSCSSCompilationSession: added many more HTML elements from the specification
     new f9af40f62 CSS: make parsing of attribute selectors stricter
     new f2de1acef CSS: fix 'not' not being allowed as an identifier by moving the check for it into CSSTree with a new problem class for unknown pseudo-classes in selectors
     new 6f571caff CSS: move function name validation into CSSTree so that those function names may be used as identifiers
     new 1422cba7b CSS: support more CSS pseudo-classes with arguments

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:
 .../driver/js/royale/JSCSSCompilationSession.java  |   5 +
 .../test/resources/royale/files/CSSTestSource.css  |   4 +
 .../royale/files/CSSTestSource_encoded_result.txt  |   4 +
 .../royale/files/CSSTestSource_result.css          |   5 +
 .../org/apache/royale/compiler/internal/css/CSS.g  |  64 +------
 .../apache/royale/compiler/internal/css/CSSTree.g  | 212 ++++++++++++++++++---
 .../apache/royale/compiler/css/ConditionType.java  |   7 +-
 .../royale/compiler/css/ICSSSelectorCondition.java |   5 +
 .../royale/compiler/internal/css/CSSSelector.java  |   5 +
 .../internal/css/CSSSelectorCondition.java         |  24 ++-
 ...Problem.java => CSSUnknownFunctionProblem.java} |  15 +-
 ...blem.java => CSSUnknownPseudoClassProblem.java} |  15 +-
 compiler/src/test/build.xml                        |   1 +
 .../internal/css/CSSSelectorConditionTests.java    |  22 +++
 14 files changed, 278 insertions(+), 110 deletions(-)
 copy compiler/src/main/java/org/apache/royale/compiler/problems/{MXMLContentAfterRootTagProblem.java => CSSUnknownFunctionProblem.java} (74%)
 copy compiler/src/main/java/org/apache/royale/compiler/problems/{MXMLContentAfterRootTagProblem.java => CSSUnknownPseudoClassProblem.java} (72%)


(royale-compiler) 01/04: CSS: make parsing of attribute selectors stricter

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 f9af40f625bf2ce6b76e997cf9a6fbd764b3f980
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Oct 7 14:56:38 2025 -0700

    CSS: make parsing of attribute selectors stricter
    
    An operator and a value are optional, but if one exists, both must exist.
---
 .../org/apache/royale/compiler/internal/css/CSS.g  |  2 +-
 .../apache/royale/compiler/internal/css/CSSTree.g  | 31 ++++++++++++++++++----
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
index c21f282a3..64f295df8 100644
--- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
+++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
@@ -520,7 +520,7 @@ formatOption
 	;
     
 attributeSelector
-    :   SQUARE_OPEN attributeName attributeOperator* attributeValue* SQUARE_END
+    :   SQUARE_OPEN attributeName (attributeOperator attributeValue)? SQUARE_END
     ;
     
 attributeName
diff --git a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
index 0322d3025..070096355 100644
--- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
+++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
@@ -386,9 +386,16 @@ elementSelector
     |   STAR           
         { $simpleSelector::element = $STAR.text; }
     ;
-    
+
+/**
+ * Matches an attribute selector.
+ *
+ * Must starts with an opening square bracket and end with a closing square
+ * bracket. Inside the brackets, it must start with attribute name. An operator
+ * and value may optionally follow, but if either exists, both must exist.
+ */
 attributeSelector
-    :   open = SQUARE_OPEN attributeName attributeOperator* attributeValue* close = SQUARE_END
+    :   open = SQUARE_OPEN attributeName (attributeOperator attributeValue)? close = SQUARE_END
         {
             if (strictFlexCSS)
             {
@@ -398,12 +405,20 @@ attributeSelector
             curAttribute = $open.text + curAttribute + $close.text;
         }
     ;
-    
+
+/**
+ * Matches an attribute name within an attribute selector.
+ */
 attributeName
     :    n1 = ID
          { curAttribute = $n1.text; }
     ;
-    
+
+/**
+ * Matches an operator within an attribute selector.
+ *
+ * Immediately follows the attribute name.
+ */
 attributeOperator
     :    o1 = BEGINS_WITH
          { curAttribute += $o1.text; }
@@ -418,7 +433,13 @@ attributeOperator
     |    o6 = EQUALS
          { curAttribute += $o6.text; }
     ;
-    
+
+
+/**
+ * Matches a value within an attribute selector.
+ *
+ * Immediately follows the attribute operator.
+ */ 
 attributeValue
     :    s = STRING
          { curAttribute += $s.text; }


(royale-compiler) 04/04: CSS: support more CSS pseudo-classes with arguments

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 1422cba7b228960bfa263cc5712b313f834a153a
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 15 13:28:49 2025 -0700

    CSS: support more CSS pseudo-classes with arguments
    
    Previously, we supported :not() only. Now, more functions are recognized. CSSSelectorCondition now includes optional arguments, which are null when there are no arguments, or a string when there are. ConditionType removes NOT and uses PSUEDO.
---
 .../driver/js/royale/JSCSSCompilationSession.java  |  5 ++++
 .../test/resources/royale/files/CSSTestSource.css  |  4 ++++
 .../royale/files/CSSTestSource_encoded_result.txt  |  4 ++++
 .../royale/files/CSSTestSource_result.css          |  5 ++++
 .../apache/royale/compiler/internal/css/CSSTree.g  | 27 ++++++++++++++++++----
 .../apache/royale/compiler/css/ConditionType.java  |  7 +-----
 .../royale/compiler/css/ICSSSelectorCondition.java |  5 ++++
 .../royale/compiler/internal/css/CSSSelector.java  |  5 ++++
 .../internal/css/CSSSelectorCondition.java         | 24 ++++++++++++++++++-
 compiler/src/test/build.xml                        |  2 +-
 .../internal/css/CSSSelectorConditionTests.java    | 22 ++++++++++++++++++
 11 files changed, 97 insertions(+), 13 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java
index c93d81eda..611dd0c3a 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/royale/JSCSSCompilationSession.java
@@ -233,6 +233,11 @@ public class JSCSSCompilationSession extends CSSCompilationSession
         {
             builder.append(condition.getConditionType().prefix);
             builder.append(condition.getValue());
+            String args = condition.getArguments();
+            if (args != null)
+            {
+                builder.append(args);
+            }
         }
     }
     
diff --git a/compiler-jx/src/test/resources/royale/files/CSSTestSource.css b/compiler-jx/src/test/resources/royale/files/CSSTestSource.css
index d23c64b31..c68648728 100755
--- a/compiler-jx/src/test/resources/royale/files/CSSTestSource.css
+++ b/compiler-jx/src/test/resources/royale/files/CSSTestSource.css
@@ -164,6 +164,10 @@ p:not(.primary) {
   color: #fff;
 }
 
+:is(ol, ul) {
+  color: #fff;
+}
+
 #my-id ~ h1:first-child span.subtitle {
   color: #fff;
 }
\ No newline at end of file
diff --git a/compiler-jx/src/test/resources/royale/files/CSSTestSource_encoded_result.txt b/compiler-jx/src/test/resources/royale/files/CSSTestSource_encoded_result.txt
index 8def6dc56..3b08e57fe 100755
--- a/compiler-jx/src/test/resources/royale/files/CSSTestSource_encoded_result.txt
+++ b/compiler-jx/src/test/resources/royale/files/CSSTestSource_encoded_result.txt
@@ -151,6 +151,10 @@ function() {this["filter"] = null},
 function() {this["color"] = 16777215},
 0,
 1,
+":is(ol, ul)",
+function() {this["color"] = 16777215},
+0,
+1,
 "span.subtitle",
 function() {this["color"] = 16777215}];
 
diff --git a/compiler-jx/src/test/resources/royale/files/CSSTestSource_result.css b/compiler-jx/src/test/resources/royale/files/CSSTestSource_result.css
index 5a847f95c..1a10074d3 100755
--- a/compiler-jx/src/test/resources/royale/files/CSSTestSource_result.css
+++ b/compiler-jx/src/test/resources/royale/files/CSSTestSource_result.css
@@ -183,6 +183,11 @@ p:not(.primary) {
 }
 
 
+:is(ol, ul) {
+        color: #fff;
+}
+
+
 #my-id~h1:first-child span.subtitle {
         color: #fff;
 }
diff --git a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
index 5f9413103..138f3f0d0 100644
--- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
+++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
@@ -172,6 +172,21 @@ protected static final List<String> KNOWN_FUNCTIONS = Arrays.asList(
     "xywh"
 );
 
+protected static final List<String> KNOWN_PSEUDO_CLASS_FUNCTIONS = Arrays.asList(
+    "dir",
+    "has",
+    "host",
+    "is",
+    "lang",
+    "not",
+    "nth-child",
+    "nth-last-child",
+    "nth-last-of-type",
+    "nth-of-type",
+    "state",
+    "where"
+);
+
 /**
  * CSS DOM object.
  */
@@ -467,11 +482,12 @@ conditionSelector
 {
     ConditionType type = null;
     String name = null;
+    String arguments = null;
 }
 @after
 {
     $simpleSelector::conditions.add(
-        new CSSSelectorCondition(name, type, $start, tokenStream));
+        new CSSSelectorCondition(name, type, arguments, $start, tokenStream));
 }
     :   ^(DOT c=ID)   { type = ConditionType.CLASS; name = $c.text; }  
     |   HASH_WORD   { type = ConditionType.ID; name = $HASH_WORD.text.substring(1); }
@@ -479,15 +495,16 @@ conditionSelector
         {
             if (strictFlexCSS)
             {
-                // Flex didn't support the CSS :not() pseudo-class
+                // Flex didn't support the CSS pseudo-class functions
                 displayStrictFlexSyntaxError($COLON.text + $s.text, $s);
             }
-            if (!$s.text.equals("not"))
+            if (!KNOWN_PSEUDO_CLASS_FUNCTIONS.contains($s.text))
             {
                 displayUnknownPseudoClassError($s.text, $s);
             }
-            type = ConditionType.NOT;
-            name = $arg.text;
+            type = ConditionType.PSEUDO;
+            name = $s.text;
+            arguments = $arg.text;
         }
     |   ^(COLON s=ID) { type = ConditionType.PSEUDO; name = $s.text; } 
     |   ^(DOUBLE_COLON dc=ID)
diff --git a/compiler/src/main/java/org/apache/royale/compiler/css/ConditionType.java b/compiler/src/main/java/org/apache/royale/compiler/css/ConditionType.java
index f538de4b3..a0ae6469d 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/css/ConditionType.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/css/ConditionType.java
@@ -35,7 +35,7 @@ public enum ConditionType
     ID("#"),
 
     /**
-     * For example: <code>s|Label:loadingState</code>
+     * For example: <code>s|Label:loadingState</code> or <code>s|Button:not(.rounded)</code>
      */
     PSEUDO(":"),
 
@@ -44,11 +44,6 @@ public enum ConditionType
      */
     PSEUDO_ELEMENT("::"),
 
-    /**
-     * For example: <code>s|Panel:not(:first-child)</code>
-     */
-    NOT(":not"),
-
     /**
      * For example: <code>s|Label[loadingState]</code>
      */
diff --git a/compiler/src/main/java/org/apache/royale/compiler/css/ICSSSelectorCondition.java b/compiler/src/main/java/org/apache/royale/compiler/css/ICSSSelectorCondition.java
index b00f130a7..f03ad55c7 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/css/ICSSSelectorCondition.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/css/ICSSSelectorCondition.java
@@ -41,6 +41,11 @@ public interface ICSSSelectorCondition extends ICSSNode
      */
     String getValue();
 
+    /**
+     * @return Optional arguments value, or null.
+     */
+    String getArguments();
+
     /**
      * @return Condition type.
      */
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSSelector.java b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSSelector.java
index 28fcd153c..e9ea9127a 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSSelector.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSSelector.java
@@ -171,6 +171,11 @@ public class CSSSelector extends CSSNodeBase implements ICSSSelector
     		ICSSSelectorCondition condition = conditions.get(i);
     		s.append(condition.getConditionType().prefix);
 			s.append(condition.getValue());
+            String args = condition.getArguments();
+            if (args != null)
+            {
+                s.append(args);
+            }
     	}
     	return s.toString();
     }
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSSelectorCondition.java b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSSelectorCondition.java
index c53dea955..d94a280e7 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSSelectorCondition.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSSelectorCondition.java
@@ -36,16 +36,33 @@ public class CSSSelectorCondition extends CSSNodeBase implements ICSSSelectorCon
                                    final ConditionType type,
                                    final CommonTree tree,
                                    final TokenStream tokenStream)
+    {
+        this(value, type, null, tree, tokenStream);
+    }
+
+    protected CSSSelectorCondition(final String value,
+                                   final ConditionType type,
+                                   final String arguments,
+                                   final CommonTree tree,
+                                   final TokenStream tokenStream)
     {
         super(tree, tokenStream, CSSModelTreeType.SELECTOR_CONDITION);
         assert !Strings.isNullOrEmpty(value) : "Selector condition value can't be empty.";
         assert type != null : "Selector condition type can't be null.";
         this.value = value;
         this.type = type;
+        this.arguments = arguments;
     }
 
     private final String value;
     private final ConditionType type;
+    private final String arguments;
+
+    @Override
+    public String getArguments()
+    {
+        return arguments;
+    }
 
     @Override
     public String getValue()
@@ -62,6 +79,11 @@ public class CSSSelectorCondition extends CSSNodeBase implements ICSSSelectorCon
     @Override
     public String toString()
     {
-        return type.prefix.concat(value);
+        String result = type.prefix.concat(value);
+        if (arguments != null)
+        {
+            result = result.concat(arguments);
+        }
+        return result;
     }
 }
diff --git a/compiler/src/test/build.xml b/compiler/src/test/build.xml
index f508beb73..9981656e7 100644
--- a/compiler/src/test/build.xml
+++ b/compiler/src/test/build.xml
@@ -318,7 +318,7 @@
             <batchtest todir="${compiler}/target/junit-reports">
                 <fileset dir="${compiler}/target/test-classes">
                     <include name="**/*Tests.class"/>
-                    <!-- <exclude name="as/**"/> -->
+                    <exclude name="as/**"/>
                     <exclude name="f/**"/>
                     <exclude name="mxml/tags/**"/>
                     <exclude name="properties/**"/>
diff --git a/compiler/src/test/java/org/apache/royale/compiler/internal/css/CSSSelectorConditionTests.java b/compiler/src/test/java/org/apache/royale/compiler/internal/css/CSSSelectorConditionTests.java
index 5a80b6a14..ec8f3e01d 100644
--- a/compiler/src/test/java/org/apache/royale/compiler/internal/css/CSSSelectorConditionTests.java
+++ b/compiler/src/test/java/org/apache/royale/compiler/internal/css/CSSSelectorConditionTests.java
@@ -75,6 +75,23 @@ public class CSSSelectorConditionTests extends CSSBaseTests {
 		assertThat("condition.getOperator()" , condition.getOperator(), is( CSSModelTreeType.SELECTOR_CONDITION ) );
 		assertThat("condition.getConditionType()" , condition.getConditionType() , is( ConditionType.PSEUDO ) );
 		assertThat("condition.getValue()" , condition.getValue(), is( "up" ) );
+		assertThat("condition.getArguments()" , condition.getArguments(), is( (String) null ) );
+	}
+
+	
+	@Test
+	public void CSSSelectorConditionTests_pseudo_function_condition()
+	{
+		String code = " custom|Button:not(.rounded) "; 
+		
+		List<ICSSSelectorCondition> conditions = getCSSSelectorConditions(code);
+		assertThat("conditions.size()" , conditions.size(), is(1) );	
+		
+		CSSSelectorCondition condition = (CSSSelectorCondition) conditions.get(0);
+		assertThat("condition.getOperator()" , condition.getOperator(), is( CSSModelTreeType.SELECTOR_CONDITION ) );
+		assertThat("condition.getConditionType()" , condition.getConditionType() , is( ConditionType.PSEUDO ) );
+		assertThat("condition.getValue()" , condition.getValue(), is( "not" ) );
+		assertThat("condition.getArguments()" , condition.getArguments(), is( "(.rounded)" ) );
 	}
 	
 	@Test
@@ -89,6 +106,7 @@ public class CSSSelectorConditionTests extends CSSBaseTests {
 		assertThat("condition.getOperator()" , condition.getOperator(), is( CSSModelTreeType.SELECTOR_CONDITION ) );
 		assertThat("condition.getConditionType()" , condition.getConditionType() , is( ConditionType.CLASS ) );
 		assertThat("condition.getValue()" , condition.getValue(), is( "rounded" ) );
+		assertThat("condition.getArguments()" , condition.getArguments(), is( (String) null ) );
 	}
 	
 	@Test
@@ -103,6 +121,7 @@ public class CSSSelectorConditionTests extends CSSBaseTests {
 		assertThat("condition.getOperator()" , condition.getOperator(), is( CSSModelTreeType.SELECTOR_CONDITION ) );
 		assertThat("condition.getConditionType()" , condition.getConditionType() , is( ConditionType.ID ) );
 		assertThat("condition.getValue())" , condition.getValue(), is( "main" ) );
+		assertThat("condition.getArguments()" , condition.getArguments(), is( (String) null ) );
 	}
 	
 	@Test
@@ -117,16 +136,19 @@ public class CSSSelectorConditionTests extends CSSBaseTests {
 		assertThat("condition1.getOperator()" , condition1.getOperator(), is( CSSModelTreeType.SELECTOR_CONDITION ) );
 		assertThat("condition1.getConditionType()" , condition1.getConditionType() , is( ConditionType.CLASS ) );
 		assertThat("condition1.getValue()" , condition1.getValue(), is( "rounded" ) );
+		assertThat("condition1.getArguments()" , condition1.getArguments(), is( (String) null ) );
 		
 		CSSSelectorCondition condition2 = (CSSSelectorCondition) conditions.get(1);
 		assertThat("condition2.getOperator()" , condition2.getOperator(), is( CSSModelTreeType.SELECTOR_CONDITION ) );
 		assertThat("condition2.getConditionType()" , condition2.getConditionType() , is( ConditionType.ID ) );
 		assertThat("condition2.getValue()" , condition2.getValue(), is( "main" ) );
+		assertThat("condition2.getArguments()" , condition2.getArguments(), is( (String) null ) );
 		
 		CSSSelectorCondition condition3 = (CSSSelectorCondition) conditions.get(2);
 		assertThat("condition3.getOperator()" , condition3.getOperator(), is( CSSModelTreeType.SELECTOR_CONDITION ) );
 		assertThat("condition3.getConditionType()" , condition3.getConditionType() , is( ConditionType.PSEUDO ) );
 		assertThat("condition3.getValue()" , condition3.getValue(), is( "up" ) );
+		assertThat("condition3.getArguments()" , condition3.getArguments(), is( (String) null ) );
 	}
 	
 


(royale-compiler) 03/04: CSS: move function name validation into CSSTree so that those function names may be used as identifiers

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 6f571caff102f0d5bfecbad37ff859bd0ef1f83a
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 15 09:55:32 2025 -0700

    CSS: move function name validation into CSSTree so that those function names may be used as identifiers
    
    Currently, url is excluded because it has options after the arguments.
    
    Introduces a new CSSUnknownFunctionProblem for this purpose.
---
 .../org/apache/royale/compiler/internal/css/CSS.g  |  56 +--------
 .../apache/royale/compiler/internal/css/CSSTree.g  | 138 ++++++++++++++++++---
 .../problems/CSSUnknownFunctionProblem.java        |  39 ++++++
 3 files changed, 161 insertions(+), 72 deletions(-)

diff --git a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
index 633d412af..8e8e7768a 100644
--- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
+++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
@@ -488,16 +488,8 @@ singleValue
     :   NUMBER_WITH_PERCENT
     |   NUMBER_WITH_UNIT
     |   HASH_WORD
-    |   CLASS_REFERENCE ARGUMENTS
-    								-> ^(CLASS_REFERENCE ARGUMENTS)
-    |   PROPERTY_REFERENCE ARGUMENTS
-    								-> ^(PROPERTY_REFERENCE ARGUMENTS)
-    |   EMBED ARGUMENTS
-    								-> ^(EMBED ARGUMENTS)
     |   URL ARGUMENTS formatOption*   -> ^(URL ARGUMENTS formatOption*)
-    |   LOCAL ARGUMENTS		        -> ^(LOCAL ARGUMENTS)
-    |   CALC ARGUMENTS		        -> ^(CALC ARGUMENTS)
-    |   VAR ARGUMENTS		        -> ^(VAR ARGUMENTS)
+    |   ID ARGUMENTS		        -> ^(ID ARGUMENTS)
     |   FUNCTIONS ARGUMENTS		        -> ^(FUNCTIONS ARGUMENTS)
     |   ALPHA_VALUE
     |   SCALE_VALUE
@@ -565,58 +557,14 @@ AT_WEBKIT_KEYFRAMES : '@-webkit-keyframes' ;
 DOUBLE_COLON : '::' ;
 COLON : ':' ;
 AT_FONT_FACE : '@font-face' ;
-CLASS_REFERENCE : 'ClassReference' ;
-PROPERTY_REFERENCE : 'PropertyReference' ;
 IMPORTANT : '!important' ;
-EMBED : 'Embed' ;
 URL : 'url' ;
 FORMAT : 'format' ;
-LOCAL : 'local' ;
-CALC : 'calc' ;
-SCALE : 'scale' ;
-VAR : 'var' ;
 NULL : 'null' ;
 ONLY : 'only' ;
 CHILD : '>' ;
 PRECEDED : '+' ;
-FUNCTIONS : '-moz-linear-gradient'
-          | '-webkit-linear-gradient'
-          | 'linear-gradient'
-          | 'radial-gradient'
-          | 'conic-gradient'
-          | 'repeating-linear-gradient'
-          | 'repeating-radial-gradient'
-          | 'repeating-conic-gradient'
-          | 'progid:DXImageTransform.Microsoft.gradient'
-          | 'translateX'
-          | 'translateY'
-          | 'translateZ'
-          | 'translate'
-          | 'rotateX'
-          | 'rotateY'
-          | 'rotateZ'
-          | 'scaleX'
-          | 'scaleY'
-          | 'scaleZ'
-          | 'skewX'
-          | 'skewY'
-          | 'skew'
-          | 'perspective'
-          | 'blur'
-          | 'brightness'
-          | 'contrast'
-          | 'drop-shadow'
-          | 'hue-rotate'
-          | 'invert'
-          | 'saturate'
-          | 'sepia'
-          ;
-/*
- * Removed for now this two since conflicts with same keywords in old fucntion
- * This will be fixed later  
- *        | 'grayscale'
- *        | 'opacity'
- */
+FUNCTIONS : 'progid:DXImageTransform.Microsoft.gradient' ;
 
 /** 
  * Matches an alpha filter - alpha(opacity=70)
diff --git a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
index aeacfb8f9..5f9413103 100644
--- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
+++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
@@ -53,6 +53,7 @@ options
 	
 package org.apache.royale.compiler.internal.css;
 
+import java.util.Arrays;
 import java.util.Map;
 import java.util.HashMap;
 import org.apache.royale.compiler.common.ISourceLocation;
@@ -61,12 +62,115 @@ import org.apache.royale.compiler.css.*;
 import org.apache.royale.compiler.problems.CSSParserProblem;
 import org.apache.royale.compiler.problems.ICompilerProblem;
 import org.apache.royale.compiler.problems.CSSStrictFlexSyntaxProblem;
+import org.apache.royale.compiler.problems.CSSUnknownFunctionProblem;
 import org.apache.royale.compiler.problems.CSSUnknownPseudoClassProblem;
 
 }
 
 @members 
 {
+protected static final List<String> STRICT_FUNCTIONS = Arrays.asList("ClassReference", "PropertyReference", "Embed", "url", "local");
+
+protected static final List<String> KNOWN_FUNCTIONS = Arrays.asList(
+    // special Flex functions
+    "ClassReference",
+    "PropertyReference",
+    "Embed",
+
+    // vendor-prefixed browser functions
+    "-moz-linear-gradient",
+    "-webkit-linear-gradient",
+
+    // regular browser functions
+    "acos",
+    "asin",
+    "atan",
+    "atan2",
+    "blur",
+    "brightness",
+    "calc",
+    "circle",
+    "clamp",
+    "color",
+    "color-mix",
+    "conic-gradient",
+    "contrast",
+    "cos",
+    "counter",
+    "counters",
+    "cubic-bezier",
+    "drop-shadow",
+    "ellipse",
+    "env",
+    "exp",
+    "grayscale",
+    "hsl",
+    "hue-rotate",
+    "hwb",
+    "hypot",
+    "image-set",
+    "inset",
+    "invert",
+    "lab",
+    "layer",
+    "lch",
+    "light-dark",
+    "linear",
+    "linear-gradient",
+    "local",
+    "log",
+    "matrix",
+    "matrix3d",
+    "max",
+    "min",
+    "minmax",
+    "mod",
+    "oklab",
+    "oklch",
+    "opacity",
+    "path",
+    "perspective",
+    "polygon",
+    "pow",
+    "radial-gradient",
+    "ray",
+    "rect",
+    "rem",
+    "repeat",
+    "repeating-conic-gradient",
+    "repeating-linear-gradient",
+    "repeating-radial-gradient",
+    "rgb",
+    "rgba",
+    "rotate",
+    "rotate3d",
+    "rotateX",
+    "rotateY",
+    "rotateZ",
+    "round",
+    "saturate",
+    "scale",
+    "scale3d",
+    "scaleX",
+    "scaleY",
+    "scaleZ",
+    "sepia",
+    "sign",
+    "skew",
+    "skewX",
+    "skewY",
+    "sqrt",
+    "steps",
+    "tan",
+    "translate",
+    "translate3d",
+    "translateX",
+    "translateY",
+    "translateZ",
+    "url",
+    "var",
+    "xywh"
+);
 
 /**
  * CSS DOM object.
@@ -136,6 +240,16 @@ public void displayUnknownPseudoClassError(String pseudoClassName, CommonTree tr
         tree.getLine(), tree.getCharPositionInLine());
     problems.add(new CSSUnknownPseudoClassProblem(location, pseudoClassName));
 }
+
+public void displayUnknownFunctionError(String functionName, CommonTree tree)
+{
+    final ISourceLocation location = new SourceLocation(
+        getSourceName(),
+        -1, -1, // TODO Need start and end info from CSS
+        tree.getLine(), tree.getCharPositionInLine());
+    problems.add(new CSSUnknownFunctionProblem(location, functionName));
+}
+
 }
 
 stylesheet
@@ -573,31 +687,19 @@ singleValue returns [CSSPropertyValue propertyValue]
             }
             $propertyValue = new CSSRgbaColorPropertyValue($RGBA.text, $start, tokenStream);
         }
-    |   ^(CLASS_REFERENCE cr=ARGUMENTS)
-        { $propertyValue = new CSSFunctionCallPropertyValue($CLASS_REFERENCE.text, $cr.text, $start, tokenStream); }
-    |   ^(PROPERTY_REFERENCE pr=ARGUMENTS)
-        { $propertyValue = new CSSFunctionCallPropertyValue($PROPERTY_REFERENCE.text, $pr.text, $start, tokenStream); }
-    |   ^(EMBED es=ARGUMENTS)
-        { $propertyValue = new CSSFunctionCallPropertyValue($EMBED.text, $es.text, $start, tokenStream); }
     |   ^(URL url=ARGUMENTS format=formatOption*)
         { $propertyValue = new CSSURLAndFormatPropertyValue($URL.text, $url.text, $format.text, $start, tokenStream); }
-    |   ^(LOCAL l=ARGUMENTS)
-        { $propertyValue = new CSSFunctionCallPropertyValue($LOCAL.text, $l.text, $start, tokenStream); }
-    |   ^(CALC l=ARGUMENTS)
+    |   ^(id=ID args=ARGUMENTS)
         {
-            if (strictFlexCSS)
+            if (strictFlexCSS && !STRICT_FUNCTIONS.contains($id.text))
             {
-                displayStrictFlexSyntaxError($CALC.text, $CALC);
+                displayStrictFlexSyntaxError($id.text, $id);
             }
-            $propertyValue = new CSSFunctionCallPropertyValue($CALC.text, $l.text, $start, tokenStream);
-        }
-    |   ^(VAR l=ARGUMENTS)
-        {
-            if (strictFlexCSS)
+            else if (!KNOWN_FUNCTIONS.contains($id.text))
             {
-                displayStrictFlexSyntaxError($VAR.text, $VAR);
+                displayUnknownFunctionError($id.text, $id);
             }
-            $propertyValue = new CSSFunctionCallPropertyValue($VAR.text, $l.text, $start, tokenStream);
+            $propertyValue = new CSSFunctionCallPropertyValue($id.text, $args.text, $start, tokenStream);
         }
     |   ^(FUNCTIONS l=ARGUMENTS)
         {
diff --git a/compiler/src/main/java/org/apache/royale/compiler/problems/CSSUnknownFunctionProblem.java b/compiler/src/main/java/org/apache/royale/compiler/problems/CSSUnknownFunctionProblem.java
new file mode 100644
index 000000000..80fe5baff
--- /dev/null
+++ b/compiler/src/main/java/org/apache/royale/compiler/problems/CSSUnknownFunctionProblem.java
@@ -0,0 +1,39 @@
+/*
+ *
+ *  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.compiler.problems;
+
+import org.apache.royale.compiler.common.ISourceLocation;
+
+/**
+ * CSS defines a set of valid functions.
+ */
+public final class CSSUnknownFunctionProblem extends CSSProblem
+{
+    public static final String DESCRIPTION =
+        "Unknown CSS value function '${functionName}'";
+
+    public CSSUnknownFunctionProblem(ISourceLocation location, String functionName)
+    {
+        super(location);
+        this.functionName = functionName;
+    }
+    
+    public final String functionName;
+}


(royale-compiler) 02/04: CSS: fix 'not' not being allowed as an identifier by moving the check for it into CSSTree with a new problem class for unknown pseudo-classes in selectors

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 f2de1acef5dfa6ef6a10547cc0d53f4f75a07caa
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 8 09:43:49 2025 -0700

    CSS: fix 'not' not being allowed as an identifier by moving the check for it into CSSTree with a new problem class for unknown pseudo-classes in selectors
    
    This will also make it easier to add new pseudo-classes in the future.
---
 .../org/apache/royale/compiler/internal/css/CSS.g  |  8 ++---
 .../apache/royale/compiler/internal/css/CSSTree.g  | 18 ++++++++--
 .../problems/CSSUnknownPseudoClassProblem.java     | 39 ++++++++++++++++++++++
 compiler/src/test/build.xml                        |  1 +
 4 files changed, 58 insertions(+), 8 deletions(-)

diff --git a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
index 64f295df8..633d412af 100644
--- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
+++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSS.g
@@ -385,8 +385,7 @@ simpleSelectorFraction
 condition
     :   ( DOT^ ID
         | HASH_WORD 
-        | COLON^ NOT ARGUMENTS 
-        | COLON^ ID 
+        | COLON^ ID ARGUMENTS?
         | DOUBLE_COLON^ ID 
         | attributeSelector
         ) 
@@ -612,15 +611,12 @@ FUNCTIONS : '-moz-linear-gradient'
           | 'saturate'
           | 'sepia'
           ;
-/**
+/*
  * Removed for now this two since conflicts with same keywords in old fucntion
  * This will be fixed later  
  *        | 'grayscale'
  *        | 'opacity'
  */
-NOT
-    :  'not'
-    ;
 
 /** 
  * Matches an alpha filter - alpha(opacity=70)
diff --git a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
index 070096355..aeacfb8f9 100644
--- a/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
+++ b/compiler/src/main/antlr3/org/apache/royale/compiler/internal/css/CSSTree.g
@@ -61,6 +61,7 @@ import org.apache.royale.compiler.css.*;
 import org.apache.royale.compiler.problems.CSSParserProblem;
 import org.apache.royale.compiler.problems.ICompilerProblem;
 import org.apache.royale.compiler.problems.CSSStrictFlexSyntaxProblem;
+import org.apache.royale.compiler.problems.CSSUnknownPseudoClassProblem;
 
 }
 
@@ -126,6 +127,15 @@ public void displayStrictFlexSyntaxError(String syntax, CommonTree tree)
         tree.getLine(), tree.getCharPositionInLine());
     problems.add(new CSSStrictFlexSyntaxProblem(location, syntax));
 }
+
+public void displayUnknownPseudoClassError(String pseudoClassName, CommonTree tree)
+{
+    final ISourceLocation location = new SourceLocation(
+        getSourceName(),
+        -1, -1, // TODO Need start and end info from CSS
+        tree.getLine(), tree.getCharPositionInLine());
+    problems.add(new CSSUnknownPseudoClassProblem(location, pseudoClassName));
+}
 }
 
 stylesheet
@@ -351,12 +361,16 @@ conditionSelector
 }
     :   ^(DOT c=ID)   { type = ConditionType.CLASS; name = $c.text; }  
     |   HASH_WORD   { type = ConditionType.ID; name = $HASH_WORD.text.substring(1); }
-    |   ^(COLON NOT arg=ARGUMENTS)
+    |   ^(COLON s=ID arg=ARGUMENTS)
         {
             if (strictFlexCSS)
             {
                 // Flex didn't support the CSS :not() pseudo-class
-                displayStrictFlexSyntaxError($COLON.text + $NOT.text, $NOT);
+                displayStrictFlexSyntaxError($COLON.text + $s.text, $s);
+            }
+            if (!$s.text.equals("not"))
+            {
+                displayUnknownPseudoClassError($s.text, $s);
             }
             type = ConditionType.NOT;
             name = $arg.text;
diff --git a/compiler/src/main/java/org/apache/royale/compiler/problems/CSSUnknownPseudoClassProblem.java b/compiler/src/main/java/org/apache/royale/compiler/problems/CSSUnknownPseudoClassProblem.java
new file mode 100644
index 000000000..5da7ac7bb
--- /dev/null
+++ b/compiler/src/main/java/org/apache/royale/compiler/problems/CSSUnknownPseudoClassProblem.java
@@ -0,0 +1,39 @@
+/*
+ *
+ *  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.compiler.problems;
+
+import org.apache.royale.compiler.common.ISourceLocation;
+
+/**
+ * CSS defines a set of valid pseudo-classes.
+ */
+public final class CSSUnknownPseudoClassProblem extends CSSProblem
+{
+    public static final String DESCRIPTION =
+        "Unknown pseudo-class '${pseudoClassName}' in CSS selector";
+
+    public CSSUnknownPseudoClassProblem(ISourceLocation location, String pseudoClassName)
+    {
+        super(location);
+        this.pseudoClassName = pseudoClassName;
+    }
+    
+    public final String pseudoClassName;
+}
diff --git a/compiler/src/test/build.xml b/compiler/src/test/build.xml
index c5d078e68..f508beb73 100644
--- a/compiler/src/test/build.xml
+++ b/compiler/src/test/build.xml
@@ -318,6 +318,7 @@
             <batchtest todir="${compiler}/target/junit-reports">
                 <fileset dir="${compiler}/target/test-classes">
                     <include name="**/*Tests.class"/>
+                    <!-- <exclude name="as/**"/> -->
                     <exclude name="f/**"/>
                     <exclude name="mxml/tags/**"/>
                     <exclude name="properties/**"/>