| | |
| | |
| | |
| | |
| | |
| |
|
| | import "class" : is-instance ; |
| | import errors ; |
| |
|
| |
|
| | |
| | |
| | rule apply-default-suffix ( suffix : list * ) |
| | { |
| | local result ; |
| | for local i in $(list) |
| | { |
| | if $(i:S) = $(suffix) |
| | { |
| | result += $(i) ; |
| | } |
| | else |
| | { |
| | result += $(i)$(suffix) ; |
| | } |
| | } |
| | return $(result) ; |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | rule basename ( name ) |
| | { |
| | if $(name:S) |
| | { |
| | name = $(name:B) ; |
| | } |
| | return $(name) ; |
| | } |
| |
|
| |
|
| | |
| | |
| | rule caller-file ( ) |
| | { |
| | local bt = [ BACKTRACE ] ; |
| | return $(bt[9]) ; |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | rule equal ( a b ) |
| | { |
| | if [ is-instance $(a) ] |
| | { |
| | return [ $(a).equal $(b) ] ; |
| | } |
| | else |
| | { |
| | if $(a) = $(b) |
| | { |
| | return true ; |
| | } |
| | } |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | rule less ( a b ) |
| | { |
| | if [ is-instance $(a) ] |
| | { |
| | return [ $(a).less $(b) ] ; |
| | } |
| | else |
| | { |
| | if $(a) < $(b) |
| | { |
| | return true ; |
| | } |
| | } |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | rule str ( value ) |
| | { |
| | if [ is-instance $(value) ] |
| | { |
| | return [ $(value).str ] ; |
| | } |
| | else |
| | { |
| | return $(value) ; |
| | } |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | rule ungrist ( names * ) |
| | { |
| | local result ; |
| | for local name in $(names) |
| | { |
| | local stripped = [ MATCH ^<(.*)>$ : $(name) ] ; |
| | if ! $(stripped) |
| | { |
| | errors.error "in ungrist $(names) : $(name) is not of the form <.*>" ; |
| | } |
| | result += $(stripped) ; |
| | } |
| | return $(result) ; |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | rule unquote ( value ? ) |
| | { |
| | local match-result = [ MATCH ^(\")(.*)(\")$ : $(value) ] ; |
| | if $(match-result) |
| | { |
| | return $(match-result[2]) ; |
| | } |
| | else |
| | { |
| | return $(value) ; |
| | } |
| | } |
| | |
| | |
| | rule __test__ ( ) |
| | { |
| | import assert ; |
| | import "class" : new ; |
| | import errors : try catch ; |
| | |
| | assert.result 123 : str 123 ; |
| | |
| | class test-class__ |
| | { |
| | rule __init__ ( ) { } |
| | rule str ( ) { return "str-test-class" ; } |
| | rule less ( a ) { return "yes, of course!" ; } |
| | rule equal ( a ) { return "not sure" ; } |
| | } |
| | |
| | assert.result "str-test-class" : str [ new test-class__ ] ; |
| | assert.true less 1 2 ; |
| | assert.false less 2 1 ; |
| | assert.result "yes, of course!" : less [ new test-class__ ] 1 ; |
| | assert.true equal 1 1 ; |
| | assert.false equal 1 2 ; |
| | assert.result "not sure" : equal [ new test-class__ ] 1 ; |
| | |
| | assert.result foo.lib foo.lib : apply-default-suffix .lib : foo.lib foo.lib |
| | ; |
| | |
| | assert.result foo : basename foo ; |
| | assert.result foo : basename foo.so ; |
| | assert.result foo.so : basename foo.so.1 ; |
| | |
| | assert.result : unquote ; |
| | assert.result "" : unquote "" ; |
| | assert.result foo : unquote foo ; |
| | assert.result \"foo : unquote \"foo ; |
| | assert.result foo\" : unquote foo\" ; |
| | assert.result foo : unquote \"foo\" ; |
| | assert.result \"foo\" : unquote \"\"foo\"\" ; |
| | |
| | assert.result : ungrist ; |
| | assert.result foo : ungrist <foo> ; |
| | assert.result <foo> : ungrist <<foo>> ; |
| | assert.result foo bar : ungrist <foo> <bar> ; |
| | |
| | try ; |
| | { |
| | ungrist "" ; |
| | } |
| | catch "in ungrist : is not of the form <.*>" ; |
| | |
| | try ; |
| | { |
| | ungrist <> ; |
| | } |
| | catch "in ungrist <> : <> is not of the form <.*>" ; |
| | |
| | try ; |
| | { |
| | ungrist foo ; |
| | } |
| | catch "in ungrist foo : foo is not of the form <.*>" ; |
| | |
| | try ; |
| | { |
| | ungrist <foo ; |
| | } |
| | catch "in ungrist <foo : <foo is not of the form <.*>" ; |
| | |
| | try ; |
| | { |
| | ungrist foo> ; |
| | } |
| | catch "in ungrist foo> : foo> is not of the form <.*>" ; |
| | |
| | try ; |
| | { |
| | ungrist foo bar ; |
| | } |
| | catch "in ungrist foo : foo is not of the form <.*>" ; |
| | |
| | try ; |
| | { |
| | ungrist foo <bar> ; |
| | } |
| | catch "in ungrist foo : foo is not of the form <.*>" ; |
| | |
| | try ; |
| | { |
| | ungrist <foo> bar ; |
| | } |
| | catch "in ungrist bar : bar is not of the form <.*>" ; |
| | } |
| | |