You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "matthiasblaesing (via GitHub)" <gi...@apache.org> on 2023/02/04 22:52:05 UTC

[GitHub] [netbeans] matthiasblaesing opened a new pull request, #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

matthiasblaesing opened a new pull request, #5432:
URL: https://github.com/apache/netbeans/pull/5432

   **Support recursive CSS property definitions (calc function with embedded function calls)**
   
   The grammar for calc property values failed to parse embedded var and
   calc calls correctly. The issue is the work-around introduces as
   function-content, which basicly prevents nesting any expression that
   contains braces.
   
   This changes the grammar parsing result from a tree to a directed graph,
   which can contain cycles. This needs to taken into account by useers of
   the parsed grammar.
   
   An example of such a cycle is:
   
   ```
   calc-fn -> calc-sum -> calc-product -> calc-value -> calc-sum
                 ^                                        |
                 +----------------------------------------+
   ```
   
   For example this is now supported:
   
   ```css
   .header {
     height: calc(28 * var(--spacing-unit));
   }
   ```
   
   **Improve compatibility for custom properties**
   
   Custom properties can hold more or less arbitrary content. This was not parsed and is now:
   
   ```css
   :root {
     --grid-gutter: (var(--margins) * var(--spacing-unit));
     --cell-margin: (var(--grid-gutter) / 2);
   }
   ```
   
   **Support CSS :has pseudo-class**
   
   This was not parsed and is now:
   
   ```css
   body:has(+ #aCheck:checked) {
       background-color:red;
   }
   ```
   
   Closes: #5052
   Closes: #5303
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] vieiro commented on a diff in pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "vieiro (via GitHub)" <gi...@apache.org>.
vieiro commented on code in PR #5432:
URL: https://github.com/apache/netbeans/pull/5432#discussion_r1096735306


##########
ide/css.lib/src/org/netbeans/modules/css/lib/properties/GrammarParser.java:
##########
@@ -372,4 +386,59 @@ public CharSequence readText() {
             return text.subSequence(0, pos);
         }
     }
