Implemented the test:x format

This commit is contained in:
Devine Lu Linvega 2019-07-26 08:34:19 +09:00
parent 35436a0a23
commit 9916331188
2 changed files with 13 additions and 7 deletions

View File

@ -95,8 +95,15 @@ function Lisp (lib = {}, includes = []) {
}
const list = []
for (let i = 0; i < input.length; i++) {
if (i === 0 && input[i].type === TYPES.symbol && input.length === 2) {
if (input[i].type === TYPES.symbol) {
if (input[i].host) {
const host = await context.get(input[i].host)
if (host) {
list.push(host[input[i].value])
}
} else {
list.push(obj => obj[input[i].value])
}
} else {
list.push(await interpret(input[i], context))
}
@ -113,10 +120,7 @@ function Lisp (lib = {}, includes = []) {
return interpretList(input, context)
} else if (input.type === TYPES.identifier) {
return context.get(input.value)
} else if (
input.type === TYPES.number || input.type === TYPES.symbol ||
input.type === TYPES.string || input.type === TYPES.bool
) {
} else if (input.type === TYPES.number || input.type === TYPES.symbol || input.type === TYPES.string || input.type === TYPES.bool) {
return input.value
}
}
@ -128,6 +132,8 @@ function Lisp (lib = {}, includes = []) {
return { type: TYPES.string, value: input.slice(1, -1) }
} else if (input[0] === ':') {
return { type: TYPES.symbol, value: input.slice(1) }
} else if (input.indexOf(':') > 0) {
return { type: TYPES.symbol, host: input.split(':')[0], value: input.split(':')[1] }
} else if (input === 'true' || input === 'false') {
return { type: TYPES.bool, value: input === 'true' }
} else {

View File

@ -11,7 +11,7 @@ function Ronin () {
b_inv: '#ffb545'
}
this.includes = ['prelude']
this.includes = [] // ['prelude']
this.el = document.createElement('div')
this.el.id = 'ronin'