Removed the path type

This commit is contained in:
Devine Lu Linvega 2019-07-16 14:14:06 +09:00
parent ed406ca1ed
commit 7d009e266d
6 changed files with 1815 additions and 29 deletions

1788
desktop/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -106,8 +106,14 @@ function Commander (ronin) {
this.cache = this._input.value this.cache = this._input.value
} }
this.canInject = function () {
return this._input.value.indexOf('$path') > -1
}
this.injectPath = function (path) { this.injectPath = function (path) {
this._input.value = this._input.value.replace('($path)', `(path "${path}")`) if (this.canInject()) {
this._input.value = this._input.value.replace('$path', `"${path}"`)
}
} }
this.commit = function () { this.commit = function () {

View File

@ -7,9 +7,8 @@ function Library (ronin) {
this.folder = (path = ronin.source.path) => { this.folder = (path = ronin.source.path) => {
const a = [] const a = []
if (path) { if (path) {
const folder = ronin.source.folder(path) if (fs.existsSync(path)) {
if (fs.existsSync(folder)) { return fs.readdirSync(path)
return fs.readdirSync(folder)
} }
} }
return a return a
@ -169,10 +168,6 @@ function Library (ronin) {
return this.pos(rect.w / 2, rect.h / 2) return this.pos(rect.w / 2, rect.h / 2)
} }
this.path = (path) => {
return path
}
this.scale = (rect, w, h) => { this.scale = (rect, w, h) => {
return { x: rect.x, y: rect.y, w: rect.w * w, h: rect.h * h } return { x: rect.x, y: rect.y, w: rect.w * w, h: rect.h * h }
} }

View File

@ -20,10 +20,9 @@ function Lisp (input, lib) {
const special = { const special = {
run: (input, context) => { run: (input, context) => {
const file = fs.readFileSync( const p = input[1].value
path.resolve(input[1].value), if (!fs.existsSync(p)) { console.warn('Source', p); return [] }
{ encoding: 'utf-8' }) const file = fs.readFileSync(p, { encoding: 'utf-8' })
return interpret(this.parse(file), context) return interpret(this.parse(file), context)
}, },
let: function (input, context) { let: function (input, context) {
@ -31,7 +30,6 @@ function Lisp (input, lib) {
acc.scope[x[0].value] = interpret(x[1], context) acc.scope[x[0].value] = interpret(x[1], context)
return acc return acc
}, new Context({}, context)) }, new Context({}, context))
return interpret(input[2], letContext) return interpret(input[2], letContext)
}, },
def: function (input, context) { def: function (input, context) {
@ -68,7 +66,6 @@ function Lisp (input, lib) {
acc[x.value] = lambdaArguments[i] acc[x.value] = lambdaArguments[i]
return acc return acc
}, {}) }, {})
return interpret(input[2], new Context(lambdaScope, context)) return interpret(input[2], new Context(lambdaScope, context))
} }
}, },

View File

@ -92,12 +92,12 @@ function Ronin () {
const file = e.dataTransfer.files[0] const file = e.dataTransfer.files[0]
if (!file || !file.name) { console.warn('File', 'Not a valid file.'); return } if (!file || !file.name) { console.warn('File', 'Not a valid file.'); return }
const path = file.path ? file.path : file.name const path = file.path ? file.path : file.name
if (path.indexOf('.lisp') > -1) { if (this.commander.canInject()) {
this.source.read(path)
this.commander.show()
} else if (file.path) {
this.commander.injectPath(file.path) this.commander.injectPath(file.path)
this.commander.show() this.commander.show()
} else if (path.indexOf('.lisp') > -1) {
this.source.read(path)
this.commander.show()
} }
} }
} }