mirror of
https://github.com/flynx/Slang.git
synced 2025-10-29 02:30:08 +00:00
added comment highlighting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
858fab4d56
commit
145967ce8f
@ -72,6 +72,25 @@
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
|
||||
/* syntax... */
|
||||
|
||||
pre .comment {
|
||||
font-style: italic;
|
||||
color: gray;
|
||||
}
|
||||
pre :not(.comment) {
|
||||
font-weight: bold;
|
||||
}
|
||||
pre :not(.comment) .string {
|
||||
font-style: italic;
|
||||
color: blue;
|
||||
}
|
||||
pre :not(.comment) .word {
|
||||
font-weight: bold;
|
||||
color: blue;
|
||||
}
|
||||
|
||||
</style>
|
||||
<script src="slang.js"></script>
|
||||
|
||||
@ -210,10 +229,28 @@ function showAvailableWords(){
|
||||
<div id="stack"></div>
|
||||
</body>
|
||||
<script>
|
||||
document.getElementById('bootstrap').innerHTML='<pre>'+BOOTSTRAP
|
||||
.replace(/&/g, '&')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/</g, '<')+'</pre>'
|
||||
var bootstrap = BOOTSTRAP
|
||||
// basic HTML compatibility stuff...
|
||||
.replace(/&/g, '&')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/</g, '<')
|
||||
// very basic syntax highlighting...
|
||||
// comments...
|
||||
.replace(/(\(.*)-(.*\))/g, '<span class="comment">$1−$2</span>')
|
||||
.replace(/(\([^\)]*\))/g, '<span class="comment">$1</span>')
|
||||
.replace(/(\s*--.*\n)/g, '<span class="comment">$1</span>')
|
||||
/*
|
||||
Object.keys(NAMESPACE).forEach(function(k){
|
||||
bootstrap = bootstrap.replace(
|
||||
RegExp('('+k
|
||||
.replace('&', '&')
|
||||
.replace('<', '<')
|
||||
.replace('>', '>')
|
||||
.replace(/([\|\[\]\.\*\/\\\?\+\-])/g, '\\$1')+')', 'g'),
|
||||
'<span class="word">$1</span>')
|
||||
})
|
||||
*/
|
||||
document.getElementById('bootstrap').innerHTML='<pre>'+bootstrap+'</pre>'
|
||||
|
||||
document.getElementById('console')
|
||||
.addEventListener("keyup", function(e) {
|
||||
|
||||
@ -396,7 +396,7 @@ var NAMESPACE = {
|
||||
|
||||
// NOTE: hate how JS handles multi-line strings...
|
||||
var BOOTSTRAP = [
|
||||
'(------------------------------------------------------------------------------',
|
||||
'-------------------------------------------------------------------------------',
|
||||
'',
|
||||
' Slang is a simple and complete [S]tack [lang]uage.',
|
||||
'',
|
||||
@ -500,7 +500,7 @@ var BOOTSTRAP = [
|
||||
' NOTE: this notation is currently used as a means to documenting words and is',
|
||||
' not interpreted in any way.',
|
||||
'',
|
||||
'------------------------------------------------------------------------------)',
|
||||
'-------------------------------------------------------------------------------',
|
||||
'--',
|
||||
'-- With that out of the way, let\'s start with the bootstrap...',
|
||||
'--',
|
||||
@ -570,9 +570,10 @@ var BOOTSTRAP = [
|
||||
'-- Here is an infix operator example...',
|
||||
'-- :: + ( a | b -- c | ) [ \\ exec 2 0 _swapN \\ exec \\ add 2 1 _swapN ]',
|
||||
'-- now let\'s make a meta function to make things shorter...',
|
||||
'-- first the helper...',
|
||||
':: _infix ( op word -- ) [',
|
||||
':: infix: ( | op word -- | ) [',
|
||||
' [',
|
||||
' -- format the word definition...',
|
||||
' -- NAME WORD -> :: NAME WORD',
|
||||
' s2b \\ :: -3 before b2s',
|
||||
'',
|
||||
' -- our template...',
|
||||
@ -580,14 +581,13 @@ var BOOTSTRAP = [
|
||||
' [ \\ exec 2 0 _swapN',
|
||||
' -- exec the right side and arragne the args for WORD...',
|
||||
' \\ exec \\ WORD 2 1 _swapN ] clone',
|
||||
' -- replace WORD with the actual target word...',
|
||||
' -- get the WORD and insert it into the template above (opsition 8)...',
|
||||
' swap 8 to',
|
||||
'',
|
||||
' -- push to code / run',
|
||||
' 3 0 _swapN ]',
|
||||
'',
|
||||
'-- formatter for the _infix word...',
|
||||
':: infix: ( | op word -- | ) [ \\ _infix 1 2 _swapN ]',
|
||||
' 3 0 _swapN ',
|
||||
' -- swap the arguments and the code to be executed...',
|
||||
' ] \\ exec 2 2 _swapN ]',
|
||||
'',
|
||||
'-- Now making a word/2 an infix operator is trivial...',
|
||||
'-- NOTE: these are at this point stupid and do not support priorities...',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user