Created by: r3m0t
The command line script reads stxcase.js with a user-provided readtable which makes it impossible to define a # behaviour and use it from the sjs
command.
Example:
var sweetjs = require('sweet.js');
var recursed = false;
module.exports = sweetjs.currentReadtable().extend({
'#': function (ch, reader, toks, source, index) {
if (recursed) return null;
var start = reader.index;
var tok;
recursed = true;
reader.readToken(); // read the #
tok = reader.suppressReadError(reader.readDelimiter);
recursed = false;
if (tok !== null && tok.value == '{}') {
// looks like #{ } form
return null;
}
return [reader.makePunctuator('+', { start: start })];
}
});
macro m {
case {_ $x } => {
var y = makeValue(42, #{$x});
return [y]
}
}
m foo # 5
Invocation:
bin/sjs -l ./readtable.js -s < ./a.js