minor fixes and a better Slang to string conversion (non-formal)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-12-30 05:07:53 +04:00
parent 58ae635ded
commit 0743ead8ef

View File

@ -55,6 +55,9 @@
color: blue; color: blue;
} }
#words {
font-family: monospace;
}
#stack { #stack {
opacity: 0.8; opacity: 0.8;
@ -66,13 +69,10 @@
<script> <script>
function stringifySlangCode(code){ function stringifySlangCode(code){
if(code.constructor.name == 'Array'){ if(typeof(code) == typeof('str') && /\s/.test(code)){
return '[ '+code.map(function(c){ return '\''+code+'\''
if(c.constructor.name == 'Array'){ } else if(code.constructor.name == 'Array'){
return stringifySlangCode(c) return '[ '+code.map(stringifySlangCode).join(' ')+' ]'
}
return c
}).join(' ')+' ]'
} }
return code return code
} }
@ -95,7 +95,7 @@ function runCommand(){
stack.innerText = 'stack: ' + stringifySlangCode(slang(command.innerText)) stack.innerText = 'stack: ' + stringifySlangCode(slang(command.innerText))
} catch(e) { } catch(e) {
stack.innerText = 'stack: ' + CONTEXT.stack stack.innerText = 'stack: ' + stringifySlangCode(CONTEXT.stack)
var err = document.createElement('div') var err = document.createElement('div')
err.classList.add('error') err.classList.add('error')
if(e.message != null){ if(e.message != null){
@ -152,19 +152,23 @@ function toggleBootstrapCode(){
} }
function showAvailableWords(){ function showAvailableWords(){
document.getElementById('words').innerHTML = Object.keys(NAMESPACE).filter(function(e){ document.getElementById('words').innerHTML = Object.keys(NAMESPACE)
// skip words starting with '_'... .sort()
if(e[0] == '_'){ .filter(function(e){
return false // skip words starting with '_'...
} if(e[0] == '_'){
return true return false
}).map(function(e){ }
var code = NAMESPACE[e] return true
if(code.constructor.name == 'Array'){ })
code = stringifySlangCode(code) .map(function(e){
} var code = NAMESPACE[e]
return '<span title="'+code+'">'+e+'</span>' if(code.constructor.name == 'Array'){
}).join(', ') code = stringifySlangCode(code)
}
return '<span title="'+code+'">'+e+'</span>'
})
.join(', ')
} }