mirror of
https://github.com/flynx/Slang.git
synced 2025-10-29 18:50:08 +00:00
removed imbeded quotes from strings...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
3a4e85455b
commit
26e85e907d
@ -54,7 +54,7 @@ function run(context){
|
|||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
|
|
||||||
var SPLITTER = /\s*\([^\)]*\)\s*|\s*--.*[\n$]|\s*(".*")\s*|\s*('.*')\s*|\s+/m
|
var SPLITTER = /\s*\([^\)]*\)\s*|\s*--.*[\n$]|\s*"([^"]*)"\s*|\s*'([^']*)'\s*|\s+/m
|
||||||
|
|
||||||
|
|
||||||
// pre-processor namespace...
|
// pre-processor namespace...
|
||||||
@ -435,16 +435,18 @@ var BOOTSTRAP = '\n'+
|
|||||||
'-- like exec but will run a block in current context...\n'+
|
'-- like exec but will run a block in current context...\n'+
|
||||||
':: b2c [ len rot b2s tor 0 _swapN ]\n'+
|
':: b2c [ len rot b2s tor 0 _swapN ]\n'+
|
||||||
'\n'+
|
'\n'+
|
||||||
':: . ( x -- ) [ print drop ]\n'+
|
':: . ( x -- ) [ drop ]\n'+
|
||||||
|
':: .. ( x -- ) [ print drop ]\n'+
|
||||||
'\n'+
|
'\n'+
|
||||||
':: swap2 ( a _ b -- b _ a ) [ swap rot swap tor swap ]\n'+
|
':: swap2 ( a _ b -- b _ a ) [ swap rot swap tor swap ]\n'+
|
||||||
':: dup2 ( a b -- a b a b ) [ dup swap2 dup rot swap2 tor swap ]\n'+
|
':: dup2 ( a b -- a b a b ) [ dup swap2 dup rot swap2 tor swap ]\n'+
|
||||||
'\n'+
|
'\n'+
|
||||||
|
':: ne ( a -- b ) [ eq not ]\n'+
|
||||||
':: isT ( a -- b ) [ not not true eq ]\n'+
|
':: isT ( a -- b ) [ not not true eq ]\n'+
|
||||||
':: isF ( a -- b ) [ not isT ]\n'+
|
':: isF ( a -- b ) [ not isT ]\n'+
|
||||||
//'\n'+
|
'\n'+
|
||||||
//'-- this defines a classic [ cond ] [ A ] [ B ] if word... (a bit too polish IMHO)\n'+
|
'-- this defines a classic [ cond ] [ A ] [ B ] if word... (a bit too polish IMHO)\n'+
|
||||||
//':: if ( cond a b -- ... ) [ rot rot exec isT tor and tor or exec ]\n'+
|
':: if ( cond a b -- ... ) [ rot rot exec isT tor and tor or exec ]\n'+
|
||||||
'\n'+
|
'\n'+
|
||||||
'-- helpers for the ternary operator...\n'+
|
'-- helpers for the ternary operator...\n'+
|
||||||
'-- run then block and drop \'else B\' if it exists...\n'+
|
'-- run then block and drop \'else B\' if it exists...\n'+
|
||||||
@ -470,6 +472,9 @@ var BOOTSTRAP = '\n'+
|
|||||||
':: push ( b e i -- b ) [ -1 before ]\n'+
|
':: push ( b e i -- b ) [ -1 before ]\n'+
|
||||||
'\n'+
|
'\n'+
|
||||||
'\n'+
|
'\n'+
|
||||||
|
':: inc ( a -- b ) [ 1 add ]\n'+
|
||||||
|
':: dec ( a -- b ) [ 1 sub ]\n'+
|
||||||
|
'\n'+
|
||||||
'-- experimental...\n'+
|
'-- experimental...\n'+
|
||||||
'-- NOTE: these are at this point stupid and do not support priorities or grouping...\n'+
|
'-- NOTE: these are at this point stupid and do not support priorities or grouping...\n'+
|
||||||
'-- NOTE: these have both stack and code effect, in genera the operations are of \n'+
|
'-- NOTE: these have both stack and code effect, in genera the operations are of \n'+
|
||||||
@ -491,8 +496,8 @@ var BOOTSTRAP = '\n'+
|
|||||||
'-- tests and examples...\n'+
|
'-- tests and examples...\n'+
|
||||||
':: hi ( -- ) [ "Hello World!" print drop ]\n'+
|
':: hi ( -- ) [ "Hello World!" print drop ]\n'+
|
||||||
//'-- NOTE: nop at the end is a stub to fix a bug in ? else ...\n'+
|
//'-- NOTE: nop at the end is a stub to fix a bug in ? else ...\n'+
|
||||||
//':: ! ( a -- b ) [ [ dup 1 eq not ] ? [ dup 1 sub ! mul ] nop ]\n'+
|
//':: ! ( a -- b ) [ [ dup 1 ne ] ? [ dup 1 sub ! mul ] nop ]\n'+
|
||||||
':: ! ( a -- b ) [ [ dup 1 eq not ] ? [ dup 1 sub ! mul ] ]\n'+
|
':: ! ( a -- b ) [ [ dup 1 ne ] ? [ dup 1 sub ! mul ] ]\n'+
|
||||||
':: range ( n -- b ) [\n'+
|
':: range ( n -- b ) [\n'+
|
||||||
' -- initial state...\n'+
|
' -- initial state...\n'+
|
||||||
' [ dup isNumber ] ? \n'+
|
' [ dup isNumber ] ? \n'+
|
||||||
@ -541,7 +546,8 @@ function slang(code, context){
|
|||||||
context = context == null ? CONTEXT : context
|
context = context == null ? CONTEXT : context
|
||||||
|
|
||||||
if(typeof(code) == typeof('abc')){
|
if(typeof(code) == typeof('abc')){
|
||||||
code = [ '"'+code+'"', 'lex', 'prep', 'exec' ]
|
//code = [ '"'+code+'"', 'lex', 'prep', 'exec' ]
|
||||||
|
code = [ code, 'lex', 'prep', 'exec' ]
|
||||||
} else {
|
} else {
|
||||||
code = [ [code], 'b2s', 'prep', 'exec' ]
|
code = [ [code], 'b2s', 'prep', 'exec' ]
|
||||||
}
|
}
|
||||||
@ -552,5 +558,47 @@ function slang(code, context){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************** RSlang ***/
|
||||||
|
|
||||||
|
var RS_PRE_NAMESPACE = {
|
||||||
|
// XXX using the ";" here just for the experiment, in the real thing
|
||||||
|
// if this thing pans out, that is, use indent... (a-la make/Python)
|
||||||
|
// XXX this reads ahead at the moment, but it must read back...
|
||||||
|
';': function(context){
|
||||||
|
var line = []
|
||||||
|
var code = context.code
|
||||||
|
var cur = code.splice(0, 1)[0]
|
||||||
|
while(cur != ';' && code.length > 0){
|
||||||
|
line.push(cur)
|
||||||
|
cur = code.splice(0, 1)[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
context.code.splice.apply(context.code, [0, 0].concat(line.reverse()))
|
||||||
|
},
|
||||||
|
|
||||||
|
'[': PRE_NAMESPACE['['],
|
||||||
|
'macro:': PRE_NAMESPACE['macro:'],
|
||||||
|
}
|
||||||
|
|
||||||
|
RS_CONTEXT = {
|
||||||
|
stack: [],
|
||||||
|
code: STARTUP.slice(),
|
||||||
|
ns: NAMESPACE,
|
||||||
|
pre_ns: PRE_NAMESPACE,
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: we use the traditional bootstrap for this...
|
||||||
|
run(RS_CONTEXT)
|
||||||
|
|
||||||
|
RS_CONTEXT.pre_ns = RS_PRE_NAMESPACE
|
||||||
|
|
||||||
|
function rslang(code, context){
|
||||||
|
context = context == null ? RS_CONTEXT : context
|
||||||
|
|
||||||
|
return slang(code, context)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* vim:set ts=4 sw=4 : */
|
* vim:set ts=4 sw=4 : */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user