character-escape.mjs 885 B

1234567891011121314151617181920212223242526272829303132333435
  1. var characterEscape = {
  2. name: 'characterEscape',
  3. tokenize: tokenizeCharacterEscape
  4. }
  5. export default characterEscape
  6. import assert from 'assert'
  7. import asciiPunctuation from '../character/ascii-punctuation.mjs'
  8. import codes from '../character/codes.mjs'
  9. import types from '../constant/types.mjs'
  10. function tokenizeCharacterEscape(effects, ok, nok) {
  11. return start
  12. function start(code) {
  13. assert(code === codes.backslash, 'expected `\\`')
  14. effects.enter(types.characterEscape)
  15. effects.enter(types.escapeMarker)
  16. effects.consume(code)
  17. effects.exit(types.escapeMarker)
  18. return open
  19. }
  20. function open(code) {
  21. if (asciiPunctuation(code)) {
  22. effects.enter(types.characterEscapeValue)
  23. effects.consume(code)
  24. effects.exit(types.characterEscapeValue)
  25. effects.exit(types.characterEscape)
  26. return ok
  27. }
  28. return nok(code)
  29. }
  30. }