diff --git a/build_system.htm b/build_system.htm index 8e90b17a0..6ec1afc93 100644 --- a/build_system.htm +++ b/build_system.htm @@ -1527,24 +1527,33 @@ IMPORT m1 : m2 : r1 x : r2 y ; # imports m2.r1 as r2 and m2.x as y into m1
CALLER_MODULE returns the name of the module scope - enclosing the call to its caller. If the scope belongs to the global + enclosing the call to its caller (if levels is supplied, it is + interpreted as an integer number of additional levels of call stack to + traverse to locate the module). If the scope belongs to the global module, or if no such module exists, returns the empty list. For - example, the following prints "{Y}": + example, the following prints "{Y} {X}":-rule CALLER_MODULE ( ) +rule CALLER_MODULE ( levels ? )
module X { rule get-caller { return [ CALLER_MODULE ] ; } + rule get-caller's-caller { return [ CALLER_MODULE 1 ] ; } + + rule call-Y { return Y.call-X2 ; } + } module Y { - rule call-X { X.get-caller ; } + rule call-X { return X.get-caller ; } + rule call-X2 { return X.get-caller's-caller ; } } -callers = [ X.get-caller ] [ Y.call-X ] ; + +callers = [ X.get-caller ] [ Y.call-X ] [ X.call-Y ] ; ECHO {$(callers)} ; +Like the module declaration syntax and the IMPORT rule, this rule is a diff --git a/v1/build_system.htm b/v1/build_system.htm index 8e90b17a0..6ec1afc93 100644 --- a/v1/build_system.htm +++ b/v1/build_system.htm @@ -1527,24 +1527,33 @@ IMPORT m1 : m2 : r1 x : r2 y ; # imports m2.r1 as r2 and m2.x as y into m1CALLER_MODULE returns the name of the module scope - enclosing the call to its caller. If the scope belongs to the global + enclosing the call to its caller (if levels is supplied, it is + interpreted as an integer number of additional levels of call stack to + traverse to locate the module). If the scope belongs to the global module, or if no such module exists, returns the empty list. For - example, the following prints "{Y}": + example, the following prints "{Y} {X}":-rule CALLER_MODULE ( ) +rule CALLER_MODULE ( levels ? )module X { rule get-caller { return [ CALLER_MODULE ] ; } + rule get-caller's-caller { return [ CALLER_MODULE 1 ] ; } + + rule call-Y { return Y.call-X2 ; } + } module Y { - rule call-X { X.get-caller ; } + rule call-X { return X.get-caller ; } + rule call-X2 { return X.get-caller's-caller ; } } -callers = [ X.get-caller ] [ Y.call-X ] ; + +callers = [ X.get-caller ] [ Y.call-X ] [ X.call-Y ] ; ECHO {$(callers)} ; +Like the module declaration syntax and the IMPORT rule, this rule is a