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