~pvigo/+junk/owncloud-14.04

« back to all changes in this revision

Viewing changes to share/owncloud/apps/files_texteditor/js/vendor/ace/src-noconflict/mode-forth.js

  • Committer: Pablo Vigo
  • Date: 2014-12-15 13:36:46 UTC
  • Revision ID: pvigo@xtec.cat-20141215133646-7d6it90e1dbsijc2
2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Distributed under the BSD license:
 
3
 *
 
4
 * Copyright (c) 2012, Ajax.org B.V.
 
5
 * All rights reserved.
 
6
 *
 
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.
 
17
 *
 
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.
 
28
 *
 
29
 *
 
30
 * Contributor(s):
 
31
 *
 
32
 *
 
33
 *
 
34
 * ***** END LICENSE BLOCK ***** */
 
35
 
 
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) {
 
37
 
 
38
 
 
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;
 
44
 
 
45
var Mode = function() {
 
46
    var highlighter = new ForthHighlightRules();
 
47
    this.foldingRules = new FoldMode();
 
48
    this.$tokenizer = new Tokenizer(highlighter.getRules());
 
49
};
 
50
oop.inherits(Mode, TextMode);
 
51
 
 
52
(function() {
 
53
    this.lineCommentStart = "(?<=^|\\s)\\.?\\( [^)]*\\)";
 
54
    this.blockComment = {start: "/*", end: "*/"};
 
55
}).call(Mode.prototype);
 
56
 
 
57
exports.Mode = Mode;
 
58
});
 
59
 
 
60
ace.define('ace/mode/forth_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
 
61
 
 
62
 
 
63
var oop = require("../lib/oop");
 
64
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
65
 
 
66
var ForthHighlightRules = function() {
 
67
 
 
68
    this.$rules = { start: [ { include: '#forth' } ],
 
69
      '#comment': 
 
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|$)',
 
81
           push: 
 
82
            [ { token: 'comment.block.forth',
 
83
                regex: '(?:^|\\s)\\*\\)(?=\\s|$)',
 
84
                next: 'pop' },
 
85
              { defaultToken: 'comment.block.forth' } ],
 
86
           comment: 'multiline comments for iForth' },
 
87
         { token: 'comment.block.documentation.forth',
 
88
           regex: '\\bDOC\\b',
 
89
           caseInsensitive: true,
 
90
           push: 
 
91
            [ { token: 'comment.block.documentation.forth',
 
92
                regex: '\\bENDDOC\\b',
 
93
                caseInsensitive: true,
 
94
                next: 'pop' },
 
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' } ],
 
100
      '#constant': 
 
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|$)'}],
 
108
      '#forth': 
 
109
       [ { include: '#constant' },
 
110
         { include: '#comment' },
 
111
         { include: '#string' },
 
112
         { include: '#word' },
 
113
         { include: '#variable' },
 
114
         { include: '#storage' },
 
115
         { include: '#word-def' } ],
 
116
      '#storage': 
 
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}],
 
120
      '#string': 
 
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}],
 
127
      '#variable': 
 
128
       [ { token: 'variable.language.forth',
 
129
           regex: '\\b(?:I|J)\\b',
 
130
           caseInsensitive: true } ],
 
131
      '#word': 
 
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}],
 
150
      '#word-def': 
 
151
       [ { token: 
 
152
            [ 'keyword.other.compile-only.forth',
 
153
              'keyword.other.compile-only.forth',
 
154
              'meta.block.forth',
 
155
              'entity.name.function.forth' ],
 
156
           regex: '(:NONAME)|(^:|\\s:)(\\s)(\\S+)(?=\\s|$)',
 
157
           caseInsensitive: true,
 
158
           push: 
 
159
            [ { token: 'keyword.other.compile-only.forth',
 
160
                regex: ';(?:CODE)?',
 
161
                caseInsensitive: true,
 
162
                next: 'pop' },
 
163
              { include: '#constant' },
 
164
              { include: '#comment' },
 
165
              { include: '#string' },
 
166
              { include: '#word' },
 
167
              { include: '#variable' },
 
168
              { include: '#storage' },
 
169
              { defaultToken: 'meta.block.forth' } ] } ] }
 
170
    
 
171
    this.normalizeRules();
 
172
};
 
173
 
 
174
ForthHighlightRules.metaData = { fileTypes: [ 'frt', 'fs', 'ldr' ],
 
175
      foldingStartMarker: '/\\*\\*|\\{\\s*$',
 
176
      foldingStopMarker: '\\*\\*/|^\\s*\\}',
 
177
      keyEquivalent: '^~F',
 
178
      name: 'Forth',
 
179
      scopeName: 'source.forth' }
 
180
 
 
181
 
 
182
oop.inherits(ForthHighlightRules, TextHighlightRules);
 
183
 
 
184
exports.ForthHighlightRules = ForthHighlightRules;
 
185
});
 
186
 
 
187
ace.define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
 
188
 
 
189
 
 
190
var oop = require("../../lib/oop");
 
191
var Range = require("../../range").Range;
 
192
var BaseFoldMode = require("./fold_mode").FoldMode;
 
193
 
 
194
var FoldMode = exports.FoldMode = function(commentRegex) {
 
195
    if (commentRegex) {
 
196
        this.foldingStartMarker = new RegExp(
 
197
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
 
198
        );
 
199
        this.foldingStopMarker = new RegExp(
 
200
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
 
201
        );
 
202
    }
 
203
};
 
204
oop.inherits(FoldMode, BaseFoldMode);
 
205
 
 
206
(function() {
 
207
 
 
208
    this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
 
209
    this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
 
210
 
 
211
    this.getFoldWidgetRange = function(session, foldStyle, row) {
 
212
        var line = session.getLine(row);
 
213
        var match = line.match(this.foldingStartMarker);
 
214
        if (match) {
 
215
            var i = match.index;
 
216
 
 
217
            if (match[1])
 
218
                return this.openingBracketBlock(session, match[1], row, i);
 
219
 
 
220
            return session.getCommentFoldRange(row, i + match[0].length, 1);
 
221
        }
 
222
 
 
223
        if (foldStyle !== "markbeginend")
 
224
            return;
 
225
 
 
226
        var match = line.match(this.foldingStopMarker);
 
227
        if (match) {
 
228
            var i = match.index + match[0].length;
 
229
 
 
230
            if (match[1])
 
231
                return this.closingBracketBlock(session, match[1], row, i);
 
232
 
 
233
            return session.getCommentFoldRange(row, i, -1);
 
234
        }
 
235
    };
 
236
 
 
237
}).call(FoldMode.prototype);
 
238
 
 
239
});