I'm trying to store some meta data about CSS styles, which our app can use to build menus that allow the user to select those styles (amongst other things).
I thought the JavaDoc style comment was the best approach, and use an attribute like config
or similar. Then store a JSON style definition as the value of that property.
I've been trying to write some RegEx (PHP) to do the following:
- Find all JavaDoc comments with
@config
attribute. - Extract the value of
@config
as the JSON object - Then match the following css TAG and CLASS names if they are defined under it.
So this comment and class definition could be extracted into 3 matches.
/**
* @config {name:'Orange Title', order:1}
*/
h1.title_orange {
}
-
Match 1 :
{name:'Orange Title', order:1}
-
Match 2 :
h1
-
Match 3 :
title_orange
What makes it more complex is the JSON part could be multiline, and the multilines may or may not contain the *
.