views:

34

answers:

1

Implementing a large JavaScript application with a lot of scripts, its become necessary to put together a build script. JavaScript labels being ubiquitous, I've decided to use them as annotations for a custom script collator. So far, I'm just employing the use statement, like this:

use: com.example.Class;

However, I want to support an 'optional quotes' syntax, so the following would be parsed correctly as well

use: 'com.example.Class';

I'm currently using this pattern to parse the first form:

/\s*use:\s*(\S+);\s*/g

The '\S+' gloms all characters between the annotation name declaration and the terminating semi colon. What rule can I write to substitute for \S+ that will return an annotation value without quotes, no matter if it was quoted or not to begin with? I can do it in two steps, but I want to do it in one.

Thanks- I know I've put this a little awkwardly

Edit 1.

I've been able to use this, but IMHO its a mess- any more elegant solutions? (By the way, this one will parse ALL label names)

/\s*([a-z]+):\s*(?:['])([a-zA-Z0-9_.]+)(?:['])|([a-zA-Z0-9_.]+);/g

Edit 2.

The logic is the same, but expresses a little more succinctly. However, it poses a problem as it seems to pull in all sorts of javascript code as well.

/\s*([a-z]+):\s*'([\w_\.]+)'|([\w_\.]+);/g
A: 

Ok -this seemed to do it. Hope someone can improve on it.

/\s*([a-z]+): *('[\w_\/\.]+'|[\w_\/\.]+);/g
VLostBoy