| 1 |
import {simpleMode} from "./simple-mode.js" |
| 2 |
|
| 3 |
export const factor = simpleMode({ |
| 4 |
start: [ |
| 5 |
// comments |
| 6 |
{regex: /#?!.*/, token: "comment"}, |
| 7 |
// strings """, multiline --> state |
| 8 |
{regex: /"""/, token: "string", next: "string3"}, |
| 9 |
{regex: /(STRING:)(\s)/, token: ["keyword", null], next: "string2"}, |
| 10 |
{regex: /\S*?"/, token: "string", next: "string"}, |
| 11 |
// numbers: dec, hex, unicode, bin, fractional, complex |
| 12 |
{regex: /(?:0x[\d,a-f]+)|(?:0o[0-7]+)|(?:0b[0,1]+)|(?:\-?\d+.?\d*)(?=\s)/, token: "number"}, |
| 13 |
//{regex: /[+-]?/} //fractional |
| 14 |
// definition: defining word, defined word, etc |
| 15 |
{regex: /((?:GENERIC)|\:?\:)(\s+)(\S+)(\s+)(\()/, token: ["keyword", null, "def", null, "bracket"], next: "stack"}, |
| 16 |
// method definition: defining word, type, defined word, etc |
| 17 |
{regex: /(M\:)(\s+)(\S+)(\s+)(\S+)/, token: ["keyword", null, "def", null, "tag"]}, |
| 18 |
// vocabulary using --> state |
| 19 |
{regex: /USING\:/, token: "keyword", next: "vocabulary"}, |
| 20 |
// vocabulary definition/use |
| 21 |
{regex: /(USE\:|IN\:)(\s+)(\S+)(?=\s|$)/, token: ["keyword", null, "tag"]}, |
| 22 |
// definition: a defining word, defined word |
| 23 |
{regex: /(\S+\:)(\s+)(\S+)(?=\s|$)/, token: ["keyword", null, "def"]}, |
| 24 |
// "keywords", incl. ; t f . [ ] { } defining words |
| 25 |
{regex: /(?:;|\\|t|f|if|loop|while|until|do|PRIVATE>|<PRIVATE|\.|\S*\[|\]|\S*\{|\})(?=\s|$)/, token: "keyword"}, |
| 26 |
// <constructors> and the like |
| 27 |
{regex: /\S+[\)>\.\*\?]+(?=\s|$)/, token: "builtin"}, |
| 28 |
{regex: /[\)><]+\S+(?=\s|$)/, token: "builtin"}, |
| 29 |
// operators |
| 30 |
{regex: /(?:[\+\-\=\/\*<>])(?=\s|$)/, token: "keyword"}, |
| 31 |
// any id (?) |
| 32 |
{regex: /\S+/, token: "variable"}, |
| 33 |
{regex: /\s+|./, token: null} |
| 34 |
], |
| 35 |
vocabulary: [ |
| 36 |
{regex: /;/, token: "keyword", next: "start"}, |
| 37 |
{regex: /\S+/, token: "tag"}, |
| 38 |
{regex: /\s+|./, token: null} |
| 39 |
], |
| 40 |
string: [ |
| 41 |
{regex: /(?:[^\\]|\\.)*?"/, token: "string", next: "start"}, |
| 42 |
{regex: /.*/, token: "string"} |
| 43 |
], |
| 44 |
string2: [ |
| 45 |
{regex: /^;/, token: "keyword", next: "start"}, |
| 46 |
{regex: /.*/, token: "string"} |
| 47 |
], |
| 48 |
string3: [ |
| 49 |
{regex: /(?:[^\\]|\\.)*?"""/, token: "string", next: "start"}, |
| 50 |
{regex: /.*/, token: "string"} |
| 51 |
], |
| 52 |
stack: [ |
| 53 |
{regex: /\)/, token: "bracket", next: "start"}, |
| 54 |
{regex: /--/, token: "bracket"}, |
| 55 |
{regex: /\S+/, token: "meta"}, |
| 56 |
{regex: /\s+|./, token: null} |
| 57 |
], |
| 58 |
languageData: { |
| 59 |
name: "factor", |
| 60 |
dontIndentStates: ["start", "vocabulary", "string", "string3", "stack"], |
| 61 |
commentTokens: {line: "!"} |
| 62 |
} |
| 63 |
}); |