author | Alan Dipert
<alan@dipert.org> 2019-08-12 18:02:30 UTC |
committer | Alan Dipert
<alan@dipert.org> 2019-08-12 18:02:30 UTC |
parent | 23ddf24300a8f8c15767c090cc1dd5f981e783ec |
jacl.js | +25 | -2 |
diff --git a/jacl.js b/jacl.js index 94a911b..632c4e1 100644 --- a/jacl.js +++ b/jacl.js @@ -57,6 +57,16 @@ class LispSymbol { popBinding() { this.value = this.stack.pop(); } + static fromString(token) { + if (/^:[^:]+$/.test(token)) { + const kw = token.substring(1); + if (readInteger(kw)) + throw new Error(`Must not have number syntax after ':': '${token}'`); + return Package.get('KEYWORD').intern(kw) + } else { + throw new Error(`TODO: other symbols`); + } + } } class LispString extends Array { @@ -205,6 +215,19 @@ const readMultiEscaped = async function(stream, token) { } }; +const readInteger = token => { + if (/^[+-]?[0-9]+\.?$/.test(token)) { + return window.parseInt(token); + } +}; + +// TODO figure out implications of jacl:undefined/jacl:true/jacl:false etc here +const interpretToken = token => { + return readInteger(token) + || LispSymbol.fromString(token) + //[+-]?[0-9]+\.?/.test/|| throw new Error(`Unknown token: '${token}'`); +}; + const readSingleEscaped = async function(stream, token) { for await(const y of stream) { if (isConstituent(y)) { @@ -217,7 +240,7 @@ const readSingleEscaped = async function(stream, token) { return readMultiEscaped(stream, token); } else if (READTABLE.val().isTerminating(y) || isWhitespace(y)) { stream.unread(y); - return token; + return interpretToken(token); } else { throw new Error(`Illegal character: '${y}'`); } @@ -266,4 +289,4 @@ var rdr = new Reader(buf); } })() -buf.writeEach('this is a test ok? 1234 "foob" ;a comment\n |LoL| '); +//buf.writeEach('this is a test ok? 1234 "foob" ;a comment\n |LoL| ');