factor.js 3.5 KB

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