factor.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://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 intially used
  17. start: [
  18. // comments
  19. {regex: /#?!.*/, token: "comment"},
  20. // strings """, multiline --> state
  21. {regex: /"""/, token: "string", next: "string3"},
  22. {regex: /"/, token: "string", next: "string"},
  23. // numbers: dec, hex, unicode, bin, fractional, complex
  24. {regex: /(?:[+-]?)(?:0x[\d,a-f]+)|(?:0o[0-7]+)|(?:0b[0,1]+)|(?:\d+.?\d*)/, token: "number"},
  25. //{regex: /[+-]?/} //fractional
  26. // definition: defining word, defined word, etc
  27. {regex: /(\:)(\s+)(\S+)(\s+)(\()/, token: ["keyword", null, "def", null, "keyword"], next: "stack"},
  28. // vocabulary using --> state
  29. {regex: /USING\:/, token: "keyword", next: "vocabulary"},
  30. // vocabulary definition/use
  31. {regex: /(USE\:|IN\:)(\s+)(\S+)/, token: ["keyword", null, "variable-2"]},
  32. // <constructors>
  33. {regex: /<\S+>/, token: "builtin"},
  34. // "keywords", incl. ; t f . [ ] { } defining words
  35. {regex: /;|t|f|if|\.|\[|\]|\{|\}|MAIN:/, token: "keyword"},
  36. // any id (?)
  37. {regex: /\S+/, token: "variable"},
  38. {
  39. regex: /./,
  40. token: null
  41. }
  42. ],
  43. vocabulary: [
  44. {regex: /;/, token: "keyword", next: "start"},
  45. {regex: /\S+/, token: "variable-2"},
  46. {
  47. regex: /./,
  48. token: null
  49. }
  50. ],
  51. string: [
  52. {regex: /(?:[^\\]|\\.)*?"/, token: "string", next: "start"},
  53. {regex: /.*/, token: "string"}
  54. ],
  55. string3: [
  56. {regex: /(?:[^\\]|\\.)*?"""/, token: "string", next: "start"},
  57. {regex: /.*/, token: "string"}
  58. ],
  59. stack: [
  60. {regex: /\)/, token: "meta", next: "start"},
  61. {regex: /--/, token: "meta"},
  62. {regex: /\S+/, token: "variable-3"},
  63. {
  64. regex: /./,
  65. token: null
  66. }
  67. ],
  68. // The meta property contains global information about the mode. It
  69. // can contain properties like lineComment, which are supported by
  70. // all modes, and also directives like dontIndentStates, which are
  71. // specific to simple modes.
  72. meta: {
  73. dontIndentStates: ["start", "vocabulary", "string", "string3", "stack"],
  74. lineComment: [ "!", "#!" ]
  75. }
  76. });
  77. CodeMirror.defineMIME("text/x-factor", "factor");
  78. });