5 |
*/ |
*/ |
6 |
|
|
7 |
/* |
/* |
8 |
* Copyright (c) 2007-2016, Tomasz Sowa |
* Copyright (c) 2007-2018, Tomasz Sowa |
9 |
* All rights reserved. |
* All rights reserved. |
10 |
* |
* |
11 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
55 |
pblocks = 0; |
pblocks = 0; |
56 |
include_level_max = 100; |
include_level_max = 100; |
57 |
delete_white_text_items = false; |
delete_white_text_items = false; |
58 |
|
program_mode = false; |
59 |
} |
} |
60 |
|
|
61 |
|
|
242 |
include_level = 0; |
include_level = 0; |
243 |
|
|
244 |
pat->item_root.Clear(); |
pat->item_root.Clear(); |
245 |
pat->item_root.type = Item::item_container; |
CreateTreeContainer(pat->item_root); |
|
|
|
|
CreateTree(pat->item_root); |
|
246 |
} |
} |
247 |
|
|
248 |
|
|
1060 |
itext = file_text.c_str(); |
itext = file_text.c_str(); |
1061 |
|
|
1062 |
item.Clear(); |
item.Clear(); |
1063 |
item.type = Item::item_container; |
CreateTreeContainer(item); |
|
CreateTree(item); |
|
1064 |
|
|
1065 |
itext = itext_old; |
itext = itext_old; |
1066 |
--include_level; |
--include_level; |
1074 |
pitem->Clear(); |
pitem->Clear(); |
1075 |
|
|
1076 |
if( program_mode ) |
if( program_mode ) |
1077 |
pitem->type = Item::item_none; |
CreateTree(*pitem); |
1078 |
else |
else |
1079 |
pitem->type = Item::item_container; |
CreateTreeContainer(*pitem); |
1080 |
|
|
|
CreateTree(*pitem); |
|
|
|
|
1081 |
if( program_mode ) |
if( program_mode ) |
1082 |
{ |
{ |
1083 |
SkipWhite(); |
SkipWhite(); |
1096 |
pitem->DeleteLastItem(); |
pitem->DeleteLastItem(); |
1097 |
|
|
1098 |
pitem = item.AddItem(); |
pitem = item.AddItem(); |
1099 |
CreateTree(*pitem); |
CreateTreeContainer(*pitem); |
1100 |
} |
} |
1101 |
} |
} |
1102 |
|
|
1108 |
|
|
1109 |
void PatternParser::CreateTreeReadBlock(Item & item) |
void PatternParser::CreateTreeReadBlock(Item & item) |
1110 |
{ |
{ |
1111 |
Item item_block; |
Item item_block; |
1112 |
|
|
1113 |
item_block.Clear(); |
CreateTreeContainer(item_block); |
|
item_block.type = Item::item_container; |
|
1114 |
|
|
|
CreateTree(item_block); |
|
|
|
|
1115 |
if( item_block.LastItemType() == Item::item_end ) |
if( item_block.LastItemType() == Item::item_end ) |
1116 |
item_block.DeleteLastItem(); |
item_block.DeleteLastItem(); |
1117 |
|
|
1125 |
void PatternParser::CreateTreeReadFor(Item & item) |
void PatternParser::CreateTreeReadFor(Item & item) |
1126 |
{ |
{ |
1127 |
Item * pitem = item.AddItem(); |
Item * pitem = item.AddItem(); |
|
pitem->Clear(); |
|
1128 |
|
|
1129 |
if( program_mode ) |
if( program_mode ) |
1130 |
pitem->type = Item::item_none; |
CreateTree(*pitem); |
1131 |
else |
else |
1132 |
pitem->type = Item::item_container; |
CreateTreeContainer(*pitem); |
1133 |
|
|
|
CreateTree(*pitem); |
|
|
|
|
1134 |
if( pitem->LastItemType() == Item::item_end ) |
if( pitem->LastItemType() == Item::item_end ) |
1135 |
pitem->DeleteLastItem(); |
pitem->DeleteLastItem(); |
1136 |
} |
} |
1137 |
|
|
1138 |
|
|
1139 |
|
|
1140 |
void PatternParser::CreateTree(Item & item) |
bool PatternParser::CreateTree(Item & item) |
1141 |
{ |
{ |
1142 |
do |
do |
1143 |
{ |
{ |
1144 |
Item * pitem; |
if( !CreateTreeReadItem(item) ) |
1145 |
|
{ |
1146 |
|
return false; |
1147 |
|
} |
1148 |
|
|
1149 |
if( item.type != Item::item_container ) |
if( item.type == Item::item_block ) |
1150 |
pitem = &item; |
CreateTreeReadBlock(item); |
1151 |
else |
} |
1152 |
pitem = item.AddItem(); |
while( item.type == Item::item_comment || item.type == Item::item_block ); |
1153 |
|
|
1154 |
do |
// such container can be read in program mode |
1155 |
{ |
if( item.type == Item::item_container ) |
1156 |
if( !CreateTreeReadItem(*pitem) ) |
CreateTreeContainer(item); |
|
{ |
|
|
if( item.type == Item::item_container ) |
|
|
item.DeleteLastItem(); |
|
1157 |
|
|
1158 |
return; |
if( item.type == Item::item_if ) |
1159 |
} |
CreateTreeReadIf(item); |
1160 |
|
|
1161 |
if( pitem->type == Item::item_block ) |
// CHECK ME is it correct to check item_filter and item_ezc here and call CreateTreeReadFor? |
1162 |
CreateTreeReadBlock(*pitem); |
if( item.type == Item::item_for || |
1163 |
} |
item.type == Item::item_filter || |
1164 |
while( pitem->type == Item::item_comment || |
item.type == Item::item_ezc ) |
1165 |
pitem->type == Item::item_block ); |
CreateTreeReadFor(item); |
1166 |
|
|
1167 |
if( pitem->type == Item::item_end || pitem->type == Item::item_else ) |
if( item.type == Item::item_include ) |
1168 |
return; |
CreateTreeReadInclude(item); |
1169 |
|
|
1170 |
if( pitem->type == Item::item_if ) |
return true; |
1171 |
CreateTreeReadIf(*pitem); |
} |
1172 |
|
|
|
if( pitem->type == Item::item_for || |
|
|
pitem->type == Item::item_filter || |
|
|
pitem->type == Item::item_ezc ) |
|
|
CreateTreeReadFor(*pitem); |
|
1173 |
|
|
1174 |
if( pitem->type == Item::item_include ) |
void PatternParser::CreateTreeContainer(Item & item) |
1175 |
CreateTreeReadInclude(*pitem); |
{ |
1176 |
|
bool item_read_correctly; |
1177 |
|
Item * pitem; |
1178 |
|
|
1179 |
|
item.type = Item::item_container; |
1180 |
|
|
1181 |
|
do |
1182 |
|
{ |
1183 |
|
pitem = item.AddItem(); |
1184 |
|
item_read_correctly = CreateTree(*pitem); |
1185 |
} |
} |
1186 |
while( item.type == Item::item_container ); |
while( item_read_correctly && pitem->type != Item::item_end && pitem->type != Item::item_else); |
1187 |
|
|
1188 |
|
if( !item_read_correctly ) |
1189 |
|
item.DeleteLastItem(); |
1190 |
} |
} |
|
|
|
1191 |
|
|
1192 |
|
|
1193 |
|
|