Debian Codegraph @

interactive-notebook/codemirror/lib/stap.js

raw
1 // The stap highlighting rules
2 // Copyright (C) 2023 Red Hat Inc.
3 //
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
7 // later version.
8 import * as CodeMirror from 'codemirror';
9 import 'codemirror/addon/mode/simple';
10
11 CodeMirror.defineSimpleMode("systemtap", {
12 // The start state contains the rules that are intially used
13 // Rules are matched in order. I am using the same order as vscode/atom
14 start: [
15 // comments
16 { regex: /\/\/\/?.*$/, token: 'comment' },
17 { regex: /#.*$/, token: "comment" },
18 { regex: /\/\*/, token: 'comment', push: 'comment_block' },
19
20 // embedded C
21 { regex: /\%{/, token: "meta", mode: { spec: "clike", end: /\%}/}},
22
23 // numbers
24 // octal number
25 { regex: /(0)([0-7]+)/, token: ["string", "number"] },
26 // hex number
27 { regex: /(0x)([0-9a-fA-F]+)/, token: ["string", "number"] },
28 // numeric args
29 { regex: /\$#/, token: "number" },
30 { regex: /\$\d+/, token: "number" },
31 // decimal number
32 { regex: /\d+/, token: "number" },
33
34 // string
35 { regex: /"/, token: 'string', push: 'string' },
36
37 // TODO: probe signatures could be highlighted
38 {
39 regex: /probe/,
40 token: "keyword",
41 },
42
43 // functions (1 group per token)
44 {
45 regex: /(function)(\s+)([A-Za-z\$_][0-9A-Za-z_\$]*)/,
46 token: ["keyword", null, "variable-2"],
47 },
48
49 // keywords
50 // Should I add (?<!\.) I can't let it start with . since .return probes exist
51 {
52 regex: /(\b)(break|continue|return|next|delete|try|catch|while|for|foreach|in|limit|if|else|global|function|private|probe)(\b)/,
53 token: [null, "keyword", null]
54 },
55
56 //macros & atwords
57 {
58 regex: /@\w+/,
59 token: "atom"
60 },
61
62 // types
63 {
64 regex: /(\b)(string|long)(\b)/,
65 token: "keyword"
66 },
67
68 // Magic commands
69 {
70 regex: /^%%.*$/,
71 token: "string-2"
72 },
73
74 // variables
75 {
76 regex: /\b[A-Za-z\$_][0-9A-Za-z_\$]*\b/,
77 token: "variable"
78 },
79
80 // operators
81 {
82 regex: /[\*\/\%\+\-\&\^!=<>~|.]=?|[=!~:?]/,
83 token: "operator"
84 },
85
86 {
87 regex: /\{%\{%\(/,
88 indent: true
89 },
90 {
91 regex: /\}%\}%\)/,
92 dedent: true
93 },
94
95 // punctuation
96 { regex: /(\;|\||,)/, token: "punctuation" }
97 ],
98
99 comment_block: [
100 { regex: /\/\*/, token: 'comment', push: 'comment_block' },
101 // this ends and restarts a comment block. but need to catch this so
102 // that it doesn\'t start _another_ level of comment blocks
103 { regex: /\*\/\*/, token: 'comment' },
104 { regex: /(\*\/\s+\*(?!\/)[^\n]*)|(\*\/)/, token: 'comment', pop: true },
105 // Match anything else as a character inside the comment
106 { regex: /./, token: 'comment' },
107 ],
108
109 string: [
110 { regex: /"/, token: 'string', pop: true },
111 { regex: /./, token: 'string' }
112 ],
113
114 // probepoints: [
115 // { regex: /0[0-7]+/, token: "number" },
116 // { regex: /0x[0-9a-fA-F]+/, token: "number" },
117 // { regex: /\d+/, token: "number" },
118 // { regex: /"/, token: 'string', push: 'string' },
119 // // (?={) looksahead for {
120 // { regex: /.*(?={)/, token: 'comment', pop: true },
121 // ],
122
123 meta: {
124 closeBrackets: { pairs: "()[]\{\}\"\"%\{\}%(%)" },
125 dontIndentStates: ['comment_block'],
126 electricInput: /^\s*\}$/,
127 blockCommentStart: '/*',
128 blockCommentEnd: '*/',
129 lineComment: '//',
130 fold: 'brace'
131 }
132 });
133
134 CodeMirror.defineMIME('text/x-systemtap', 'systemtap');
135 CodeMirror.defineMIME('text/systemtap', 'systemtap');
136
137 CodeMirror.modeInfo.push({
138 ext: ['stp'],
139 mime: "text/x-systemtap",
140 mode: 'systemtap',
141 name: 'systemtap'
142 });