sets.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. var types = require('./types');
  2. var INTS = function() {
  3. return [{ type: types.RANGE , from: 48, to: 57 }];
  4. };
  5. var WORDS = function() {
  6. return [
  7. { type: types.CHAR, value: 95 },
  8. { type: types.RANGE, from: 97, to: 122 },
  9. { type: types.RANGE, from: 65, to: 90 }
  10. ].concat(INTS());
  11. };
  12. var WHITESPACE = function() {
  13. return [
  14. { type: types.CHAR, value: 9 },
  15. { type: types.CHAR, value: 10 },
  16. { type: types.CHAR, value: 11 },
  17. { type: types.CHAR, value: 12 },
  18. { type: types.CHAR, value: 13 },
  19. { type: types.CHAR, value: 32 },
  20. { type: types.CHAR, value: 160 },
  21. { type: types.CHAR, value: 5760 },
  22. { type: types.CHAR, value: 6158 },
  23. { type: types.CHAR, value: 8192 },
  24. { type: types.CHAR, value: 8193 },
  25. { type: types.CHAR, value: 8194 },
  26. { type: types.CHAR, value: 8195 },
  27. { type: types.CHAR, value: 8196 },
  28. { type: types.CHAR, value: 8197 },
  29. { type: types.CHAR, value: 8198 },
  30. { type: types.CHAR, value: 8199 },
  31. { type: types.CHAR, value: 8200 },
  32. { type: types.CHAR, value: 8201 },
  33. { type: types.CHAR, value: 8202 },
  34. { type: types.CHAR, value: 8232 },
  35. { type: types.CHAR, value: 8233 },
  36. { type: types.CHAR, value: 8239 },
  37. { type: types.CHAR, value: 8287 },
  38. { type: types.CHAR, value: 12288 },
  39. { type: types.CHAR, value: 65279 }
  40. ];
  41. };
  42. var NOTANYCHAR = function() {
  43. return [
  44. { type: types.CHAR, value: 10 },
  45. { type: types.CHAR, value: 13 },
  46. { type: types.CHAR, value: 8232 },
  47. { type: types.CHAR, value: 8233 },
  48. ];
  49. };
  50. // Predefined class objects.
  51. exports.words = function() {
  52. return { type: types.SET, set: WORDS(), not: false };
  53. };
  54. exports.notWords = function() {
  55. return { type: types.SET, set: WORDS(), not: true };
  56. };
  57. exports.ints = function() {
  58. return { type: types.SET, set: INTS(), not: false };
  59. };
  60. exports.notInts = function() {
  61. return { type: types.SET, set: INTS(), not: true };
  62. };
  63. exports.whitespace = function() {
  64. return { type: types.SET, set: WHITESPACE(), not: false };
  65. };
  66. exports.notWhitespace = function() {
  67. return { type: types.SET, set: WHITESPACE(), not: true };
  68. };
  69. exports.anyChar = function() {
  70. return { type: types.SET, set: NOTANYCHAR(), not: true };
  71. };