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 <[email protected]>
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;
+}

Reply via email to