aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/properties/properties.js
blob: 2529505b9d6e588564788ad41e13ab3bfcaef44c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
CodeMirror.defineMode("properties", function() {
  return {
    token: function(stream, state) {
      var sol = stream.sol();
      var eol = stream.eol();

      if (sol) {
        if (state.nextMultiline) {
          state.inMultiline = true;
          state.nextMultiline = false;
        } else {
          state.position = "key";
        }
      }

      if (eol && ! state.nextMultiline) {
        state.inMultiline = false;
        state.position = "key";
      }

      if (sol) {
        while(stream.eatSpace());
      }

      var ch = stream.next();

      if (sol && (ch === "#" || ch === "!")) {
        state.position = "comment";
        stream.skipToEnd();
        return "comment";

      } else if (ch === "=" || ch === ":") {
        state.position = "value";
        return "equals";

      } else if (ch === "\\" && state.position === "value") {
        if (stream.next() !== "u") {    // u = Unicode sequence \u1234
          // Multiline value
          state.nextMultiline = true;
        }
      }

      return state.position;
    },

    startState: function() {
      return {
        position : "key",       // Current position, "key", "value" or "comment"
        nextMultiline : false,  // Is the next line multiline value
        inMultiline : false     // Is the current line a multiline value
      };
    }

  };
});

CodeMirror.defineMIME("text/x-properties", "properties");