factor.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  3. // Factor syntax highlight - simple mode
  4. //
  5. // by Dimage Sapelkin (https://github.com/kerabromsmu)
  6. ;(function (mod) {
  7. if (typeof exports == 'object' && typeof module == 'object')
  8. // CommonJS
  9. mod(require('../../lib/codemirror'), require('../../addon/mode/simple'))
  10. else if (typeof define == 'function' && define.amd)
  11. // AMD
  12. define(['../../lib/codemirror', '../../addon/mode/simple'], mod)
  13. // Plain browser env
  14. else mod(CodeMirror)
  15. })(function (CodeMirror) {
  16. 'use strict'
  17. CodeMirror.defineSimpleMode('factor', {
  18. // The start state contains the rules that are initially used
  19. start: [
  20. // comments
  21. { regex: /#?!.*/, token: 'comment' },
  22. // strings """, multiline --> state
  23. { regex: /"""/, token: 'string', next: 'string3' },
  24. { regex: /(STRING:)(\s)/, token: ['keyword', null], next: 'string2' },
  25. { regex: /\S*?"/, token: 'string', next: 'string' },
  26. // numbers: dec, hex, unicode, bin, fractional, complex
  27. { regex: /(?:0x[\d,a-f]+)|(?:0o[0-7]+)|(?:0b[0,1]+)|(?:\-?\d+.?\d*)(?=\s)/, token: 'number' },
  28. //{regex: /[+-]?/} //fractional
  29. // definition: defining word, defined word, etc
  30. { regex: /((?:GENERIC)|\:?\:)(\s+)(\S+)(\s+)(\()/, token: ['keyword', null, 'def', null, 'bracket'], next: 'stack' },
  31. // method definition: defining word, type, defined word, etc
  32. { regex: /(M\:)(\s+)(\S+)(\s+)(\S+)/, token: ['keyword', null, 'def', null, 'tag'] },
  33. // vocabulary using --> state
  34. { regex: /USING\:/, token: 'keyword', next: 'vocabulary' },
  35. // vocabulary definition/use
  36. { regex: /(USE\:|IN\:)(\s+)(\S+)(?=\s|$)/, token: ['keyword', null, 'tag'] },
  37. // definition: a defining word, defined word
  38. { regex: /(\S+\:)(\s+)(\S+)(?=\s|$)/, token: ['keyword', null, 'def'] },
  39. // "keywords", incl. ; t f . [ ] { } defining words
  40. { regex: /(?:;|\\|t|f|if|loop|while|until|do|PRIVATE>|<PRIVATE|\.|\S*\[|\]|\S*\{|\})(?=\s|$)/, token: 'keyword' },
  41. // <constructors> and the like
  42. { regex: /\S+[\)>\.\*\?]+(?=\s|$)/, token: 'builtin' },
  43. { regex: /[\)><]+\S+(?=\s|$)/, token: 'builtin' },
  44. // operators
  45. { regex: /(?:[\+\-\=\/\*<>])(?=\s|$)/, token: 'keyword' },
  46. // any id (?)
  47. { regex: /\S+/, token: 'variable' },
  48. { regex: /\s+|./, token: null },
  49. ],
  50. vocabulary: [
  51. { regex: /;/, token: 'keyword', next: 'start' },
  52. { regex: /\S+/, token: 'tag' },
  53. { regex: /\s+|./, token: null },
  54. ],
  55. string: [
  56. { regex: /(?:[^\\]|\\.)*?"/, token: 'string', next: 'start' },
  57. { regex: /.*/, token: 'string' },
  58. ],
  59. string2: [
  60. { regex: /^;/, token: 'keyword', next: 'start' },
  61. { regex: /.*/, token: 'string' },
  62. ],
  63. string3: [
  64. { regex: /(?:[^\\]|\\.)*?"""/, token: 'string', next: 'start' },
  65. { regex: /.*/, token: 'string' },
  66. ],
  67. stack: [
  68. { regex: /\)/, token: 'bracket', next: 'start' },
  69. { regex: /--/, token: 'bracket' },
  70. { regex: /\S+/, token: 'meta' },
  71. { regex: /\s+|./, token: null },
  72. ],
  73. // The meta property contains global information about the mode. It
  74. // can contain properties like lineComment, which are supported by
  75. // all modes, and also directives like dontIndentStates, which are
  76. // specific to simple modes.
  77. meta: {
  78. dontIndentStates: ['start', 'vocabulary', 'string', 'string3', 'stack'],
  79. lineComment: '!',
  80. },
  81. })
  82. CodeMirror.defineMIME('text/x-factor', 'factor')
  83. })