版博士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.

attribute-value.js 1.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const { isWhitespace } = require('../helpers')
  2. const {
  3. ATTRIBUTE_VALUE_WRAPPED_CONTEXT,
  4. ATTRIBUTES_CONTEXT,
  5. ATTRIBUTE_VALUE_BARE_CONTEXT
  6. } = require('../constants/tokenizer-contexts')
  7. const {
  8. TOKEN_ATTRIBUTE_VALUE_WRAPPER_START
  9. } = require('../constants/token-types')
  10. function wrapper (state, tokens) {
  11. const wrapper = state.decisionBuffer
  12. tokens.push({
  13. type: TOKEN_ATTRIBUTE_VALUE_WRAPPER_START,
  14. content: wrapper,
  15. startPosition: state.caretPosition,
  16. endPosition: state.caretPosition
  17. })
  18. state.accumulatedContent = ''
  19. state.decisionBuffer = ''
  20. state.currentContext = ATTRIBUTE_VALUE_WRAPPED_CONTEXT
  21. state.contextParams[ATTRIBUTE_VALUE_WRAPPED_CONTEXT] = { wrapper }
  22. state.caretPosition++
  23. }
  24. function bare (state) {
  25. state.accumulatedContent = state.decisionBuffer
  26. state.decisionBuffer = ''
  27. state.currentContext = ATTRIBUTE_VALUE_BARE_CONTEXT
  28. state.caretPosition++
  29. }
  30. function tagEnd (state) {
  31. state.accumulatedContent = ''
  32. state.decisionBuffer = ''
  33. state.currentContext = ATTRIBUTES_CONTEXT
  34. }
  35. function parseSyntax (chars, state, tokens) {
  36. if (chars === '"' || chars === '\'') {
  37. return wrapper(state, tokens)
  38. }
  39. if (chars === '>' || chars === '/') {
  40. return tagEnd(state, tokens)
  41. }
  42. if (!isWhitespace(chars)) {
  43. return bare(state, tokens)
  44. }
  45. state.decisionBuffer = ''
  46. state.caretPosition++
  47. }
  48. module.exports = {
  49. parseSyntax
  50. }