版博士V2.0程序
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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const {
  2. TOKEN_COMMENT_START,
  3. TOKEN_COMMENT_END,
  4. TOKEN_COMMENT_CONTENT
  5. } = require('../constants/token-types')
  6. function handleCommentStart (state, token) {
  7. state.currentNode.content.start = token
  8. state.caretPosition++
  9. return state
  10. }
  11. function handleCommentContent (state, token) {
  12. state.currentNode.content.value = token
  13. state.caretPosition++
  14. return state
  15. }
  16. function handleCommentEnd (state, token) {
  17. state.currentNode.content.end = token
  18. state.currentNode = state.currentNode.parentRef
  19. state.currentContext = state.currentContext.parentRef
  20. state.caretPosition++
  21. return state
  22. }
  23. module.exports = function comment (token, state) {
  24. if (token.type === TOKEN_COMMENT_START) {
  25. return handleCommentStart(state, token)
  26. }
  27. if (token.type === TOKEN_COMMENT_CONTENT) {
  28. return handleCommentContent(state, token)
  29. }
  30. if (token.type === TOKEN_COMMENT_END) {
  31. return handleCommentEnd(state, token)
  32. }
  33. state.caretPosition++
  34. return state
  35. }