1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2012, Ajax.org B.V.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* * Neither the name of Ajax.org B.V. nor the
15
* names of its contributors may be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
* ***** END LICENSE BLOCK ***** */
36
ace.define('ace/mode/forth', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/forth_highlight_rules', 'ace/mode/folding/cstyle'], function(require, exports, module) {
39
var oop = require("../lib/oop");
40
var TextMode = require("./text").Mode;
41
var Tokenizer = require("../tokenizer").Tokenizer;
42
var ForthHighlightRules = require("./forth_highlight_rules").ForthHighlightRules;
43
var FoldMode = require("./folding/cstyle").FoldMode;
45
var Mode = function() {
46
var highlighter = new ForthHighlightRules();
47
this.foldingRules = new FoldMode();
48
this.$tokenizer = new Tokenizer(highlighter.getRules());
50
oop.inherits(Mode, TextMode);
53
this.lineCommentStart = "(?<=^|\\s)\\.?\\( [^)]*\\)";
54
this.blockComment = {start: "/*", end: "*/"};
55
}).call(Mode.prototype);
60
ace.define('ace/mode/forth_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
63
var oop = require("../lib/oop");
64
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
66
var ForthHighlightRules = function() {
68
this.$rules = { start: [ { include: '#forth' } ],
70
[ { token: 'comment.line.double-dash.forth',
71
regex: '(?:^|\\s)--\\s.*$',
72
comment: 'line comments for iForth' },
73
{ token: 'comment.line.backslash.forth',
74
regex: '(?:^|\\s)\\\\[\\s\\S]*$',
75
comment: 'ANSI line comment' },
76
{ token: 'comment.line.backslash-g.forth',
77
regex: '(?:^|\\s)\\\\[Gg] .*$',
78
comment: 'gForth line comment' },
79
{ token: 'comment.block.forth',
80
regex: '(?:^|\\s)\\(\\*(?=\\s|$)',
82
[ { token: 'comment.block.forth',
83
regex: '(?:^|\\s)\\*\\)(?=\\s|$)',
85
{ defaultToken: 'comment.block.forth' } ],
86
comment: 'multiline comments for iForth' },
87
{ token: 'comment.block.documentation.forth',
89
caseInsensitive: true,
91
[ { token: 'comment.block.documentation.forth',
92
regex: '\\bENDDOC\\b',
93
caseInsensitive: true,
95
{ defaultToken: 'comment.block.documentation.forth' } ],
96
comment: 'documentation comments for iForth' },
97
{ token: 'comment.line.parentheses.forth',
98
regex: '(?:^|\\s)\\.?\\( [^)]*\\)',
99
comment: 'ANSI line comment' } ],
101
[ { token: 'constant.language.forth',
102
regex: '(?:^|\\s)(?:TRUE|FALSE|BL|PI|CELL|C/L|R/O|W/O|R/W)(?=\\s|$)',
103
caseInsensitive: true},
104
{ token: 'constant.numeric.forth',
105
regex: '(?:^|\\s)[$#%]?[-+]?[0-9]+(?:\\.[0-9]*e-?[0-9]+|\\.?[0-9a-fA-F]*)(?=\\s|$)'},
106
{ token: 'constant.character.forth',
107
regex: '(?:^|\\s)(?:[&^]\\S|(?:"|\')\\S(?:"|\'))(?=\\s|$)'}],
109
[ { include: '#constant' },
110
{ include: '#comment' },
111
{ include: '#string' },
112
{ include: '#word' },
113
{ include: '#variable' },
114
{ include: '#storage' },
115
{ include: '#word-def' } ],
117
[ { token: 'storage.type.forth',
118
regex: '(?:^|\\s)(?:2CONSTANT|2VARIABLE|ALIAS|CONSTANT|CREATE-INTERPRET/COMPILE[:]?|CREATE|DEFER|FCONSTANT|FIELD|FVARIABLE|USER|VALUE|VARIABLE|VOCABULARY)(?=\\s|$)',
119
caseInsensitive: true}],
121
[ { token: 'string.quoted.double.forth',
122
regex: '(ABORT" |BREAK" |\\." |C" |0"|S\\\\?" )([^"]+")',
123
caseInsensitive: true},
124
{ token: 'string.unquoted.forth',
125
regex: '(?:INCLUDE|NEEDS|REQUIRE|USE)[ ]\\S+(?=\\s|$)',
126
caseInsensitive: true}],
128
[ { token: 'variable.language.forth',
129
regex: '\\b(?:I|J)\\b',
130
caseInsensitive: true } ],
132
[ { token: 'keyword.control.immediate.forth',
133
regex: '(?:^|\\s)\\[(?:\\?DO|\\+LOOP|AGAIN|BEGIN|DEFINED|DO|ELSE|ENDIF|FOR|IF|IFDEF|IFUNDEF|LOOP|NEXT|REPEAT|THEN|UNTIL|WHILE)\\](?=\\s|$)',
134
caseInsensitive: true},
135
{ token: 'keyword.other.immediate.forth',
136
regex: '(?:^|\\s)(?:COMPILE-ONLY|IMMEDIATE|IS|RESTRICT|TO|WHAT\'S|])(?=\\s|$)',
137
caseInsensitive: true},
138
{ token: 'keyword.control.compile-only.forth',
139
regex: '(?:^|\\s)(?:-DO|\\-LOOP|\\?DO|\\?LEAVE|\\+DO|\\+LOOP|ABORT\\"|AGAIN|AHEAD|BEGIN|CASE|DO|ELSE|ENDCASE|ENDIF|ENDOF|ENDTRY\\-IFERROR|ENDTRY|FOR|IF|IFERROR|LEAVE|LOOP|NEXT|RECOVER|REPEAT|RESTORE|THEN|TRY|U\\-DO|U\\+DO|UNTIL|WHILE)(?=\\s|$)',
140
caseInsensitive: true},
141
{ token: 'keyword.other.compile-only.forth',
142
regex: '(?:^|\\s)(?:\\?DUP-0=-IF|\\?DUP-IF|\\)|\\[|\\[\'\\]|\\[CHAR\\]|\\[COMPILE\\]|\\[IS\\]|\\[TO\\]|<COMPILATION|<INTERPRETATION|ASSERT\\(|ASSERT0\\(|ASSERT1\\(|ASSERT2\\(|ASSERT3\\(|COMPILATION>|DEFERS|DOES>|INTERPRETATION>|OF|POSTPONE)(?=\\s|$)',
143
caseInsensitive: true},
144
{ token: 'keyword.other.non-immediate.forth',
145
regex: '(?:^|\\s)(?:\'|<IS>|<TO>|CHAR|END-STRUCT|INCLUDE[D]?|LOAD|NEEDS|REQUIRE[D]?|REVISION|SEE|STRUCT|THRU|USE)(?=\\s|$)',
146
caseInsensitive: true},
147
{ token: 'keyword.other.warning.forth',
148
regex: '(?:^|\\s)(?:~~|BREAK:|BREAK"|DBG)(?=\\s|$)',
149
caseInsensitive: true}],
152
[ 'keyword.other.compile-only.forth',
153
'keyword.other.compile-only.forth',
155
'entity.name.function.forth' ],
156
regex: '(:NONAME)|(^:|\\s:)(\\s)(\\S+)(?=\\s|$)',
157
caseInsensitive: true,
159
[ { token: 'keyword.other.compile-only.forth',
161
caseInsensitive: true,
163
{ include: '#constant' },
164
{ include: '#comment' },
165
{ include: '#string' },
166
{ include: '#word' },
167
{ include: '#variable' },
168
{ include: '#storage' },
169
{ defaultToken: 'meta.block.forth' } ] } ] }
171
this.normalizeRules();
174
ForthHighlightRules.metaData = { fileTypes: [ 'frt', 'fs', 'ldr' ],
175
foldingStartMarker: '/\\*\\*|\\{\\s*$',
176
foldingStopMarker: '\\*\\*/|^\\s*\\}',
177
keyEquivalent: '^~F',
179
scopeName: 'source.forth' }
182
oop.inherits(ForthHighlightRules, TextHighlightRules);
184
exports.ForthHighlightRules = ForthHighlightRules;
187
ace.define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
190
var oop = require("../../lib/oop");
191
var Range = require("../../range").Range;
192
var BaseFoldMode = require("./fold_mode").FoldMode;
194
var FoldMode = exports.FoldMode = function(commentRegex) {
196
this.foldingStartMarker = new RegExp(
197
this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
199
this.foldingStopMarker = new RegExp(
200
this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
204
oop.inherits(FoldMode, BaseFoldMode);
208
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
209
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
211
this.getFoldWidgetRange = function(session, foldStyle, row) {
212
var line = session.getLine(row);
213
var match = line.match(this.foldingStartMarker);
218
return this.openingBracketBlock(session, match[1], row, i);
220
return session.getCommentFoldRange(row, i + match[0].length, 1);
223
if (foldStyle !== "markbeginend")
226
var match = line.match(this.foldingStopMarker);
228
var i = match.index + match[0].length;
231
return this.closingBracketBlock(session, match[1], row, i);
233
return session.getCommentFoldRange(row, i, -1);
237
}).call(FoldMode.prototype);