reader.js
function read_via_closest_dialect(lexer, options) {
  trace(lexer.message_src_loc("", lexer, {file:false}));

  // options allow this function to be used when a readtab
  // handler needs to read by invoking a handler that it's
  // overridden, without knowing what dialect was overridden.
  // (see invoke_readfn_overridden_by below)
  options = options || {};
  // normally we start with the close dialect (0)
  var startingDialect = options.startingDialect || 0;

  // And normally we read the source text under the current position
  // unless they give us a token that's already been read)
  var token = options.token;
  if(!token) {
    // we *peek* when determining which readtab read function to call,
    // so the read functions can consume the *entire* form, including the
    // first token (which makes the design of the read functions easier
    // easier to understand and test in isolation).
    token = lexer.peek_token();
  }

  debug('reading expression starting "' + token.text + '"');
  var form = retry;
  var readfn;
  // try the dialects from beginning (inner scope) to end (outer scope)...
  for(var i = startingDialect; isretry(form) && i < lexer.dialects.length; i++) {
    var dialect = lexer.dialects[i];
    debug('looking for "' + token.text + '" in ' + dialect.name + ' readtab');
    readfn = findReadfn(dialect.readtab, token)
    if(readfn) {
      form = read_via_readfn(readfn, lexer, token.text);
      if(!form) {
        lexer.error('Invalid response from "' + token.text + '" readtab function in "' +
          dialect.name + '"');
      }
    }
  }

  // if we've tried all the dialects and either didn't find a match,
  // or found a match that returned "reader.retry"...
  if(isretry(form)) {
    // try all the dialects again, this time looking for "__default"
    // note: most likely this will get all the way to core's __default,
    //   but dialect's *can* override __default if they need to, and
    //   could e.g. "selectively" override it by returning reader.retry in
    //   cases where they want core's __default to handle it instead.
    for(var i = startingDialect; isretry(form) && i < lexer.dialects.length; i++) {
      var dialect = lexer.dialects[i];
      debug('looking for "__default" in ' + dialect.name + ' readtab');
      readfn = dialect.readtab !== undefined ? dialect.readtab['__default'] : undefined;
      if(readfn) {
        form = read_via_readfn(readfn, lexer, token.text);
        if(!form) {
          lexer.error('Invalid response for "' + token.text +
            '" returned by __default function in "' + dialect.name + '"');
        }
      }
    }
  }

  // this should never happen (because of __default) but JIC:
  if(!form || isretry(form)) {
    lexer.error('No dialect handled the text starting "' + lexer.snoop(10) + '...');
  }

  return form;
}
function read_via_closest_dialect(lexer, options) {
  trace(lexer.message_src_loc("", lexer, {file:false}));

  // options allow this function to be used when a readtab
  // handler needs to read by invoking a handler that it's
  // overridden, without knowing what dialect was overridden.
  // (see invoke_readfn_overridden_by below)
  options = options || {};
  // normally we start with the close dialect (0)
  var startingDialect = options.startingDialect || 0;

  // And normally we read the source text under the current position
  // unless they give us a token that's already been read)
  var token = options.token;
  if(!token) {
    // we *peek* when determining which readtab read function to call,
    // so the read functions can consume the *entire* form, including the
    // first token (which makes the design of the read functions easier
    // easier to understand and test in isolation).
    token = lexer.peek_token();
  }

  debug('reading expression starting "' + token.text + '"');
  var form = retry;
  var readfn;
  // try the dialects from beginning (inner scope) to end (outer scope)...
  for(var i = startingDialect; isretry(form) && i < lexer.dialects.length; i++) {
    var dialect = lexer.dialects[i];
    debug('looking for "' + token.text + '" in ' + dialect.name + ' readtab');
    readfn = findReadfn(dialect.readtab, token)
    if(readfn) {
      form = read_via_readfn(readfn, lexer, token.text);
      if(!form) {
        lexer.error('Invalid response from "' + token.text + '" readtab function in "' +
          dialect.name + '"');
      }
    }
  }

  // if we've tried all the dialects and either didn't find a match,
  // or found a match that returned "reader.retry"...
  if(isretry(form)) {
    // try all the dialects again, this time looking for "__default"
    // note: most likely this will get all the way to core's __default,
    //   but dialect's *can* override __default if they need to, and
    //   could e.g. "selectively" override it by returning reader.retry in
    //   cases where they want core's __default to handle it instead.
    for(var i = startingDialect; isretry(form) && i < lexer.dialects.length; i++) {
      var dialect = lexer.dialects[i];
      debug('looking for "__default" in ' + dialect.name + ' readtab');
      readfn = dialect.readtab !== undefined ? dialect.readtab['__default'] : undefined;
      if(readfn) {
        form = read_via_readfn(readfn, lexer, token.text);
        if(!form) {
          lexer.error('Invalid response for "' + token.text +
            '" returned by __default function in "' + dialect.name + '"');
        }
      }
    }
  }

  // this should never happen (because of __default) but JIC:
  if(!form || isretry(form)) {
    lexer.error('No dialect handled the text starting "' + lexer.snoop(10) + '...');
  }

  return form;
}
function read_via_closest_dialect ( lexer , options ) { trace ( lexer . message_src_loc ( "" , lexer , { file : false } ) ) ; // options allow this function to be used when a readtab // handler needs to read by invoking a handler that it's // overridden, without knowing what dialect was overridden. // (see invoke_readfn_overridden_by below) options = options || { } ; // normally we start with the close dialect (0) var startingDialect = options . startingDialect || 0 ; // And normally we read the source text under the current position // unless they give us a token that's already been read) var token = options . token ; if ( ! token ) { // we *peek* when determining which readtab read function to call, // so the read functions can consume the *entire* form, including the // first token (which makes the design of the read functions easier // easier to understand and test in isolation). token = lexer . peek_token ( ) ; } debug ( 'reading expression starting "' + token . text + '"' ) ; var form = retry ; var readfn ; // try the dialects from beginning (inner scope) to end (outer scope)... for ( var i = startingDialect ; isretry ( form ) && i < lexer . dialects . length ; i ++ ) { var dialect = lexer . dialects [ i ] ; debug ( 'looking for "' + token . text + '" in ' + dialect . name + ' readtab' ) ; readfn = findReadfn ( dialect . readtab , token ) if ( readfn ) { form = read_via_readfn ( readfn , lexer , token . text ) ; if ( ! form ) { lexer . error ( 'Invalid response from "' + token . text + '" readtab function in "' + dialect . name + '"' ) ; } } } // if we've tried all the dialects and either didn't find a match, // or found a match that returned "reader.retry"... if ( isretry ( form ) ) { // try all the dialects again, this time looking for "__default" // note: most likely this will get all the way to core's __default, //   but dialect's *can* override __default if they need to, and //   could e.g. "selectively" override it by returning reader.retry in //   cases where they want core's __default to handle it instead. for ( var i = startingDialect ; isretry ( form ) && i < lexer . dialects . length ; i ++ ) { var dialect = lexer . dialects [ i ] ; debug ( 'looking for "__default" in ' + dialect . name + ' readtab' ) ; readfn = dialect . readtab !== undefined ? dialect . readtab [ '__default' ] : undefined ; if ( readfn ) { form = read_via_readfn ( readfn , lexer , token . text ) ; if ( ! form ) { lexer . error ( 'Invalid response for "' + token . text + '" returned by __default function in "' + dialect . name + '"' ) ; } } } } // this should never happen (because of __default) but JIC: if ( ! form || isretry ( form ) ) { lexer . error ( 'No dialect handled the text starting "' + lexer . snoop ( 10 ) + '...' ) ; } return form ; }
Read the form under the current position, using the closest scoped
dialect that contains a matching entry in it's readtab.

If such an entry returns "reader.retry", try the
*next* closest dialect with a match (and so on) until one
of the dialect's reads the form, otherwise it gets read by
the closest "__default" handler.
Read the form under the current position using the closest scoped dialect that contains a matching entry in it s readtab .