版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

59 строки
1.3 KiB

  1. const { calculateTokenCharactersRange } = require('../helpers')
  2. const {
  3. TOKEN_COMMENT_END,
  4. TOKEN_COMMENT_CONTENT
  5. } = require('../constants/token-types')
  6. const {
  7. DATA_CONTEXT
  8. } = require('../constants/tokenizer-contexts')
  9. const COMMENT_END = '-->'
  10. function commentEnd (state, tokens) {
  11. const contentRange = calculateTokenCharactersRange(state, { keepBuffer: false })
  12. const commentEndRange = {
  13. startPosition: contentRange.endPosition + 1,
  14. endPosition: contentRange.endPosition + COMMENT_END.length,
  15. }
  16. tokens.push({
  17. type: TOKEN_COMMENT_CONTENT,
  18. content: state.accumulatedContent,
  19. startPosition: contentRange.startPosition,
  20. endPosition: contentRange.endPosition
  21. })
  22. tokens.push({
  23. type: TOKEN_COMMENT_END,
  24. content: state.decisionBuffer,
  25. startPosition: commentEndRange.startPosition,
  26. endPosition: commentEndRange.endPosition
  27. })
  28. state.accumulatedContent = ''
  29. state.decisionBuffer = ''
  30. state.currentContext = DATA_CONTEXT
  31. state.caretPosition++
  32. }
  33. function parseSyntax (chars, state, tokens) {
  34. if (chars === '-' || chars === '--') {
  35. state.caretPosition++
  36. return
  37. }
  38. if (chars === COMMENT_END) {
  39. return commentEnd(state, tokens)
  40. }
  41. state.accumulatedContent += state.decisionBuffer
  42. state.decisionBuffer = ''
  43. state.caretPosition++
  44. }
  45. module.exports = {
  46. parseSyntax
  47. }