+
+    private static class PropertyGrammarElementRef {
+        private final GrammarElement parent;
+        private final int index;
+        private final String propertyName;
+
+        public PropertyGrammarElementRef(GrammarElement parent, int index, String propertyName) {
+            this.parent = parent;
+            this.index = index;
+            this.propertyName = propertyName;
+        }
+
+        @Override
+        public int hashCode() {
+            int hash = 7;
+            hash = 29 * hash + this.index;
+            hash = 29 * hash + Objects.hashCode(this.propertyName);
+            return hash;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            final PropertyGrammarElementRef other = (PropertyGrammarElementRef) obj;
+            if (this.index != other.index) {
+                return false;
+            }
+            if (!Objects.equals(this.propertyName, other.propertyName)) {
+                return false;
+            }
+            return truncatedPath(this.parent).equals(truncatedPath(other.parent));
+        }
+
+        @SuppressWarnings("AssignmentToMethodParameter")
+        private String truncatedPath(GrammarElement parent) {
+            StringBuilder path = new StringBuilder();
+            while(parent != null) {
+                path.append(parent.getName());
+                path.append("/");
+                if(parent.getName() != null) {

Review Comment:
   This `if (parent.getName() != null) {` shouldn't it be two lines above? Or do we want `path.append(parent.getName());` even if `parent.getName()` is null?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] vieiro commented on pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "vieiro (via GitHub)" <gi...@apache.org>.
vieiro commented on PR #5432:
URL: https://github.com/apache/netbeans/pull/5432#issuecomment-1418259926

   > @vieiro thank you for the review. I pushed updates - could you have another look?
   
   @matthiasblaesing Great job. Thanks again for this!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on a diff in pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on code in PR #5432:
URL: https://github.com/apache/netbeans/pull/5432#discussion_r1096797911


##########
ide/css.lib/src/org/netbeans/modules/css/lib/api/properties/Properties.java:
##########
@@ -144,24 +146,26 @@ public static boolean isAggregatedProperty(FileObject context, PropertyDefinitio
         final GroupGrammarElement grammarElement = propertyDefinition.getGrammarElement(context);
         final AtomicBoolean isAggregated = new AtomicBoolean(false);
         grammarElement.accept(new GrammarElementVisitor() {
-            private boolean cancelled = false;
+            private final Map<GroupGrammarElement,Void> seen = new IdentityHashMap<>();

Review Comment:
   Addressed via https://github.com/apache/netbeans/pull/5432/commits/e2dd93481e809985df55c138448cbaaf0ab75f4b
   Learned something new here - thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on a diff in pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on code in PR #5432:
URL: https://github.com/apache/netbeans/pull/5432#discussion_r1096798104


##########
ide/css.lib/src/org/netbeans/modules/css/lib/properties/GrammarParser.java:
##########
@@ -372,4 +386,59 @@ public CharSequence readText() {
             return text.subSequence(0, pos);
         }
     }
+
+    private static class PropertyGrammarElementRef {
+        private final GrammarElement parent;
+        private final int index;
+        private final String propertyName;
+
+        public PropertyGrammarElementRef(GrammarElement parent, int index, String propertyName) {
+            this.parent = parent;
+            this.index = index;
+            this.propertyName = propertyName;
+        }
+
+        @Override
+        public int hashCode() {
+            int hash = 7;
+            hash = 29 * hash + this.index;
+            hash = 29 * hash + Objects.hashCode(this.propertyName);
+            return hash;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            final PropertyGrammarElementRef other = (PropertyGrammarElementRef) obj;
+            if (this.index != other.index) {
+                return false;
+            }
+            if (!Objects.equals(this.propertyName, other.propertyName)) {
+                return false;
+            }
+            return truncatedPath(this.parent).equals(truncatedPath(other.parent));
+        }
+
+        @SuppressWarnings("AssignmentToMethodParameter")
+        private String truncatedPath(GrammarElement parent) {
+            StringBuilder path = new StringBuilder();
+            while(parent != null) {
+                path.append(parent.getName());
+                path.append("/");
+                if(parent.getName() != null) {

Review Comment:
   Yes implementation of `PropertyGrammarElementRef` was bogus. Addressed via:
   https://github.com/apache/netbeans/pull/5432/commits/ecd64eee0b30d600967c751cae5281cf842daa1a



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] vieiro commented on a diff in pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "vieiro (via GitHub)" <gi...@apache.org>.
vieiro commented on code in PR #5432:
URL: https://github.com/apache/netbeans/pull/5432#discussion_r1096735730


##########
ide/css.visual/src/org/netbeans/modules/css/visual/RuleEditorNode.java:
##########
@@ -595,15 +596,29 @@ private PropertyValuesEditor createPropertyValueEditor(FileObject context, Prope
             GroupGrammarElement rootElement = pmodel.getGrammarElement(context);
 
             rootElement.accept(new GrammarElementVisitor() {
+                private Map<GroupGrammarElement,Void> seen = new IdentityHashMap<>();
+

Review Comment:
   It's fine, as in comment above we could also use a map for cleaner semantics.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on a diff in pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on code in PR #5432:
URL: https://github.com/apache/netbeans/pull/5432#discussion_r1096797903


##########
ide/css.visual/src/org/netbeans/modules/css/visual/RuleEditorNode.java:
##########
@@ -595,15 +596,29 @@ private PropertyValuesEditor createPropertyValueEditor(FileObject context, Prope
             GroupGrammarElement rootElement = pmodel.getGrammarElement(context);
 
             rootElement.accept(new GrammarElementVisitor() {
+                private Map<GroupGrammarElement,Void> seen = new IdentityHashMap<>();
+

Review Comment:
   Addressed via https://github.com/apache/netbeans/pull/5432/commits/e2dd93481e809985df55c138448cbaaf0ab75f4b



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on a diff in pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on code in PR #5432:
URL: https://github.com/apache/netbeans/pull/5432#discussion_r1096733434


##########
ide/css.lib/src/org/netbeans/modules/css/lib/Css3.g:
##########
@@ -36,6 +36,9 @@
 //    from the module directory (ide/css.lib)
 // 3. Rerun unittests
 // 4. Commit Css3.g together with generated Css3Lexer.java and Css3Parser.java
+//

Review Comment:
   I'm inclined to agree, however I quote:
   
   ```
   // This grammar is free to use providing you retain everyhting in this header comment
   // section.
   ```
   
   so I let it stand as is. Lines 19+ I think spell it out, that this is a modified version.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing merged pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing merged PR #5432:
URL: https://github.com/apache/netbeans/pull/5432


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] vieiro commented on a diff in pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "vieiro (via GitHub)" <gi...@apache.org>.
vieiro commented on code in PR #5432:
URL: https://github.com/apache/netbeans/pull/5432#discussion_r1096734291


##########
ide/css.lib/src/org/netbeans/modules/css/lib/api/properties/Properties.java:
##########
@@ -144,24 +146,26 @@ public static boolean isAggregatedProperty(FileObject context, PropertyDefinitio
         final GroupGrammarElement grammarElement = propertyDefinition.getGrammarElement(context);
         final AtomicBoolean isAggregated = new AtomicBoolean(false);
         grammarElement.accept(new GrammarElementVisitor() {
-            private boolean cancelled = false;
+            private final Map<GroupGrammarElement,Void> seen = new IdentityHashMap<>();

Review Comment:
   It's ok. Maybe`Collections.newSetFromMap(new IdentityHashMap<>()) `  makes things clearer below (`seen.contains`, `seen.add`, etc.)?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] vieiro commented on a diff in pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "vieiro (via GitHub)" <gi...@apache.org>.
vieiro commented on code in PR #5432:
URL: https://github.com/apache/netbeans/pull/5432#discussion_r1096732685


##########
ide/css.lib/src/org/netbeans/modules/css/lib/Css3.g:
##########
@@ -36,6 +36,9 @@
 //    from the module directory (ide/css.lib)
 // 3. Rerun unittests
 // 4. Commit Css3.g together with generated Css3Lexer.java and Css3Parser.java
+//

Review Comment:
   At the top of this file there's a line like this:
   ```
   Author : Jim Idle, Temporal Wave LLC.
   ```
   We may want to add an additional author there (be it Matthias or the NetBeans team or something). After all we don't want Jim Idle to be blamed by our sins... ;-) 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] matthiasblaesing commented on pull request #5432: CSS: Support recursive calc definition, improve compatibility for custom properties, support :has pseudo-class

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #5432:
URL: https://github.com/apache/netbeans/pull/5432#issuecomment-1418250554

   @vieiro thank you for the review. I pushed updates - could you have another look?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists