Requires
Provides
- License:
- MIT
- Authors:
- Yaroslaff Fedin
- 17
(function(exports) {
- 19
- 20
- 21
- 22
var combineRegExp = (typeof require == 'undefined')
? exports.combineRegExp
: require('./sg-regex-tools').combineRegExp
var SheetParser = exports.SheetParser
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
var Value = SheetParser.Value = {version: '1.0.2 dev'};
Value.translate = function(value) {
var found, result = [], matched = [], scope = result, func, text;
var regex = Value.tokenize;
var names = regex.names;
while (found = regex.exec(value)) matched.push(found);
for (var i = 0; found = matched[i++];) {
if (func = found[names['function']]) {
var obj = {};
var translated = obj[found[names['function']]] = Value.translate(found[names._arguments]);
for (var j = 0, bit; bit = translated[j]; j++) if (bit && bit.length == 1) translated[j] = bit[0];
scope.push(obj);
} else if (found[names.comma]) {
if (!result[0].push) result = [result];
result.push(scope = []);
} else if (found[names.whitespace]) {
var length = scope.length;
if (length && (scope == result) && !scope[length - 1].push) scope = scope[length - 1] = [scope[length - 1]];
} else if (text = (found[names.dstring] || found[names.sstring])) {
scope.push(text)
} else if (text = found[names.token]) {
if (!text.match(Value.hex)) {
var match = Value.length.exec(text);
Value.length.lastIndex = 0;
if (match) {
var number = parseFloat(match[1]);
text = match[2] ? {number: number, unit: match[2]} : number;
} else if (!text.match(Value.keyword)) return false;
}
scope.push(text);
}
}
return result.length == 1 ? result[0] : result;
}
var x = combineRegExp
var OR = '|'
var rRound = "(?:[^()]|\\((?:[^()]|\\((?:[^()]|\\((?:[^()]|\\([^()]*\\))*\\))*\\))*\\))";
;(Value.stringDouble = x(/"((?:[^"]|\\")*)"/)).names = ['dstring']
;(Value.stringSingle = x(/'((?:[^']|\\')*)'/)).names = ['sstring']
;(Value.string = x([Value.stringSingle, OR, Value.stringDouble]))
;(Value.keyword = x(/[-a-zA-Z0-9]+/, "keyword"))
;(Value.token = x(/[^$,\s\/)]+/, "token"))
;(Value['function'] = x("([-a-zA-Z0-9]+)\\((" + rRound + "*)\\)"))
.names = [ 'function', '_arguments']
;(Value.integer = x(/-?\d+/))
;(Value.float = x(/-?\d+\.\d*/))
;(Value.number = x(['(', Value.float, OR, Value.integer, ')']))
.names = [ 'number']
;(Value.unit = x(/em|px|pt|%|fr/, 'unit'))
;(Value.length = x(['^', Value.number, Value.unit, "?$"]))
;(Value.direction = x(/top|left|bottom|right|center/, 'direction'))
;(Value.position = x([Value.length, OR, Value.direction]))
;(Value.hex = x(/#[0-9a-z]+/, 'hex'))
;(Value.comma = x(/\s*,\s*/, 'comma'))
;(Value.whitespace = x(/\s+/, 'whitespace'))
;(Value.slash = x(/\//, 'slash'))
Value.tokenize = x
(
[ x(Value['function']),
, OR
, x(Value.comma)
, OR
, x(Value.whitespace)
, OR
, x(Value.slash)
, OR
, x(Value.string)
, OR
, x(Value.token)
]
)
})(typeof exports != 'undefined' ? exports : this);