author | Alan Dipert
<alan@dipert.org> 2019-08-28 04:35:10 UTC |
committer | Alan Dipert
<alan@dipert.org> 2019-08-28 04:35:10 UTC |
parent | 0ec3fcfbfef2ce7986aa3a5c9e80538fa5bdf9c0 |
jacl.js | +16 | -9 |
diff --git a/jacl.js b/jacl.js index 5635550..2822796 100644 --- a/jacl.js +++ b/jacl.js @@ -41,7 +41,7 @@ class Cons { class LispSymbol { constructor(name, packageName) { this.name = name; - this.package = packageName; + this.packageName = packageName; this.value = UNDEFINED; this.fvalue = UNDEFINED; this.stack = []; @@ -64,9 +64,9 @@ class LispSymbol { this.value = this.stack.pop(); } static intern(packageName, name) { - if (readInteger(packageName)) + if (readInteger(packageName)[0]) throw new Error(`Symbol package must not be number: '${packageName}'`); - if (readInteger(name)) + if (readInteger(name)[0]) throw new Error(`Symbol name must not be number: '${name}'`); return Package.get(packageName, true).intern(name); } @@ -87,12 +87,14 @@ class LispSymbol { throw new Error(`Unknown symbol syntax: '${token}'`); } - static internFromString(token) { - if (LispSymbol.isKeyword(token)) { - return LispSymbol.intern('KEYWORD', token.substring(1)); + static internFromString(str) { + if (typeof str !== 'string') throw new Error(`Can only intern strings`); + + if (LispSymbol.isKeyword(str)) { + return LispSymbol.intern('KEYWORD', str.substring(1)); } - const [pkgName, name] = LispSymbol.getPackageAndName(token); + let [pkgName, name] = LispSymbol.getPackageAndName(str); if (!pkgName) pkgName = PACKAGE.val().name; @@ -223,7 +225,10 @@ const READTABLE = Package.intern('CL', '*READTABLE*'); class Token extends String { interpret() { - return readInteger(this) || LispSymbol.internFromString(this); + const [isInt, intVal] = readInteger(this); + if (isInt) return intVal; + + return LispSymbol.internFromString(this.valueOf()); } static is(x, y) { return (x instanceof Token) && x.valueOf() === y; @@ -315,7 +320,9 @@ const readMultiEscaped = async function(stream, token) { const readInteger = token => { if (/^[+-]?[0-9]+\.?$/.test(token)) { - return window.parseInt(token); + return new Values(true, window.parseInt(token)); + } else { + return new Values(false, null); } };