Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

name.cjs 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. const util_1 = require("../../util.cjs");
  6. const isQuoted = s => s && s.startsWith('"') && s.endsWith('"');
  7. /**
  8. * Splits remaining `spec.lines[].tokens.description` into `name` and `descriptions` tokens,
  9. * and populates the `spec.name`
  10. */
  11. function nameTokenizer() {
  12. const typeEnd = (num, {
  13. tokens
  14. }, i) => tokens.type === '' ? num : i;
  15. return spec => {
  16. // look for the name in the line where {type} ends
  17. const {
  18. tokens
  19. } = spec.source[spec.source.reduce(typeEnd, 0)];
  20. const source = tokens.description.trimLeft();
  21. const quotedGroups = source.split('"'); // if it starts with quoted group, assume it is a literal
  22. if (quotedGroups.length > 1 && quotedGroups[0] === '' && quotedGroups.length % 2 === 1) {
  23. spec.name = quotedGroups[1];
  24. tokens.name = `"${quotedGroups[1]}"`;
  25. [tokens.postName, tokens.description] = util_1.splitSpace(source.slice(tokens.name.length));
  26. return spec;
  27. }
  28. let brackets = 0;
  29. let name = '';
  30. let optional = false;
  31. let defaultValue; // assume name is non-space string or anything wrapped into brackets
  32. for (const ch of source) {
  33. if (brackets === 0 && util_1.isSpace(ch)) break;
  34. if (ch === '[') brackets++;
  35. if (ch === ']') brackets--;
  36. name += ch;
  37. }
  38. if (brackets !== 0) {
  39. spec.problems.push({
  40. code: 'spec:name:unpaired-brackets',
  41. message: 'unpaired brackets',
  42. line: spec.source[0].number,
  43. critical: true
  44. });
  45. return spec;
  46. }
  47. const nameToken = name;
  48. if (name[0] === '[' && name[name.length - 1] === ']') {
  49. optional = true;
  50. name = name.slice(1, -1);
  51. const parts = name.split('=');
  52. name = parts[0].trim();
  53. if (parts[1] !== undefined) defaultValue = parts.slice(1).join('=').trim();
  54. if (name === '') {
  55. spec.problems.push({
  56. code: 'spec:name:empty-name',
  57. message: 'empty name',
  58. line: spec.source[0].number,
  59. critical: true
  60. });
  61. return spec;
  62. }
  63. if (defaultValue === '') {
  64. spec.problems.push({
  65. code: 'spec:name:empty-default',
  66. message: 'empty default value',
  67. line: spec.source[0].number,
  68. critical: true
  69. });
  70. return spec;
  71. } // has "=" and is not a string, except for "=>"
  72. if (!isQuoted(defaultValue) && /=(?!>)/.test(defaultValue)) {
  73. spec.problems.push({
  74. code: 'spec:name:invalid-default',
  75. message: 'invalid default value syntax',
  76. line: spec.source[0].number,
  77. critical: true
  78. });
  79. return spec;
  80. }
  81. }
  82. spec.optional = optional;
  83. spec.name = name;
  84. tokens.name = nameToken;
  85. if (defaultValue !== undefined) spec.default = defaultValue;
  86. [tokens.postName, tokens.description] = util_1.splitSpace(source.slice(tokens.name.length));
  87. return spec;
  88. };
  89. }
  90. exports.default = nameTokenizer;
  91. //# sourceMappingURL=name.cjs.map