Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add 'table' property to Readtable entries #2

Copy link
Copy link

Description

@gabejohnson
Issue body actions

It would be useful to generalize dispatch macros and not have to hard-code a single character as the dispatch character.

For instance:

const entry = {
  key: '#',
  table: Readtable.from([...]),
  action(...) { ... }
}

The semantics would be defined in the reader but I'm thinking:

  1. If the entry has a table, look at the next char and see if the table has an entry for it and recurse.
  2. If the entry has a table and an action, do 1 but only after running the action (for side-effects/setup).
  3. If the entry has no table, just execute the action.

Maybe 2 is unnecessary or maybe the action just before the final table found should execute.

Motivation:

The current table-driven reader in sweet.js uses some simple tries for dealing w/ punctuators and keywords. This function could be built into the readtable implementation.

const tEntry = {
  key: 't',
  table: Readtable.from([{
    key: 'h',
    table: Readtable.from([{
      key: 'i',
      table: Readtable.from([{
        key: 's',
        action(stream) {
          stream.readString();
          return KeywordToken({ value: 'this' });
        }
      }])
    }, {
      key: 'r',
      table: Readtable.from([{
        key: 'o',
        table: Readtable.from([{
          key: 'w',
          action(stream) {
            stream.readString();
            return KeywordToken({ value: 'throw'});
          }
        }])
      }])
    }])
  }])
};

Now this would obviously be procedurally generated, but this illustrates the concept.

Note: Another way to achieve similar functionality would be to allow multi-char keys.

Reactions are currently unavailable

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

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.