fixed: program_mode was not set in cctor

fixed: container was not correctly parsed (in template mode)




git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@1139 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2018-11-01 21:52:33 +00:00
parent a6b767a223
commit bf62d44346
3 changed files with 58 additions and 59 deletions

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2007-2015, Tomasz Sowa * Copyright (c) 2007-2018, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -363,6 +363,7 @@ Generator<StreamType>::Generator() : empty_stream()
can_find_in_cache = true; can_find_in_cache = true;
can_use_vars = true; can_use_vars = true;
expression_parser = nullptr; expression_parser = nullptr;
program_mode = false;
} }
@ -396,6 +397,7 @@ Generator<StreamType> & Generator<StreamType>::operator=(const Generator<StreamT
block_stack_size = n.block_stack_size; block_stack_size = n.block_stack_size;
ezc_out_stack_size = n.ezc_out_stack_size; ezc_out_stack_size = n.ezc_out_stack_size;
expression_parser = n.expression_parser; expression_parser = n.expression_parser;
program_mode = n.program_mode;
// vars doesn't have to be copied // vars doesn't have to be copied

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2007-2016, Tomasz Sowa * Copyright (c) 2007-2018, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -55,6 +55,7 @@ PatternParser::PatternParser()
pblocks = 0; pblocks = 0;
include_level_max = 100; include_level_max = 100;
delete_white_text_items = false; delete_white_text_items = false;
program_mode = false;
} }
@ -241,9 +242,7 @@ void PatternParser::ParseString(const wchar_t * str, Pattern & pattern)
include_level = 0; include_level = 0;
pat->item_root.Clear(); pat->item_root.Clear();
pat->item_root.type = Item::item_container; CreateTreeContainer(pat->item_root);
CreateTree(pat->item_root);
} }
@ -1061,8 +1060,7 @@ void PatternParser::CreateTreeReadIncludeSkipAllowFlag(Item & item)
itext = file_text.c_str(); itext = file_text.c_str();
item.Clear(); item.Clear();
item.type = Item::item_container; CreateTreeContainer(item);
CreateTree(item);
itext = itext_old; itext = itext_old;
--include_level; --include_level;
@ -1076,11 +1074,9 @@ void PatternParser::CreateTreeReadIf(Item & item)
pitem->Clear(); pitem->Clear();
if( program_mode ) if( program_mode )
pitem->type = Item::item_none; CreateTree(*pitem);
else else
pitem->type = Item::item_container; CreateTreeContainer(*pitem);
CreateTree(*pitem);
if( program_mode ) if( program_mode )
{ {
@ -1100,7 +1096,7 @@ void PatternParser::CreateTreeReadIf(Item & item)
pitem->DeleteLastItem(); pitem->DeleteLastItem();
pitem = item.AddItem(); pitem = item.AddItem();
CreateTree(*pitem); CreateTreeContainer(*pitem);
} }
} }
@ -1112,12 +1108,9 @@ void PatternParser::CreateTreeReadIf(Item & item)
void PatternParser::CreateTreeReadBlock(Item & item) void PatternParser::CreateTreeReadBlock(Item & item)
{ {
Item item_block; Item item_block;
item_block.Clear(); CreateTreeContainer(item_block);
item_block.type = Item::item_container;
CreateTree(item_block);
if( item_block.LastItemType() == Item::item_end ) if( item_block.LastItemType() == Item::item_end )
item_block.DeleteLastItem(); item_block.DeleteLastItem();
@ -1132,14 +1125,11 @@ Item item_block;
void PatternParser::CreateTreeReadFor(Item & item) void PatternParser::CreateTreeReadFor(Item & item)
{ {
Item * pitem = item.AddItem(); Item * pitem = item.AddItem();
pitem->Clear();
if( program_mode ) if( program_mode )
pitem->type = Item::item_none; CreateTree(*pitem);
else else
pitem->type = Item::item_container; CreateTreeContainer(*pitem);
CreateTree(*pitem);
if( pitem->LastItemType() == Item::item_end ) if( pitem->LastItemType() == Item::item_end )
pitem->DeleteLastItem(); pitem->DeleteLastItem();
@ -1147,52 +1137,58 @@ void PatternParser::CreateTreeReadFor(Item & item)
void PatternParser::CreateTree(Item & item) bool PatternParser::CreateTree(Item & item)
{ {
do do
{ {
Item * pitem; if( !CreateTreeReadItem(item) )
if( item.type != Item::item_container )
pitem = &item;
else
pitem = item.AddItem();
do
{ {
if( !CreateTreeReadItem(*pitem) ) return false;
{
if( item.type == Item::item_container )
item.DeleteLastItem();
return;
}
if( pitem->type == Item::item_block )
CreateTreeReadBlock(*pitem);
} }
while( pitem->type == Item::item_comment ||
pitem->type == Item::item_block );
if( pitem->type == Item::item_end || pitem->type == Item::item_else ) if( item.type == Item::item_block )
return; CreateTreeReadBlock(item);
if( pitem->type == Item::item_if )
CreateTreeReadIf(*pitem);
if( pitem->type == Item::item_for ||
pitem->type == Item::item_filter ||
pitem->type == Item::item_ezc )
CreateTreeReadFor(*pitem);
if( pitem->type == Item::item_include )
CreateTreeReadInclude(*pitem);
} }
while( item.type == Item::item_container ); while( item.type == Item::item_comment || item.type == Item::item_block );
// such container can be read in program mode
if( item.type == Item::item_container )
CreateTreeContainer(item);
if( item.type == Item::item_if )
CreateTreeReadIf(item);
// CHECK ME is it correct to check item_filter and item_ezc here and call CreateTreeReadFor?
if( item.type == Item::item_for ||
item.type == Item::item_filter ||
item.type == Item::item_ezc )
CreateTreeReadFor(item);
if( item.type == Item::item_include )
CreateTreeReadInclude(item);
return true;
} }
void PatternParser::CreateTreeContainer(Item & item)
{
bool item_read_correctly;
Item * pitem;
item.type = Item::item_container;
do
{
pitem = item.AddItem();
item_read_correctly = CreateTree(*pitem);
}
while( item_read_correctly && pitem->type != Item::item_end && pitem->type != Item::item_else);
if( !item_read_correctly )
item.DeleteLastItem();
}

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2007-2016, Tomasz Sowa * Copyright (c) 2007-2018, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -188,7 +188,8 @@ private:
void CreateTreeReadIf(Item & item); void CreateTreeReadIf(Item & item);
void CreateTreeReadBlock(Item & item); void CreateTreeReadBlock(Item & item);
void CreateTreeReadFor(Item & item); void CreateTreeReadFor(Item & item);
void CreateTree(Item & item); bool CreateTree(Item & item);
void CreateTreeContainer(Item & item);
void CreateTreeReadInclude(Item & item); void CreateTreeReadInclude(Item & item);
void CreateTreeReadIncludeSkipAllowFlag(Item & item); void CreateTreeReadIncludeSkipAllowFlag(Item & item);