Requires

Provides

License:
MIT
Authors:
Yaroslaff Fedin
  1. 17
(function(exports) {

  1. 19
  2. 20
  3. 21
  4. 22
var combineRegExp = (typeof require == 'undefined') ? exports.combineRegExp : require('./sg-regex-tools').combineRegExp var SheetParser = exports.SheetParser

  1. 25
var Property = SheetParser.Property = {version: '0.2 dev'};

Finds optional groups in expressions and builds keyword indecies for them. Keyword index is an object that has keywords as keys and values as property names.

Index only holds keywords that can be uniquely identified as one of the properties in group.

  1. 36
  2. 37
  3. 38
  4. 39
  5. 40
  6. 41
  7. 42
  8. 43
  9. 44
  10. 45
  11. 46
  12. 47
  13. 48
  14. 49
  15. 50
  16. 51
  17. 52
Property.index = function(properties, context) { var index = {}; for (var i = 0, property; property = properties[i]; i++) { if (property.push) { var group = index[i] = {}; for (var j = 0, prop; prop = property[j]; j++) { var keys = context[prop].keywords; if (keys) for (var key in keys) { if (group[key] == null) group[key] = prop; else group[key] = false; } } for (var keyword in group) if (!group[keyword]) delete group[keyword]; } } return index; };

Simple value

  1. 58
  2. 59
  3. 60
  4. 61
  5. 62
  6. 63
  7. 64
Property.simple = function(types, keywords) { return function(value) { if (keywords && keywords[value]) return true; if (types) for (var i = 0, type; type = types[i++];) if (Type[type](value)) return true; return false; } };

Links list of inambigous arguments with corresponding properties keeping the order.

  1. 71
  2. 72
  3. 73
  4. 74
  5. 75
  6. 76
  7. 77
  8. 78
  9. 79
  10. 80
  11. 81
  12. 82
  13. 83
  14. 84
  15. 85
  16. 86
  17. 87
  18. 88
  19. 89
  20. 90
  21. 91
  22. 92
  23. 93
  24. 94
  25. 95
  26. 96
  27. 97
  28. 98
  29. 99
  30. 100
  31. 101
  32. 102
  33. 103
  34. 104
  35. 105
  36. 106
  37. 107
  38. 108
  39. 109
  40. 110
  41. 111
  42. 112
  43. 113
  44. 114
  45. 115
  46. 116
Property.shorthand = function(properties, keywords, context) { var index, r = 0; for (var i = 0, property; property = properties[i++];) if (!property.push) r++; return function() { var result = [], used = {}, start = 0, group, k = 0, l = arguments.length; for (var i = 0, argument; argument = arguments[i]; i++) { var property = properties[k]; if (!property) return false; if ((group = (property.push && property))) property = properties[k + 1]; if (property) { if (context[property](argument)) k++ else property = false } if (group) { if (!property) { if (!index) index = Property.index(properties, context) if (property = index[k][argument]) if (used[property]) return false; else used[property] = 1; } if ((property && !used[property]) || (i == l - 1)) { if (i - start > group.length) return false; for (var j = start; j < (i + +!property); j++) if (!result[j]) for (var m = 0, optional; optional = group[m++];) { if (!used[optional] && context[optional](arguments[j])) { result[j] = optional; used[optional] = true break; } } start = i; k++; } } if (result[i] == null) result[i] = property; } if (i < r) return false for (var i = 0, j = arguments.length, object = {}; i < j; i++) { var value = result[i]; if (!value) return false; object[value] = arguments[i]; } return object; }; }

A shorthand that operates on collection of properties. When given values are not enough (less than properties in collection), the value sequence is repeated until all properties are filled.

  1. 124
  2. 125
  3. 126
  4. 127
  5. 128
  6. 129
  7. 130
  8. 131
  9. 132
  10. 133
  11. 134
  12. 135
  13. 136
  14. 137
  15. 138
  16. 139
  17. 140
  18. 141
  19. 142
  20. 143
  21. 144
  22. 145
  23. 146
  24. 147
  25. 148
  26. 149
Property.collection = function(properties, keywords, context) { var first = context[properties[0]]; if (first.type != 'simple') return function(arg) { var args = (!arg || !arg.push) ? [Array.prototype.slice.call(arguments)] : arguments; var length = args.length; var result = {}; for (var i = 0, property; property = properties[i]; i++) { var values = context[property].apply(1, args[i] || args[i % 2] || args[0]); if (!values) return false; for (var prop in values) result[prop] = values[prop]; } return result; } else return function() { var length = arguments.length; var result = {}; for (var i = 0, property; property = properties[i]; i++) { var values = arguments[i] || arguments[i % 2] || arguments[0]; if (!context[property].call(1, values)) return false; result[property] = values; } return result; } };

Multiple value property accepts arrays as arguments as well as regular stuff

  1. 156
Property.multiple = function(arg) {

if (arg.push)

  1. 158
  2. 159
  3. 160
  4. 161
  5. 162
  6. 163
  7. 164
  8. 165
  9. 166
  10. 167
  11. 168
  12. 169
  13. 170
  14. 171
  15. 172
  16. 173
  17. 174
  18. 175
  19. 176
  20. 177
  21. 178
  22. 179
  23. 180
  24. 181
  25. 182
  26. 183
  27. 184
  28. 185
  29. 186
  30. 187
  31. 188
  32. 189
  33. 190
  34. 191
  35. 192
  36. 193
  37. 194
  38. 195
  39. 196
  40. 197
  41. 198
  42. 199
  43. 200
  44. 201
  45. 202
  46. 203
  47. 204
  48. 205
  49. 206
  50. 207
  51. 208
  52. 209
  53. 210
  54. 211
  55. 212
  56. 213
  57. 214
  58. 215
  59. 216
  60. 217
  61. 218
  62. 219
  63. 220
  64. 221
  65. 222
  66. 223
  67. 224
  68. 225
  69. 226
  70. 227
  71. 228
} Property.compile = function(definition, context) { var properties, keywords, types; for (var i = 0, bit; bit = definition[i++];) { if (bit.push) properties = bit; else if (bit.indexOf) { if (!Type[bit]) { if (!keywords) keywords = {}; keywords[bit] = 1; } else types ? types.push(bit) : (types = [bit]); } else options = bit; } var type = properties ? (keywords && keywords.collection ? "collection" : "shorthand") : 'simple' var property = Property[type](properties || types, keywords, context); if (keywords) property.keywords = keywords; if (properties) { var props = []; for (var i = 0, prop; prop = properties[i++];) prop.push ? props.push.apply(props, prop) : props.push(prop); property.properties = props; } property.type = type; return property; }; var Type = Property.Type = { length: function(obj) { return typeof obj == 'number' || (!obj.indexOf && ('number' in obj) && obj.unit && (obj.unit != '%')) }, color: function(obj) { return obj.indexOf ? obj.match(/^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/) : (obj.isColor || obj.rgba || obj.rgb || obj.hsb) }, number: function(obj) { return typeof obj == 'number' }, integer: function(obj) { return obj % 1 == 0 && ((0 + obj).toString() == obj) }, keyword: function(keywords) { var storage; for (var i = 0, keyword; keyword = keywords[i++];) storage[keyword] = 1; return function(keyword) { return !!storage[keyword] } }, strings: function(obj) { return !!obj.indexOf }, url: function(obj) { return !obj.indexOf && ("url" in obj); }, position: function(obj) { var positions = Type.position.positions; if (!positions) positions = Type.position.positions = {left: 1, top: 1, bottom: 1, right: 1, center: 1} return positions[obj] }, percentage: function(obj) { return obj.unit == '%' } }; })(typeof exports != 'undefined' ? exports : this);