Differences From Artifact [59dc790b72d21ee0]:
- File
polemy/layer.d
- 2010-11-23 10:37:54 - part of checkin [5e924caac9] on branch trunk - added AST-rewriting macro sample. (user: kinaba) [annotate]
To Artifact [bd983db748e0ad6a]:
- File
polemy/layer.d
- 2010-11-23 18:28:47 - part of checkin [ba11f1d551] on branch trunk - fixed the macro scoping rules concerning non-macro let (user: kinaba) [annotate]
13 13
14 14 enum : Layer
15 15 {
16 16 SystemLayer = "(system)", /// Predefined layer for internal data
17 17 ValueLayer = "@value", /// Predefined layer for normal run
18 18 MacroLayer = "@macro", /// Predefined layer for macro run (@lay() changes layer)
19 19 RawMacroLayer = "(rawmacro)", /// Predefined layer for macro run (@lay() becomes AST)
20 + AstLayer = "(ast)", /// Predefined layer for macro run (never invoke macro)
20 21 }
21 22
22 23 /// True if it is macro-like layer that basically generates syntax tree
23 24
24 -bool isMacroishLayer( Layer lay )
25 +bool isASTLayer( Layer lay )
25 26 {
26 - return lay==MacroLayer || lay==RawMacroLayer;
27 + return lay==MacroLayer || lay==RawMacroLayer || lay==AstLayer;
27 28 }
28 29
29 30 unittest
30 31 {
31 - assert( !isMacroishLayer(SystemLayer) );
32 - assert( !isMacroishLayer(ValueLayer) );
33 - assert( isMacroishLayer(MacroLayer) );
34 - assert( isMacroishLayer(RawMacroLayer) );
32 + assert( !isASTLayer(SystemLayer) );
33 + assert( !isASTLayer(ValueLayer) );
34 + assert( isASTLayer(MacroLayer) );
35 + assert( isASTLayer(RawMacroLayer) );
36 + assert( isASTLayer(AstLayer) );
35 37 }
36 38
37 39 /// True if in the specified layer @lay(...) has no effect and merely produces a syntax tree
38 40
39 41 bool isNoLayerChangeLayer( Layer lay )
40 42 {
41 - return lay==RawMacroLayer;
43 + return lay==RawMacroLayer || lay==AstLayer;
42 44 }
43 45
44 46 unittest
45 47 {
46 48 assert( !isNoLayerChangeLayer(SystemLayer) );
47 49 assert( !isNoLayerChangeLayer(ValueLayer) );
48 50 assert( !isNoLayerChangeLayer(MacroLayer) );
49 51 assert( isNoLayerChangeLayer(RawMacroLayer) );
52 + assert( isNoLayerChangeLayer(AstLayer) );
53 +}
54 +
55 +/// True if do macro expanstion
56 +
57 +bool isMacroLayer( Layer lay )
58 +{
59 + return lay==MacroLayer || lay==RawMacroLayer;
60 +}
61 +
62 +unittest
63 +{
64 + assert( !isMacroLayer(SystemLayer) );
65 + assert( !isMacroLayer(ValueLayer) );
66 + assert( isMacroLayer(MacroLayer) );
67 + assert( isMacroLayer(RawMacroLayer) );
68 + assert( !isMacroLayer(AstLayer) );
50 69 }