How to use the babylon/lib/tokenizer/state function in babylon

To help you get started, we’ve selected a few babylon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github forivall / tacoscript / packages / babylon-plugin-cst / src / plugin.js View on Github external
export default function(instance, pluginOptions) {
  instance.whitespaceState = new TokenizerState();
  instance.whitespaceState.init({}, instance.state.input);
  instance.whitespaceState.type = tokenTypes.whitespace;

  instance.cstState = {
    format: pluginOptions.format || {}
  };

  instance.extend("skipSpace", function(/*inner*/ /*complete override*/) {
    return function skipSpace() {
      this.startWhitespace();
      loop: while (this.state.pos < this.input.length) {
        let ch = this.input.charCodeAt(this.state.pos);
        switch (ch) {
          case 32: case 160: // ' '
            this.whitespaceState.value += String.fromCharCode(ch);
            ++this.state.pos;
github forivall / tacoscript / packages / str-to-token / src / index.js View on Github external
getTokenFromString(input, stateOpts) {
    this.input = input;
    this.state = new State();
    this.state.init(input);
    Object.assign(this.state, stateOpts);

    this.skipSpace();

    if (this.state.comments.length > 0) {
      let comment = this.state.comments[0];
      this.state.type = comment.type;
      this.state.value = comment.value;
    } else if (this.state.pos >= this.input.length) {
      this.state.type = "Whitespace";
      this.state.value = input;
    } else {
      this.readToken(this.fullCharCodeAtPos());
    }
github forivall / tacoscript / packages / str-to-token / src / index.js View on Github external
finishToken(type, val) {
    this.state.type = type;
    this.state.value = val;
    if (this.state.pos !== this.input.length) {
      if (this.triedTmplToken) {
        this.raise(0, "Did not consume entire string '" + this.input + "'");
      } else {
        this.state = new State();
        this.state.init(this.input);
        try {
          this.readTmplToken();
        } catch (e) {
          this.raise(0, "Could not consume entire string '" + this.input + "'");
        }
      }
    }
  }