mode-turtle.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. ace.define("ace/mode/turtle_highlight_rules",[], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var TurtleHighlightRules = function() {
  6. this.$rules = {
  7. start: [{
  8. include: "#comments"
  9. }, {
  10. include: "#strings"
  11. }, {
  12. include: "#base-prefix-declarations"
  13. }, {
  14. include: "#string-language-suffixes"
  15. }, {
  16. include: "#string-datatype-suffixes"
  17. }, {
  18. include: "#relative-urls"
  19. }, {
  20. include: "#xml-schema-types"
  21. }, {
  22. include: "#rdf-schema-types"
  23. }, {
  24. include: "#owl-types"
  25. }, {
  26. include: "#qnames"
  27. }, {
  28. include: "#punctuation-operators"
  29. }],
  30. "#base-prefix-declarations": [{
  31. token: "keyword.other.prefix.turtle",
  32. regex: /@(?:base|prefix)/
  33. }],
  34. "#comments": [{
  35. token: [
  36. "punctuation.definition.comment.turtle",
  37. "comment.line.hash.turtle"
  38. ],
  39. regex: /(#)(.*$)/
  40. }],
  41. "#owl-types": [{
  42. token: "support.type.datatype.owl.turtle",
  43. regex: /owl:[a-zA-Z]+/
  44. }],
  45. "#punctuation-operators": [{
  46. token: "keyword.operator.punctuation.turtle",
  47. regex: /;|,|\.|\(|\)|\[|\]/
  48. }],
  49. "#qnames": [{
  50. token: "entity.name.other.qname.turtle",
  51. regex: /(?:[a-zA-Z][-_a-zA-Z0-9]*)?:(?:[_a-zA-Z][-_a-zA-Z0-9]*)?/
  52. }],
  53. "#rdf-schema-types": [{
  54. token: "support.type.datatype.rdf.schema.turtle",
  55. regex: /rdfs?:[a-zA-Z]+|(?:^|\s)a(?:\s|$)/
  56. }],
  57. "#relative-urls": [{
  58. token: "string.quoted.other.relative.url.turtle",
  59. regex: /</,
  60. push: [{
  61. token: "string.quoted.other.relative.url.turtle",
  62. regex: />/,
  63. next: "pop"
  64. }, {
  65. defaultToken: "string.quoted.other.relative.url.turtle"
  66. }]
  67. }],
  68. "#string-datatype-suffixes": [{
  69. token: "keyword.operator.datatype.suffix.turtle",
  70. regex: /\^\^/
  71. }],
  72. "#string-language-suffixes": [{
  73. token: [
  74. "keyword.operator.language.suffix.turtle",
  75. "constant.language.suffix.turtle"
  76. ],
  77. regex: /(?!")(@)([a-z]+(?:\-[a-z0-9]+)*)/
  78. }],
  79. "#strings": [{
  80. token: "string.quoted.triple.turtle",
  81. regex: /"""/,
  82. push: [{
  83. token: "string.quoted.triple.turtle",
  84. regex: /"""/,
  85. next: "pop"
  86. }, {
  87. defaultToken: "string.quoted.triple.turtle"
  88. }]
  89. }, {
  90. token: "string.quoted.double.turtle",
  91. regex: /"/,
  92. push: [{
  93. token: "string.quoted.double.turtle",
  94. regex: /"/,
  95. next: "pop"
  96. }, {
  97. token: "invalid.string.newline",
  98. regex: /$/
  99. }, {
  100. token: "constant.character.escape.turtle",
  101. regex: /\\./
  102. }, {
  103. defaultToken: "string.quoted.double.turtle"
  104. }]
  105. }],
  106. "#xml-schema-types": [{
  107. token: "support.type.datatype.xml.schema.turtle",
  108. regex: /xsd?:[a-z][a-zA-Z]+/
  109. }]
  110. };
  111. this.normalizeRules();
  112. };
  113. TurtleHighlightRules.metaData = {
  114. fileTypes: ["ttl", "nt"],
  115. name: "Turtle",
  116. scopeName: "source.turtle"
  117. };
  118. oop.inherits(TurtleHighlightRules, TextHighlightRules);
  119. exports.TurtleHighlightRules = TurtleHighlightRules;
  120. });
  121. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  122. "use strict";
  123. var oop = require("../../lib/oop");
  124. var Range = require("../../range").Range;
  125. var BaseFoldMode = require("./fold_mode").FoldMode;
  126. var FoldMode = exports.FoldMode = function(commentRegex) {
  127. if (commentRegex) {
  128. this.foldingStartMarker = new RegExp(
  129. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  130. );
  131. this.foldingStopMarker = new RegExp(
  132. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  133. );
  134. }
  135. };
  136. oop.inherits(FoldMode, BaseFoldMode);
  137. (function() {
  138. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  139. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  140. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  141. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  142. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  143. this._getFoldWidgetBase = this.getFoldWidget;
  144. this.getFoldWidget = function(session, foldStyle, row) {
  145. var line = session.getLine(row);
  146. if (this.singleLineBlockCommentRe.test(line)) {
  147. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  148. return "";
  149. }
  150. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  151. if (!fw && this.startRegionRe.test(line))
  152. return "start"; // lineCommentRegionStart
  153. return fw;
  154. };
  155. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  156. var line = session.getLine(row);
  157. if (this.startRegionRe.test(line))
  158. return this.getCommentRegionBlock(session, line, row);
  159. var match = line.match(this.foldingStartMarker);
  160. if (match) {
  161. var i = match.index;
  162. if (match[1])
  163. return this.openingBracketBlock(session, match[1], row, i);
  164. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  165. if (range && !range.isMultiLine()) {
  166. if (forceMultiline) {
  167. range = this.getSectionRange(session, row);
  168. } else if (foldStyle != "all")
  169. range = null;
  170. }
  171. return range;
  172. }
  173. if (foldStyle === "markbegin")
  174. return;
  175. var match = line.match(this.foldingStopMarker);
  176. if (match) {
  177. var i = match.index + match[0].length;
  178. if (match[1])
  179. return this.closingBracketBlock(session, match[1], row, i);
  180. return session.getCommentFoldRange(row, i, -1);
  181. }
  182. };
  183. this.getSectionRange = function(session, row) {
  184. var line = session.getLine(row);
  185. var startIndent = line.search(/\S/);
  186. var startRow = row;
  187. var startColumn = line.length;
  188. row = row + 1;
  189. var endRow = row;
  190. var maxRow = session.getLength();
  191. while (++row < maxRow) {
  192. line = session.getLine(row);
  193. var indent = line.search(/\S/);
  194. if (indent === -1)
  195. continue;
  196. if (startIndent > indent)
  197. break;
  198. var subRange = this.getFoldWidgetRange(session, "all", row);
  199. if (subRange) {
  200. if (subRange.start.row <= startRow) {
  201. break;
  202. } else if (subRange.isMultiLine()) {
  203. row = subRange.end.row;
  204. } else if (startIndent == indent) {
  205. break;
  206. }
  207. }
  208. endRow = row;
  209. }
  210. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  211. };
  212. this.getCommentRegionBlock = function(session, line, row) {
  213. var startColumn = line.search(/\s*$/);
  214. var maxRow = session.getLength();
  215. var startRow = row;
  216. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  217. var depth = 1;
  218. while (++row < maxRow) {
  219. line = session.getLine(row);
  220. var m = re.exec(line);
  221. if (!m) continue;
  222. if (m[1]) depth--;
  223. else depth++;
  224. if (!depth) break;
  225. }
  226. var endRow = row;
  227. if (endRow > startRow) {
  228. return new Range(startRow, startColumn, endRow, line.length);
  229. }
  230. };
  231. }).call(FoldMode.prototype);
  232. });
  233. ace.define("ace/mode/turtle",[], function(require, exports, module) {
  234. "use strict";
  235. var oop = require("../lib/oop");
  236. var TextMode = require("./text").Mode;
  237. var TurtleHighlightRules = require("./turtle_highlight_rules").TurtleHighlightRules;
  238. var FoldMode = require("./folding/cstyle").FoldMode;
  239. var Mode = function() {
  240. this.HighlightRules = TurtleHighlightRules;
  241. this.foldingRules = new FoldMode();
  242. };
  243. oop.inherits(Mode, TextMode);
  244. (function() {
  245. this.$id = "ace/mode/turtle";
  246. }).call(Mode.prototype);
  247. exports.Mode = Mode;
  248. });
  249. (function() {
  250. ace.require(["ace/mode/turtle"], function(m) {
  251. if (typeof module == "object" && typeof exports == "object" && module) {
  252. module.exports = m;
  253. }
  254. });
  255. })();