Skip to content

Instantly share code, notes, and snippets.

@Inviz
Created March 19, 2012 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Inviz/2128574 to your computer and use it in GitHub Desktop.
Save Inviz/2128574 to your computer and use it in GitHub Desktop.
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);
@subtleGradient
Copy link

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.

@Inviz
Copy link
Author

Inviz commented Mar 20, 2012

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.

@subtleGradient
Copy link

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