20be503cae 2010-11-24 kinaba: /** c316790569 2010-11-21 kinaba: * Authors: k.inaba c316790569 2010-11-21 kinaba: * License: NYSL 0.9982 http://www.kmonos.net/nysl/ c316790569 2010-11-21 kinaba: * c316790569 2010-11-21 kinaba: * Definition of constants related to the layers. c316790569 2010-11-21 kinaba: */ c316790569 2010-11-21 kinaba: module polemy.layer; c316790569 2010-11-21 kinaba: import polemy._common; c316790569 2010-11-21 kinaba: c316790569 2010-11-21 kinaba: /// Type for the layer ID c316790569 2010-11-21 kinaba: c316790569 2010-11-21 kinaba: alias string Layer; c316790569 2010-11-21 kinaba: c316790569 2010-11-21 kinaba: enum : Layer c316790569 2010-11-21 kinaba: { 6ac127ddd0 2010-11-23 kinaba: SystemLayer = "(system)", /// Predefined layer for internal data 6ac127ddd0 2010-11-23 kinaba: ValueLayer = "@value", /// Predefined layer for normal run b97bd4f713 2010-11-23 kinaba: MacroLayer = "@macro", /// Predefined layer for macro run (@lay() changes layer) b97bd4f713 2010-11-23 kinaba: RawMacroLayer = "(rawmacro)", /// Predefined layer for macro run (@lay() becomes AST) 153a14cec0 2010-11-24 kinaba: } 153a14cec0 2010-11-24 kinaba: 153a14cec0 2010-11-24 kinaba: /// True if it is a user-defined layer 153a14cec0 2010-11-24 kinaba: 153a14cec0 2010-11-24 kinaba: bool isUserDefinedLayer( Layer lay ) 153a14cec0 2010-11-24 kinaba: { 153a14cec0 2010-11-24 kinaba: return lay!=SystemLayer && lay!=ValueLayer && lay!=MacroLayer && lay!=RawMacroLayer; 153a14cec0 2010-11-24 kinaba: } 153a14cec0 2010-11-24 kinaba: 153a14cec0 2010-11-24 kinaba: unittest 153a14cec0 2010-11-24 kinaba: { 153a14cec0 2010-11-24 kinaba: assert( !isUserDefinedLayer(SystemLayer) ); 153a14cec0 2010-11-24 kinaba: assert( !isUserDefinedLayer(ValueLayer) ); 153a14cec0 2010-11-24 kinaba: assert( !isUserDefinedLayer(MacroLayer) ); 153a14cec0 2010-11-24 kinaba: assert( !isUserDefinedLayer(RawMacroLayer) ); 153a14cec0 2010-11-24 kinaba: assert( isUserDefinedLayer("@foo") ); ba11f1d551 2010-11-23 kinaba: } ba11f1d551 2010-11-23 kinaba: 36c517dfc4 2010-11-23 kinaba: /// True if it is macro-like layer that basically generates syntax tree 36c517dfc4 2010-11-23 kinaba: ba11f1d551 2010-11-23 kinaba: bool isASTLayer( Layer lay ) b97bd4f713 2010-11-23 kinaba: { 153a14cec0 2010-11-24 kinaba: return lay==MacroLayer || lay==RawMacroLayer; 5e924caac9 2010-11-23 kinaba: } 5e924caac9 2010-11-23 kinaba: 5e924caac9 2010-11-23 kinaba: unittest 5e924caac9 2010-11-23 kinaba: { ba11f1d551 2010-11-23 kinaba: assert( !isASTLayer(SystemLayer) ); ba11f1d551 2010-11-23 kinaba: assert( !isASTLayer(ValueLayer) ); ba11f1d551 2010-11-23 kinaba: assert( isASTLayer(MacroLayer) ); ba11f1d551 2010-11-23 kinaba: assert( isASTLayer(RawMacroLayer) ); 36c517dfc4 2010-11-23 kinaba: } 36c517dfc4 2010-11-23 kinaba: 36c517dfc4 2010-11-23 kinaba: /// True if in the specified layer @lay(...) has no effect and merely produces a syntax tree b97bd4f713 2010-11-23 kinaba: b97bd4f713 2010-11-23 kinaba: bool isNoLayerChangeLayer( Layer lay ) b97bd4f713 2010-11-23 kinaba: { 153a14cec0 2010-11-24 kinaba: return lay==RawMacroLayer; 5e924caac9 2010-11-23 kinaba: } 5e924caac9 2010-11-23 kinaba: 5e924caac9 2010-11-23 kinaba: unittest 5e924caac9 2010-11-23 kinaba: { 5e924caac9 2010-11-23 kinaba: assert( !isNoLayerChangeLayer(SystemLayer) ); 5e924caac9 2010-11-23 kinaba: assert( !isNoLayerChangeLayer(ValueLayer) ); 5e924caac9 2010-11-23 kinaba: assert( !isNoLayerChangeLayer(MacroLayer) ); 5e924caac9 2010-11-23 kinaba: assert( isNoLayerChangeLayer(RawMacroLayer) ); ba11f1d551 2010-11-23 kinaba: } ba11f1d551 2010-11-23 kinaba: ba11f1d551 2010-11-23 kinaba: /// True if do macro expanstion ba11f1d551 2010-11-23 kinaba: ba11f1d551 2010-11-23 kinaba: bool isMacroLayer( Layer lay ) ba11f1d551 2010-11-23 kinaba: { ba11f1d551 2010-11-23 kinaba: return lay==MacroLayer || lay==RawMacroLayer; ba11f1d551 2010-11-23 kinaba: } ba11f1d551 2010-11-23 kinaba: ba11f1d551 2010-11-23 kinaba: unittest ba11f1d551 2010-11-23 kinaba: { ba11f1d551 2010-11-23 kinaba: assert( !isMacroLayer(SystemLayer) ); ba11f1d551 2010-11-23 kinaba: assert( !isMacroLayer(ValueLayer) ); ba11f1d551 2010-11-23 kinaba: assert( isMacroLayer(MacroLayer) ); ba11f1d551 2010-11-23 kinaba: assert( isMacroLayer(RawMacroLayer) ); c316790569 2010-11-21 kinaba: }