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.

source-parser.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Markers } from '../primitives.js';
  2. import { seedTokens, splitSpace, splitCR } from '../util.js';
  3. export default function getParser({ startLine = 0, } = {}) {
  4. let block = null;
  5. let num = startLine;
  6. return function parseSource(source) {
  7. let rest = source;
  8. const tokens = seedTokens();
  9. [tokens.lineEnd, rest] = splitCR(rest);
  10. [tokens.start, rest] = splitSpace(rest);
  11. if (block === null &&
  12. rest.startsWith(Markers.start) &&
  13. !rest.startsWith(Markers.nostart)) {
  14. block = [];
  15. tokens.delimiter = rest.slice(0, Markers.start.length);
  16. rest = rest.slice(Markers.start.length);
  17. [tokens.postDelimiter, rest] = splitSpace(rest);
  18. }
  19. if (block === null) {
  20. num++;
  21. return null;
  22. }
  23. const isClosed = rest.trimRight().endsWith(Markers.end);
  24. if (tokens.delimiter === '' &&
  25. rest.startsWith(Markers.delim) &&
  26. !rest.startsWith(Markers.end)) {
  27. tokens.delimiter = Markers.delim;
  28. rest = rest.slice(Markers.delim.length);
  29. [tokens.postDelimiter, rest] = splitSpace(rest);
  30. }
  31. if (isClosed) {
  32. const trimmed = rest.trimRight();
  33. tokens.end = rest.slice(trimmed.length - Markers.end.length);
  34. rest = trimmed.slice(0, -Markers.end.length);
  35. }
  36. tokens.description = rest;
  37. block.push({ number: num, source, tokens });
  38. num++;
  39. if (isClosed) {
  40. const result = block.slice();
  41. block = null;
  42. return result;
  43. }
  44. return null;
  45. };
  46. }