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.

index.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { splitLines } from '../util.js';
  2. import blockParser from './block-parser.js';
  3. import sourceParser from './source-parser.js';
  4. import specParser from './spec-parser.js';
  5. import tokenizeTag from './tokenizers/tag.js';
  6. import tokenizeType from './tokenizers/type.js';
  7. import tokenizeName from './tokenizers/name.js';
  8. import tokenizeDescription, { getJoiner as getDescriptionJoiner, } from './tokenizers/description.js';
  9. export default function getParser({ startLine = 0, fence = '```', spacing = 'compact', tokenizers = [
  10. tokenizeTag(),
  11. tokenizeType(spacing),
  12. tokenizeName(),
  13. tokenizeDescription(spacing),
  14. ], } = {}) {
  15. if (startLine < 0 || startLine % 1 > 0)
  16. throw new Error('Invalid startLine');
  17. const parseSource = sourceParser({ startLine });
  18. const parseBlock = blockParser({ fence });
  19. const parseSpec = specParser({ tokenizers });
  20. const joinDescription = getDescriptionJoiner(spacing);
  21. const notEmpty = (line) => line.tokens.description.trim() != '';
  22. return function (source) {
  23. const blocks = [];
  24. for (const line of splitLines(source)) {
  25. const lines = parseSource(line);
  26. if (lines === null)
  27. continue;
  28. if (lines.find(notEmpty) === undefined)
  29. continue;
  30. const sections = parseBlock(lines);
  31. const specs = sections.slice(1).map(parseSpec);
  32. blocks.push({
  33. description: joinDescription(sections[0]),
  34. tags: specs,
  35. source: lines,
  36. problems: specs.reduce((acc, spec) => acc.concat(spec.problems), []),
  37. });
  38. }
  39. return blocks;
  40. };
  41. }