Artifact Content
Not logged in

Artifact 70a85e9a66eddacd698f7a5f37a74d1c3a006dac


/**
 * Authors: k.inaba
 * License: NYSL 0.9982 http://www.kmonos.net/nysl/
 *
 * Definition of constants related to the layers.
 */
module polemy.layer;
import polemy._common;

/// Type for the layer ID

alias string Layer;

enum : Layer
{
	SystemLayer   = "(system)",   /// Predefined layer for internal data
	ValueLayer    = "@value",     /// Predefined layer for normal run
	MacroLayer    = "@macro",     /// Predefined layer for macro run (@lay() changes layer)
	RawMacroLayer = "(rawmacro)", /// Predefined layer for macro run (@lay() becomes AST)
}

/// True if it is a user-defined layer

bool isUserDefinedLayer( Layer lay )
{
	return lay!=SystemLayer && lay!=ValueLayer && lay!=MacroLayer && lay!=RawMacroLayer;
}

unittest
{
	assert( !isUserDefinedLayer(SystemLayer) );
	assert( !isUserDefinedLayer(ValueLayer) );
	assert( !isUserDefinedLayer(MacroLayer) );
	assert( !isUserDefinedLayer(RawMacroLayer) );
	assert( isUserDefinedLayer("@foo") );
}

/// True if it is macro-like layer that basically generates syntax tree

bool isASTLayer( Layer lay )
{
	return lay==MacroLayer || lay==RawMacroLayer;
}

unittest
{
	assert( !isASTLayer(SystemLayer) );
	assert( !isASTLayer(ValueLayer) );
	assert( isASTLayer(MacroLayer) );
	assert( isASTLayer(RawMacroLayer) );
}

/// True if in the specified layer @lay(...) has no effect and merely produces a syntax tree

bool isNoLayerChangeLayer( Layer lay )
{
	return lay==RawMacroLayer;
}

unittest
{
	assert( !isNoLayerChangeLayer(SystemLayer) );
	assert( !isNoLayerChangeLayer(ValueLayer) );
	assert( !isNoLayerChangeLayer(MacroLayer) );
	assert( isNoLayerChangeLayer(RawMacroLayer) );
}

/// True if do macro expanstion

bool isMacroLayer( Layer lay )
{
	return lay==MacroLayer || lay==RawMacroLayer;
}

unittest
{
	assert( !isMacroLayer(SystemLayer) );
	assert( !isMacroLayer(ValueLayer) );
	assert( isMacroLayer(MacroLayer) );
	assert( isMacroLayer(RawMacroLayer) );
}