flow.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict'
  2. Object.defineProperty(exports, '__esModule', {value: true})
  3. var assert = require('assert')
  4. var codes = require('../character/codes.js')
  5. var markdownLineEnding = require('../character/markdown-line-ending.js')
  6. var types = require('../constant/types.js')
  7. var content = require('../tokenize/content.js')
  8. var factorySpace = require('../tokenize/factory-space.js')
  9. var partialBlankLine = require('../tokenize/partial-blank-line.js')
  10. function _interopDefaultLegacy(e) {
  11. return e && typeof e === 'object' && 'default' in e ? e : {default: e}
  12. }
  13. var assert__default = /*#__PURE__*/ _interopDefaultLegacy(assert)
  14. var tokenize = initializeFlow
  15. function initializeFlow(effects) {
  16. var self = this
  17. var initial = effects.attempt(
  18. // Try to parse a blank line.
  19. partialBlankLine,
  20. atBlankEnding,
  21. // Try to parse initial flow (essentially, only code).
  22. effects.attempt(
  23. this.parser.constructs.flowInitial,
  24. afterConstruct,
  25. factorySpace(
  26. effects,
  27. effects.attempt(
  28. this.parser.constructs.flow,
  29. afterConstruct,
  30. effects.attempt(content, afterConstruct)
  31. ),
  32. types.linePrefix
  33. )
  34. )
  35. )
  36. return initial
  37. function atBlankEnding(code) {
  38. assert__default['default'](
  39. code === codes.eof || markdownLineEnding(code),
  40. 'expected eol or eof'
  41. )
  42. if (code === codes.eof) {
  43. effects.consume(code)
  44. return
  45. }
  46. effects.enter(types.lineEndingBlank)
  47. effects.consume(code)
  48. effects.exit(types.lineEndingBlank)
  49. self.currentConstruct = undefined
  50. return initial
  51. }
  52. function afterConstruct(code) {
  53. assert__default['default'](
  54. code === codes.eof || markdownLineEnding(code),
  55. 'expected eol or eof'
  56. )
  57. if (code === codes.eof) {
  58. effects.consume(code)
  59. return
  60. }
  61. effects.enter(types.lineEnding)
  62. effects.consume(code)
  63. effects.exit(types.lineEnding)
  64. self.currentConstruct = undefined
  65. return initial
  66. }
  67. }
  68. exports.tokenize = tokenize