Is the CSS parser malfunctioning?

My program is designed to scan css files using the jar cssparser-0.9.5.jar and perform various operations on the data.

public static Map<String, CSSStyleRule> parseCSS(String FileName) throws IOException {
        Map<String, CSSStyleRule> rules = new LinkedHashMap<String, CSSStyleRule>();
        InputSource inputSource = new InputSource(
                new FileReader(FileName));
        CSSStyleSheet styleSheet = new CSSOMParser().parseStyleSheet(
                inputSource, null, null);

        CSSRuleList ruleList = styleSheet.getCssRules();
        for (int i = 0; i < ruleList.getLength(); i++) {
            CSSRule rule = ruleList.item(i);
            if (rule.getType() == CSSRule.STYLE_RULE) {
                CSSStyleRule styleRule = (CSSStyleRule) rule;
                rules.put(styleRule.getSelectorText(), styleRule);
            }
        }

        return rules;
    }

While the code performs well for most classes, there is an issue with classes that have properties starting with '-' such as in the following example:

.overlay
{
    filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
}

After parsing, it generates an error due to the presence of double ':' in the .overlay class's properties. Any ideas on how to solve this problem?

Answer №1

The issue highlighted in your code is not at the root level, but rather within the lexical scanner itself. The identifier definition (IDENT) appears to be incorrect as it allows for hyphens and permits identifiers to begin with hyphens.

According to the CSS3 syntax specification:

CSS3 restricts identifiers (such as element names, classes, and IDs in selectors) to only include [A-Za-z0-9] characters, ISO 10646 characters 161 and above, along with hyphens (-) and underscores (_); they must not commence with a digit or a hyphen followed by a digit.

You can find the detailed specification here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Selectize-dropdown menu shines brightly as it opens upwards

In my sleek dashboard design, I have implemented a few dropdown menus using selectizeInput. These menus are currently positioned at the bottom of the page, but I want them to open in an upward direction instead of downward. While I found a workaround for ...

Utilizing the Increment Unary Operator Alongside Map Retrieval in Java

Why does the ++ operator not work with the map.get() function when extracting an Integer value from a Map and placing it into a new int variable with one added to it? For example, int foo = map.get(key)++; To bypass this limitation, I utilized the followi ...

When the user clicks on the login text field or password field, any existing text will

Currently, I am working on the login section of my website and I would like to implement a similar effect to Twitter's login form, where the Username and Password values disappear when the Textfield and Password field are in focus. I have attempted to ...

What is the best way to implement backup style attributes for a React JS component?

Is there a method to implement fallback style properties for a component? For example: var inlineStyle = { display: '-webkit-box', display: '-webkit-flex', display: '-moz-box', display: '-moz-flex', ...

Center text inside a d3 svg element

As a newcomer to the d3 library, I am facing challenges with a basic task. Inspired by this example on gradients, I have integrated a linear gradient into the footer div element: #footer { position: absolute; z-index: 10; bottom: 10 ...

Use Javascript to deactivate the mouse cursor and rely solely on the keyboard cursor for navigation

I am facing an issue with a div that contains a textarea. The cursor is automatically positioned at the beginning of the text within the textarea. I would like to disable the mouse cursor when hovering over the textarea but still be able to navigate within ...

`Text-overflow ellipsis should function consistently across both Firefox and Chrome browsers`

A design has been created to showcase captions for articles and their respective statuses. The article name box has a fixed width, with text-overflow:ellipsis applied to trim excessively long names. Additionally, a light grey dotted line is added at the en ...

Issue with Font Requests in Browsers when Using Angular 10 and SCSS with @font-face

I have a project built with Angular 10 that utilizes SCSS for styling. In my _typography.scss file, I have defined some @font-face rules pointing to the font files located in the assets/fonts directory. However, when I run the application, the browser does ...

Using float instead of CSS inline-block is more effective for styling a PHP element

I've been working on styling a page that was generated with App Gini. While I have been successful in editing most elements so far, I am facing an issue with getting inline-block to work properly. Although float:left is functioning correctly, I would ...

Using jQuery to update the CSS class for all li icons except for the one that is currently selected

Utilizing Font Awesome Icons within the li elements of a ul Challenge When a user clicks on the user icon, the color changes from black to yellow. If the user clicks on another icon, that one also turns yellow. Is there a way to remove the existing yell ...

Google Extension PHP Plugin

Is it feasible to integrate a PHP file into a Google Extension for Chrome? I've been exploring the idea of creating an extension and most resources only mention HTML, CSS, and JavaScript. Any guidance on using PHP in the extension would be highly valu ...

Struggling to grasp the concept of Vue3 style binding

While browsing the Vue website, I came across a particular example that left me puzzled. Inside the <script> section, there is this code: const color = ref('green') function toggleColor() { color.value = color.value === 'green' ...

Comparing C/C++ Structs to Java: What's the Difference?

I'm currently working on a C code and only have basic knowledge of Java. I'm wondering if there is a way to create a similar structure in Java like the code below. I believe we can achieve this using a Java class, but the challenge I'm enco ...

When the state changes, initiate the animation

Currently, I am working with Vue.js and need to animate a navigation menu. My goal is to display two li elements when a user hovers over one of the navigation buttons. At the moment, I have set the data type showActivities to false by default and changed ...

Full height Footer using Flash and HTML

Seeking advice: I successfully implemented a Flash object with 100% height and width on an HTML page. However, I am struggling to add an HTML footer that stays fixed at the bottom of the page. Attempts made: I have tried various solutions, searched on Go ...

Is there a way to temporarily toggle classes with jQuery?

Incorporating ZeroClipboard, I have implemented the following code to alter the text and class of my 'copy to clipboard button' by modifying the innerHTML. Upon clicking, this triggers a smooth class transition animation. client.on( "complete", ...

What is the best way to retrieve text that is viewable to the user when there is a text overflow situation

When using ellipsis in a text input to indicate overflow, is there a way to determine what text is visible to the user versus hidden behind the ellipsis? Thank you for any help! https://i.stack.imgur.com/8iLBQ.png In my scenario, I need to display a list ...

Innovative: Enhancing column width dynamically without compromising grid integrity

Currently, I am utilizing Bourbon's Neat library to structure my grid system. Within my code, I have the following setup: section { @include outer-container; aside { @include span-columns(3); } article { @include span-columns(9); } } The chal ...

Several treeviews for selecting data

I need some help with a specific assignment. The back end code is all set, but I'm struggling with the UI component. The task requires two tree views, one on the left and one on the right. The left tree view will contain states with multiple children, ...

Making all elements the same height in rows with w3.css

Struggling to achieve equal height for the elements in my rows. Any suggestions on how to make this work? Thank you and cheers. <div class="w3-row"> <div class="w3-container w3-quarter w3-green text-center matrix-element"> < ...