-
-
Save subtleGradient/2139456 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': '\\g<inside_round>', | |
'fn_name': '\\g<unicode>', | |
'fn': '\\g<fn_tail>?\\g<fn_name>\\(\\g<fn_arguments>\\)', | |
'block_arguments': '\\g<inside_curly>', | |
'block_body': '\\g<inside_curly>', | |
'block': '\\{\\g<block_arguments>?\\g<block_body>\\}', | |
'double_string': '"((?:[^"]|\\")*)"/', | |
'single_string': "'((?:[^']|\\')*)'", | |
'string': '\\g<double_string>|\\g<single_string>' | |
'whitespace': '\\s+', | |
'comma': ',', | |
'semicolon': ';', | |
'separator': '(\\g<whitespace>|\\g<comma>|\\g<semicolon>)' | |
'index': '\\[\\s*\\g<inside_square>\\s*\\]', | |
'token_tail': '\\.', | |
'token_name': '\\g<unicode>', | |
'token': '\\g<token_tail>?\\g<token_name>', | |
'length_number': '[-+]?(?:\\d+\\.\\d*|\\d*\\.\\d+)' | |
'length_unit': 'em|px|pt|%|fr|deg|(?=$|[^a-zA-Z0-9.])' | |
'length': '\\g<length_number>\\g<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); |
Yeah, perhaps it makes sense to try to follow someone else's syntax. Although \g really adds some mess around to what already is hard to read.
Thanks, i'll keep it in mind and change the subgroups to square brackets thing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is what it would look like using 'Subexp call ("Tanaka Akira special")'.
Cf. http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt #9