|
23 | 23 | * $GIT_REPO_DIR/tool-support/syntax-highlighting/jupyter/mode_template.ts |
24 | 24 | */ |
25 | 25 |
|
26 | | -// tslint:disable-next-line |
27 | | -import 'codemirror/addon/mode/simple'; |
28 | | - |
29 | | -import * as CodeMirror from 'codemirror'; |
30 | | - |
31 | | -const SI_MODE = 'sysml'; |
32 | | -const P_MIME = 'text/x-sysml' |
| 26 | +import {StringStream} from "@codemirror/language" |
| 27 | +import { clike } from '@codemirror/legacy-modes/mode/clike'; |
33 | 28 |
|
34 | 29 | const f_wordify = (h: any, s: string) => ({...h, [s]: true}); |
35 | | - |
36 | | -export function defineSysMLv2Mode(): void { |
37 | | - CodeMirror.defineMode(SI_MODE, (gc_mode, gc_parser) => { |
38 | | - return CodeMirror.getMode(gc_mode, { |
39 | | - name: 'clike', |
40 | | - keywords: [ |
41 | | - "about", "abstract", "accept", "action", "actor", "after", "alias", "all", "allocate", "allocation", |
42 | | - "analysis", "and", "as", "assert", "assign", "assume", "at", "attribute", "bind", "binding", "by", |
43 | | - "calc", "case", "comment", "concern", "connect", "connection", "constant", "constraint", "crosses", |
44 | | - "decide", "def", "default", "defined", "dependency", "derived", "do", "doc", "else", "end", "entry", |
45 | | - "enum", "event", "exhibit", "exit", "expose", "filter", "first", "flow", "for", "fork", "frame", "from", |
46 | | - "hastype", "if", "implies", "import", "in", "include", "individual", "inout", "interface", "istype", |
47 | | - "item", "join", "language", "library", "locale", "loop", "merge", "message", "meta", "metadata", "new", |
48 | | - "nonunique", "not", "objective", "occurrence", "of", "or", "ordered", "out", "package", "parallel", |
49 | | - "part", "perform", "port", "private", "protected", "public", "redefines", "ref", "references", "render", |
50 | | - "rendering", "rep", "require", "requirement", "return", "satisfy", "send", "snapshot", "specializes", |
51 | | - "stakeholder", "standard", "state", "subject", "subsets", "succession", "terminate", "then", |
52 | | - "timeslice", "to", "transition", "until", "use", "variant", "variation", "verification", "verify", |
53 | | - "via", "view", "viewpoint", "when", "while", "xor" |
54 | | - ].reduce(f_wordify, {}), |
55 | | - defKeywords: [ |
56 | | - "action", "allocation", "analysis", "attribute", "binding", "calc", "case", "comment", "concern", |
57 | | - "connection", "constraint", "def", "doc", "enum", "flow", "interface", "item", "metadata", "objective", |
58 | | - "occurrence", "package", "part", "port", "ref", "rendering", "rep", "requirement", "snapshot", "state", |
59 | | - "subject", "succession", "timeslice", "transition", "verification", "view", "viewpoint" |
60 | | - ].reduce(f_wordify, {}), |
61 | | - typeFirstDefinitions: true, |
62 | | - atoms: ['true', 'false', 'null'].reduce(f_wordify), |
63 | | - number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i, |
64 | | - modeProps: { |
65 | | - fold: ['brace'], |
| 30 | +export const sysmlparser = clike({ |
| 31 | + name: 'sysml', |
| 32 | + keywords: [ |
| 33 | + "about", "abstract", "accept", "action", "actor", "after", "alias", "all", "allocate", "allocation", |
| 34 | + "analysis", "and", "as", "assert", "assign", "assume", "at", "attribute", "bind", "binding", "by", |
| 35 | + "calc", "case", "comment", "concern", "connect", "connection", "constant", "constraint", "crosses", |
| 36 | + "decide", "def", "default", "defined", "dependency", "derived", "do", "doc", "else", "end", "entry", |
| 37 | + "enum", "event", "exhibit", "exit", "expose", "filter", "first", "flow", "for", "fork", "frame", "from", |
| 38 | + "hastype", "if", "implies", "import", "in", "include", "individual", "inout", "interface", "istype", |
| 39 | + "item", "join", "language", "library", "locale", "loop", "merge", "message", "meta", "metadata", "new", |
| 40 | + "nonunique", "not", "objective", "occurrence", "of", "or", "ordered", "out", "package", "parallel", |
| 41 | + "part", "perform", "port", "private", "protected", "public", "redefines", "ref", "references", "render", |
| 42 | + "rendering", "rep", "require", "requirement", "return", "satisfy", "send", "snapshot", "specializes", |
| 43 | + "stakeholder", "standard", "state", "subject", "subsets", "succession", "terminate", "then", |
| 44 | + "timeslice", "to", "transition", "until", "use", "variant", "variation", "verification", "verify", |
| 45 | + "via", "view", "viewpoint", "when", "while", "xor" |
| 46 | + ].reduce(f_wordify, {}), |
| 47 | + types: [ |
| 48 | + "action", "allocation", "analysis", "attribute", "binding", "calc", "case", "comment", "concern", |
| 49 | + "connection", "constraint", "def", "doc", "enum", "flow", "interface", "item", "metadata", "objective", |
| 50 | + "occurrence", "package", "part", "port", "ref", "rendering", "rep", "requirement", "snapshot", "state", |
| 51 | + "subject", "succession", "timeslice", "transition", "verification", "view", "viewpoint" |
| 52 | + ].reduce(f_wordify, {}), |
| 53 | + atoms: ['true', 'false', 'null'].reduce(f_wordify, {}), |
| 54 | + number: /^(?:0x[a-f\d_]+|0b[01_]+|(?:[\d_]+\.?\d*|\.\d+)(?:e[-+]?[\d_]+)?)(u|ll?|l|f)?/i, |
| 55 | + hooks: { |
| 56 | + "'": function(stream: StringStream) { |
| 57 | + let b_escaped = false; |
| 58 | + let s_next; |
| 59 | + while(s_next = stream.next()) { |
| 60 | + if(s_next === "'" && !b_escaped) break; |
| 61 | + b_escaped = !b_escaped && s_next === '\\'; |
| 62 | + } |
| 63 | + return 'variable'; |
66 | 64 | }, |
67 | | - hooks: { |
68 | | - "'": function(stream: CodeMirror.StringStream) { |
69 | | - let b_escaped = false; |
70 | | - let s_next; |
71 | | - while(s_next = stream.next()) { |
72 | | - if(s_next === "'" && !b_escaped) break; |
73 | | - b_escaped = !b_escaped && s_next === '\\'; |
| 65 | + '/': function(stream: StringStream) { |
| 66 | + if(stream.match('/*', false)) stream.next(); |
| 67 | + return false; |
| 68 | + }, |
| 69 | + "#": function(stream: StringStream) { |
| 70 | + let b_first = true; |
| 71 | + do { |
| 72 | + if (stream.match("'", true)) { |
| 73 | + let b_escaped = false; |
| 74 | + let s_next; |
| 75 | + while(s_next = stream.next()) { |
| 76 | + if(s_next === "'" && !b_escaped) break; |
| 77 | + b_escaped = !b_escaped && s_next === '\\'; |
| 78 | + } |
| 79 | + } else if (stream.match(/\w/, true)) { |
| 80 | + stream.eatWhile(/\w/); |
| 81 | + } else if (b_first) { |
| 82 | + return 'operator'; |
74 | 83 | } |
75 | | - return 'variable'; |
76 | | - }, |
77 | | - '/': function(stream: CodeMirror.StringStream) { |
78 | | - if(stream.match('/*', false)) stream.next(); |
79 | | - return false; |
80 | | - }, |
81 | | - "#": function(stream: CodeMirror.StringStream) { |
82 | | - let b_first = true; |
83 | | - do { |
84 | | - if (stream.match("'", true)) { |
85 | | - let b_escaped = false; |
86 | | - let s_next; |
87 | | - while(s_next = stream.next()) { |
88 | | - if(s_next === "'" && !b_escaped) break; |
89 | | - b_escaped = !b_escaped && s_next === '\\'; |
90 | | - } |
91 | | - } else if (stream.match(/\w/, true)) { |
92 | | - stream.eatWhile(/\w/); |
93 | | - } else if (b_first) { |
94 | | - return 'operator'; |
95 | | - } |
96 | | - b_first = false; |
97 | | - } while (stream.match('::', true)) |
98 | | - return 'keyword'; |
99 | | - }, |
| 84 | + b_first = false; |
| 85 | + } while (stream.match('::', true)) |
| 86 | + return 'keyword'; |
100 | 87 | }, |
101 | | - }); |
102 | | - }); |
103 | | - |
104 | | - CodeMirror.defineMIME(P_MIME, SI_MODE); |
105 | | - |
106 | | - (CodeMirror as any).modeInfo.push({ |
107 | | - ext: ['sysml'], |
108 | | - mime: P_MIME, |
109 | | - mode: SI_MODE, |
110 | | - name: 'sysml', |
111 | | - }); |
112 | | -} |
| 88 | + }, |
| 89 | + } |
| 90 | +); |
0 commit comments