Skip to content

What to do about 'mode' #4

Description

@gabejohnson

The mode property on a table entry bugs me. It's inherited from particular Lisp implementations of readtables.

In the sweet.js reader, the only flag that sets the reader into a particular mode is dispatch. Though that mode could be done away if ideas from #2 or #3 are implemented.

It is also used to communicate to readIdentifier and readNumericLiteral that reading should terminate via entry.mode === 'terminating'. But this is really just a message from one entry to another.

This property could be generalized to pass JSON serializable messages to actions or to the reader.

const someEntry = {
  key: '@',
  message: '{  "maxPrefixLength": 3  }',
  action(stream) { ... }
}

const someOtherEntry = {
  action: function(stream) {
    let char, value = '', table = getCurrentReadtable();
    while (...) {
      char = stream.peek();
      const mapping = table.getMapping(char);
      if (mapping && mapping.message) {
        const msg = JSON.parse(message);
        if (msg.maxPrefixLength) {
          if (value.length + 1 <= msg.maxPrefixLength) return value + stream.readString();
        } else if(msg.terminating) {
          return value;
        }
      }
      value += stream.readString();
    }
    return value;
  }
}

/cc @disnet

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions