Created
March 19, 2012 23:49
-
-
Save Inviz/2128574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var regexp = LSD.RegExp({ | |
'fn_tail': '\\.', | |
'fn_arguments': 'inside_round', | |
'fn_name': 'unicode', | |
'fn': '(fn_tail)?(fn_name)\\((fn_arguments)\\)', | |
'block_arguments': 'inside_curly', | |
'block_body': 'inside_curly', | |
'block': '\\{(block_arguments)?(block_body)\\}', | |
'double_string': '"((?:[^"]|\\")*)"/', | |
'single_string': "'((?:[^']|\\')*)'", | |
'string': '(double_string)|(single_string)' | |
'whitespace': '\\s+', | |
'comma': ',', | |
'semicolon': ';', | |
'separator': '(whitespace|comma|semicolon)' | |
'index': '\\[\\s*(inside_square)\\s*\\]', | |
'token_tail': '\\.', | |
'token_name': 'unicode', | |
'token': '(token_tail)?(token_name)', | |
'length_number': '[-+]?(?:\\d+\\.\\d*|\\d*\\.\\d+)' | |
'length_unit': 'em|px|pt|%|fr|deg|(?=$|[^a-zA-Z0-9.])' | |
'length': '(length_number)(length_unit)', | |
'operator': '([-+]|[\\/%^~=><*\\^!|&$]+)' | |
}, { | |
fn: function(tail, name, args) { | |
}, | |
block: function(args, body) { | |
}, | |
index: function(content) { | |
}, | |
token: function(name) { | |
}, | |
length: function(number, unit) { | |
}, | |
operator: function(name) { | |
}, | |
separator: function(token) { | |
switch (token) { | |
case ';': | |
break; | |
case ',': | |
break; | |
} | |
} | |
}) | |
var results = regexp.exec(string); |
My idea is that any string can be replaced with another sub-expression, but you might have a point. Adding square brackets is not big of a deal though.
http://xregexp.com/plugins/#unicode is an example of something similar.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice.
I don't like your syntax for nested selectors though.
Check out http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt #9 subexp call.