[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/vendor/codemirror/mode/sparql/ -> sparql.js (source)

   1  // CodeMirror, copyright (c) by Marijn Haverbeke and others
   2  // Distributed under an MIT license: https://codemirror.net/5/LICENSE
   3  
   4  (function(mod) {
   5    if (typeof exports == "object" && typeof module == "object") // CommonJS
   6      mod(require("../../lib/codemirror"));
   7    else if (typeof define == "function" && define.amd) // AMD
   8      define(["../../lib/codemirror"], mod);
   9    else // Plain browser env
  10      mod(CodeMirror);
  11  })(function(CodeMirror) {
  12  "use strict";
  13  
  14  CodeMirror.defineMode("sparql", function(config) {
  15    var indentUnit = config.indentUnit;
  16    var curPunc;
  17  
  18    function wordRegexp(words) {
  19      return new RegExp("^(?:" + words.join("|") + ")$", "i");
  20    }
  21    var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri",
  22                          "iri", "uri", "bnode", "count", "sum", "min", "max", "avg", "sample",
  23                          "group_concat", "rand", "abs", "ceil", "floor", "round", "concat", "substr", "strlen",
  24                          "replace", "ucase", "lcase", "encode_for_uri", "contains", "strstarts", "strends",
  25                          "strbefore", "strafter", "year", "month", "day", "hours", "minutes", "seconds",
  26                          "timezone", "tz", "now", "uuid", "struuid", "md5", "sha1", "sha256", "sha384",
  27                          "sha512", "coalesce", "if", "strlang", "strdt", "isnumeric", "regex", "exists",
  28                          "isblank", "isliteral", "a", "bind"]);
  29    var keywords = wordRegexp(["base", "prefix", "select", "distinct", "reduced", "construct", "describe",
  30                               "ask", "from", "named", "where", "order", "limit", "offset", "filter", "optional",
  31                               "graph", "by", "asc", "desc", "as", "having", "undef", "values", "group",
  32                               "minus", "in", "not", "service", "silent", "using", "insert", "delete", "union",
  33                               "true", "false", "with",
  34                               "data", "copy", "to", "move", "add", "create", "drop", "clear", "load"]);
  35    var operatorChars = /[*+\-<>=&|\^\/!\?]/;
  36  
  37    function tokenBase(stream, state) {
  38      var ch = stream.next();
  39      curPunc = null;
  40      if (ch == "$" || ch == "?") {
  41        if(ch == "?" && stream.match(/\s/, false)){
  42          return "operator";
  43        }
  44        stream.match(/^[A-Za-z0-9_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][A-Za-z0-9_\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]*/);
  45        return "variable-2";
  46      }
  47      else if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) {
  48        stream.match(/^[^\s\u00a0>]*>?/);
  49        return "atom";
  50      }
  51      else if (ch == "\"" || ch == "'") {
  52        state.tokenize = tokenLiteral(ch);
  53        return state.tokenize(stream, state);
  54      }
  55      else if (/[{}\(\),\.;\[\]]/.test(ch)) {
  56        curPunc = ch;
  57        return "bracket";
  58      }
  59      else if (ch == "#") {
  60        stream.skipToEnd();
  61        return "comment";
  62      }
  63      else if (operatorChars.test(ch)) {
  64        return "operator";
  65      }
  66      else if (ch == ":") {
  67        eatPnLocal(stream);
  68        return "atom";
  69      }
  70      else if (ch == "@") {
  71        stream.eatWhile(/[a-z\d\-]/i);
  72        return "meta";
  73      }
  74      else {
  75        stream.eatWhile(/[_\w\d]/);
  76        if (stream.eat(":")) {
  77          eatPnLocal(stream);
  78          return "atom";
  79        }
  80        var word = stream.current();
  81        if (ops.test(word))
  82          return "builtin";
  83        else if (keywords.test(word))
  84          return "keyword";
  85        else
  86          return "variable";
  87      }
  88    }
  89  
  90    function eatPnLocal(stream) {
  91      stream.match(/(\.(?=[\w_\-\\%])|[:\w_-]|\\[-\\_~.!$&'()*+,;=/?#@%]|%[a-f\d][a-f\d])+/i);
  92    }
  93  
  94    function tokenLiteral(quote) {
  95      return function(stream, state) {
  96        var escaped = false, ch;
  97        while ((ch = stream.next()) != null) {
  98          if (ch == quote && !escaped) {
  99            state.tokenize = tokenBase;
 100            break;
 101          }
 102          escaped = !escaped && ch == "\\";
 103        }
 104        return "string";
 105      };
 106    }
 107  
 108    function pushContext(state, type, col) {
 109      state.context = {prev: state.context, indent: state.indent, col: col, type: type};
 110    }
 111    function popContext(state) {
 112      state.indent = state.context.indent;
 113      state.context = state.context.prev;
 114    }
 115  
 116    return {
 117      startState: function() {
 118        return {tokenize: tokenBase,
 119                context: null,
 120                indent: 0,
 121                col: 0};
 122      },
 123  
 124      token: function(stream, state) {
 125        if (stream.sol()) {
 126          if (state.context && state.context.align == null) state.context.align = false;
 127          state.indent = stream.indentation();
 128        }
 129        if (stream.eatSpace()) return null;
 130        var style = state.tokenize(stream, state);
 131  
 132        if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") {
 133          state.context.align = true;
 134        }
 135  
 136        if (curPunc == "(") pushContext(state, ")", stream.column());
 137        else if (curPunc == "[") pushContext(state, "]", stream.column());
 138        else if (curPunc == "{") pushContext(state, "}", stream.column());
 139        else if (/[\]\}\)]/.test(curPunc)) {
 140          while (state.context && state.context.type == "pattern") popContext(state);
 141          if (state.context && curPunc == state.context.type) {
 142            popContext(state);
 143            if (curPunc == "}" && state.context && state.context.type == "pattern")
 144              popContext(state);
 145          }
 146        }
 147        else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state);
 148        else if (/atom|string|variable/.test(style) && state.context) {
 149          if (/[\}\]]/.test(state.context.type))
 150            pushContext(state, "pattern", stream.column());
 151          else if (state.context.type == "pattern" && !state.context.align) {
 152            state.context.align = true;
 153            state.context.col = stream.column();
 154          }
 155        }
 156  
 157        return style;
 158      },
 159  
 160      indent: function(state, textAfter) {
 161        var firstChar = textAfter && textAfter.charAt(0);
 162        var context = state.context;
 163        if (/[\]\}]/.test(firstChar))
 164          while (context && context.type == "pattern") context = context.prev;
 165  
 166        var closing = context && firstChar == context.type;
 167        if (!context)
 168          return 0;
 169        else if (context.type == "pattern")
 170          return context.col;
 171        else if (context.align)
 172          return context.col + (closing ? 0 : 1);
 173        else
 174          return context.indent + (closing ? 0 : indentUnit);
 175      },
 176  
 177      lineComment: "#"
 178    };
 179  });
 180  
 181  CodeMirror.defineMIME("application/sparql-query", "sparql");
 182  
 183  });


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer