blob: c7ff3be61a6ed8906c54fb8c02db426471fcf9f6 [file] [log] [blame] [raw]
RabsRincon6ef87b52018-02-27 14:58:21 +01001// Copyright (c) 2012, Matt Godbolt
Matt Godboltc60cad22014-11-26 08:24:40 -06002// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6//
7// * Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above copyright
10// notice, this list of conditions and the following disclaimer in the
11// documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23// POSSIBILITY OF SUCH DAMAGE.
Matt Godboltda98a1e2012-07-03 15:45:30 -050024
jaredwy70556a62017-11-04 16:07:29 +110025"use strict";
RabsRincon8015e5f2019-07-22 15:15:58 +020026var monaco = require('monaco-editor');
Matt Godbolt29ccf882017-01-15 10:00:42 -060027
jaredwy70556a62017-11-04 16:07:29 +110028function definition() {
29 return {
30 // Set defaultToken to invalid to see what you do not tokenize yet
31 defaultToken: 'invalid',
Matt Godbolt29ccf882017-01-15 10:00:42 -060032
jaredwy70556a62017-11-04 16:07:29 +110033 // C# style strings
34 escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
Matt Godbolt29ccf882017-01-15 10:00:42 -060035
jaredwy70556a62017-11-04 16:07:29 +110036 registers: /%?\b(r[0-9]+[dbw]?|([er]?([abcd][xhl]|cs|fs|ds|ss|sp|bp|ip|sil?|dil?))|[xyz]mm[0-9]+|sp|fp|lr)\b/,
Matt Godbolt29ccf882017-01-15 10:00:42 -060037
jaredwy70556a62017-11-04 16:07:29 +110038 intelOperators: /PTR|(D|Q|[XYZ]MM)?WORD/,
Matt Godboltb72bd482017-01-16 12:26:26 -060039
jaredwy70556a62017-11-04 16:07:29 +110040 tokenizer: {
41 root: [
42 // Error document
43 [/^<.*>$/, {token: 'annotation'}],
44 // Label definition
Matt Godbolteb0a45d2019-03-31 11:44:54 -050045 [/^[.a-zA-Z0-9_$?@].*:/, {token: 'type.identifier'}],
jaredwy70556a62017-11-04 16:07:29 +110046 // Label definition (ARM style)
Matt Godbolteb0a45d2019-03-31 11:44:54 -050047 [/^\s*[|][^|]*[|]/, {token: 'type.identifier'}],
jaredwy70556a62017-11-04 16:07:29 +110048 // Label definition (CL style)
Matt Godbolteb0a45d2019-03-31 11:44:54 -050049 [/^\s*[.a-zA-Z0-9_$|]*\s*(PROC|ENDP|DB|DD)/, {token: 'type.identifier'}],
jaredwy70556a62017-11-04 16:07:29 +110050 // Constant definition
Matt Godbolteb0a45d2019-03-31 11:44:54 -050051 [/^[.a-zA-Z0-9_$?@][^=]*=/, {token: 'type.identifier'}],
jaredwy70556a62017-11-04 16:07:29 +110052 // opcode
53 [/[.a-zA-Z_][.a-zA-Z_0-9]*/, {token: 'keyword', next: '@rest'}],
Matt Godboltac8d24a2018-05-07 18:22:58 -050054 // braces and parentheses at the start of the line (e.g. nvcc output)
55 [/[(){}]/, {token: 'operator', next: '@rest'}],
Matt Godbolt29ccf882017-01-15 10:00:42 -060056
jaredwy70556a62017-11-04 16:07:29 +110057 // whitespace
58 {include: '@whitespace'}
59 ],
Matt Godbolt29ccf882017-01-15 10:00:42 -060060
jaredwy70556a62017-11-04 16:07:29 +110061 rest: [
62 // pop at the beginning of the next line and rematch
63 [/^.*$/, {token: '@rematch', next: '@pop'}],
Matt Godboltb72bd482017-01-16 12:26:26 -060064
jaredwy70556a62017-11-04 16:07:29 +110065 [/@registers/, 'variable.predefined'],
66 [/@intelOperators/, 'annotation'],
67 // brackets
RabsRincon670afd82018-02-13 14:49:07 +010068 [/[{}<>()[\]]/, '@brackets'],
Matt Godboltea7964d2017-02-13 22:46:24 -060069
jaredwy70556a62017-11-04 16:07:29 +110070 // ARM-style label reference
71 [/[|][^|]*[|]*/, 'type.identifier'],
Matt Godbolt29ccf882017-01-15 10:00:42 -060072
jaredwy70556a62017-11-04 16:07:29 +110073 // numbers
RabsRincon670afd82018-02-13 14:49:07 +010074 [/\d*\.\d+([eE][-+]?\d+)?/, 'number.float'],
jaredwy70556a62017-11-04 16:07:29 +110075 [/([$]|0[xX])[0-9a-fA-F]+/, 'number.hex'],
76 [/\d+/, 'number'],
77 // ARM-style immediate numbers (which otherwise look like comments)
78 [/#-?\d+/, 'number'],
Matt Godbolt29ccf882017-01-15 10:00:42 -060079
jaredwy70556a62017-11-04 16:07:29 +110080 // operators
Matt Godboltac8d24a2018-05-07 18:22:58 -050081 [/[-+,*/!:&{}()]/, 'operator'],
Matt Godbolt29ccf882017-01-15 10:00:42 -060082
jaredwy70556a62017-11-04 16:07:29 +110083 // strings
84 [/"([^"\\]|\\.)*$/, 'string.invalid'], // non-terminated string
85 [/"/, {token: 'string.quote', bracket: '@open', next: '@string'}],
Matt Godbolt29ccf882017-01-15 10:00:42 -060086
jaredwy70556a62017-11-04 16:07:29 +110087 // characters
88 [/'[^\\']'/, 'string'],
89 [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
90 [/'/, 'string.invalid'],
Matt Godboltb72bd482017-01-16 12:26:26 -060091
jaredwy70556a62017-11-04 16:07:29 +110092 // Assume anything else is a label reference
93 [/%?[.?_$a-zA-Z@][.?_$a-zA-Z0-9@]*/, 'type.identifier'],
Matt Godboltb72bd482017-01-16 12:26:26 -060094
jaredwy70556a62017-11-04 16:07:29 +110095 // whitespace
96 {include: '@whitespace'}
97 ],
Matt Godbolt29ccf882017-01-15 10:00:42 -060098
jaredwy70556a62017-11-04 16:07:29 +110099 comment: [
RabsRincon670afd82018-02-13 14:49:07 +0100100 [/[^/*]+/, 'comment'],
jaredwy70556a62017-11-04 16:07:29 +1100101 [/\/\*/, 'comment', '@push'], // nested comment
102 ["\\*/", 'comment', '@pop'],
RabsRincon670afd82018-02-13 14:49:07 +0100103 [/[/*]/, 'comment']
jaredwy70556a62017-11-04 16:07:29 +1100104 ],
Matt Godbolt29ccf882017-01-15 10:00:42 -0600105
jaredwy70556a62017-11-04 16:07:29 +1100106 string: [
107 [/[^\\"]+/, 'string'],
108 [/@escapes/, 'string.escape'],
109 [/\\./, 'string.escape.invalid'],
110 [/"/, {token: 'string.quote', bracket: '@close', next: '@pop'}]
111 ],
Matt Godbolt29ccf882017-01-15 10:00:42 -0600112
jaredwy70556a62017-11-04 16:07:29 +1100113 whitespace: [
114 [/[ \t\r\n]+/, 'white'],
115 [/\/\*/, 'comment', '@comment'],
116 [/\/\/.*$/, 'comment'],
117 [/[#;\\@].*$/, 'comment']
118 ]
119 }
120 };
121}
Matt Godbolt29ccf882017-01-15 10:00:42 -0600122
Sebastian Staffaa36e23c2019-03-11 16:32:26 +0100123var def = definition();
jaredwy70556a62017-11-04 16:07:29 +1100124monaco.languages.register({id: 'asm'});
Sebastian Staffaa36e23c2019-03-11 16:32:26 +0100125monaco.languages.setMonarchTokensProvider('asm', def);
126
127module.exports = def;