Sha256: 5860fb4ad9f72176bd206e64434b82c4c16eb7fe8c420896d0c8412bcc2a6669

Contents?: true

Size: 1.96 KB

Versions: 104

Compression:

Stored size: 1.96 KB

Contents

// A framework for simple tokenizers. Takes care of newlines and
// white-space, and of getting the text from the source stream into
// the token object. A state is a function of two arguments -- a
// string stream and a setState function. The second can be used to
// change the tokenizer's state, and can be ignored for stateless
// tokenizers. This function should advance the stream over a token
// and return a string or object containing information about the next
// token, or null to pass and have the (new) state be called to finish
// the token. When a string is given, it is wrapped in a {style, type}
// object. In the resulting object, the characters consumed are stored
// under the content property. Any whitespace following them is also
// automatically consumed, and added to the value property. (Thus,
// content is the actual meaningful part of the token, while value
// contains all the text it spans.)

function tokenizer(source, state) {
  // Newlines are always a separate token.
  function isWhiteSpace(ch) {
    // The messy regexp is because IE's regexp matcher is of the
    // opinion that non-breaking spaces are no whitespace.
    return ch != "\n" && /^[\s\u00a0]*$/.test(ch);
  }

  var tokenizer = {
    state: state,

    take: function(type) {
      if (typeof(type) == "string")
        type = {style: type, type: type};

      type.content = (type.content || "") + source.get();
      if (!/\n$/.test(type.content))
        source.nextWhile(isWhiteSpace);
      type.value = type.content + source.get();
      return type;
    },

    next: function () {
      if (!source.more()) throw StopIteration;

      var type;
      if (source.equals("\n")) {
        source.next();
        return this.take("whitespace");
      }
      
      if (source.applies(isWhiteSpace))
        type = "whitespace";
      else
        while (!type)
          type = this.state(source, function(s) {tokenizer.state = s;});

      return this.take(type);
    }
  };
  return tokenizer;
}

Version data entries

104 entries across 104 versions & 5 rubygems

Version Path
erp_app-3.1.16 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.15 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.14 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.13 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.12 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.11 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.10 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.9 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.8 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.7 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.6 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.5 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.4 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.3 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.2 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.0.16 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.0.15 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.1 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.1.0 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js
erp_app-3.0.14 public/javascripts/erp_app/ckeditor/plugins/sourcepopup/codemirror/editor/js/tokenize.js