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.

factory-destination.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. 'use strict'
  2. var asciiControl = require('../character/ascii-control.js')
  3. var markdownLineEndingOrSpace = require('../character/markdown-line-ending-or-space.js')
  4. var markdownLineEnding = require('../character/markdown-line-ending.js')
  5. // eslint-disable-next-line max-params
  6. function destinationFactory(
  7. effects,
  8. ok,
  9. nok,
  10. type,
  11. literalType,
  12. literalMarkerType,
  13. rawType,
  14. stringType,
  15. max
  16. ) {
  17. var limit = max || Infinity
  18. var balance = 0
  19. return start
  20. function start(code) {
  21. if (code === 60) {
  22. effects.enter(type)
  23. effects.enter(literalType)
  24. effects.enter(literalMarkerType)
  25. effects.consume(code)
  26. effects.exit(literalMarkerType)
  27. return destinationEnclosedBefore
  28. }
  29. if (asciiControl(code) || code === 41) {
  30. return nok(code)
  31. }
  32. effects.enter(type)
  33. effects.enter(rawType)
  34. effects.enter(stringType)
  35. effects.enter('chunkString', {
  36. contentType: 'string'
  37. })
  38. return destinationRaw(code)
  39. }
  40. function destinationEnclosedBefore(code) {
  41. if (code === 62) {
  42. effects.enter(literalMarkerType)
  43. effects.consume(code)
  44. effects.exit(literalMarkerType)
  45. effects.exit(literalType)
  46. effects.exit(type)
  47. return ok
  48. }
  49. effects.enter(stringType)
  50. effects.enter('chunkString', {
  51. contentType: 'string'
  52. })
  53. return destinationEnclosed(code)
  54. }
  55. function destinationEnclosed(code) {
  56. if (code === 62) {
  57. effects.exit('chunkString')
  58. effects.exit(stringType)
  59. return destinationEnclosedBefore(code)
  60. }
  61. if (code === null || code === 60 || markdownLineEnding(code)) {
  62. return nok(code)
  63. }
  64. effects.consume(code)
  65. return code === 92 ? destinationEnclosedEscape : destinationEnclosed
  66. }
  67. function destinationEnclosedEscape(code) {
  68. if (code === 60 || code === 62 || code === 92) {
  69. effects.consume(code)
  70. return destinationEnclosed
  71. }
  72. return destinationEnclosed(code)
  73. }
  74. function destinationRaw(code) {
  75. if (code === 40) {
  76. if (++balance > limit) return nok(code)
  77. effects.consume(code)
  78. return destinationRaw
  79. }
  80. if (code === 41) {
  81. if (!balance--) {
  82. effects.exit('chunkString')
  83. effects.exit(stringType)
  84. effects.exit(rawType)
  85. effects.exit(type)
  86. return ok(code)
  87. }
  88. effects.consume(code)
  89. return destinationRaw
  90. }
  91. if (code === null || markdownLineEndingOrSpace(code)) {
  92. if (balance) return nok(code)
  93. effects.exit('chunkString')
  94. effects.exit(stringType)
  95. effects.exit(rawType)
  96. effects.exit(type)
  97. return ok(code)
  98. }
  99. if (asciiControl(code)) return nok(code)
  100. effects.consume(code)
  101. return code === 92 ? destinationRawEscape : destinationRaw
  102. }
  103. function destinationRawEscape(code) {
  104. if (code === 40 || code === 41 || code === 92) {
  105. effects.consume(code)
  106. return destinationRaw
  107. }
  108. return destinationRaw(code)
  109. }
  110. }
  111. module.exports = destinationFactory