start working on a 'program mode'
a new syntax for simple scripting git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@1134 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
|
||||
|
||||
#include "patternparser.h"
|
||||
#include "convert/convert.h"
|
||||
|
||||
#ifdef EZC_USE_WINIX_LOGGER
|
||||
#include "core/log.h"
|
||||
@@ -155,6 +156,11 @@ void PatternParser::SetCommentary(const std::wstring & com_start, const std::wst
|
||||
}
|
||||
|
||||
|
||||
void PatternParser::SetProgramMode(bool program_mode)
|
||||
{
|
||||
this->program_mode = program_mode;
|
||||
}
|
||||
|
||||
|
||||
void PatternParser::CreateMsg(std::wstring & out, const wchar_t * type, const wchar_t * arg)
|
||||
{
|
||||
@@ -186,6 +192,7 @@ void PatternParser::ParseFile(const char * file_name, Pattern & pattern)
|
||||
pat = &pattern;
|
||||
PT::UTF8ToWide(file_name, pat->item_root.file_name);
|
||||
include_level = 0;
|
||||
|
||||
CreateTreeReadIncludeSkipAllowFlag(pat->item_root);
|
||||
}
|
||||
|
||||
@@ -232,6 +239,10 @@ void PatternParser::ParseString(const wchar_t * str, Pattern & pattern)
|
||||
pat = &pattern;
|
||||
itext = str;
|
||||
include_level = 0;
|
||||
|
||||
pat->item_root.Clear();
|
||||
pat->item_root.type = Item::item_container;
|
||||
|
||||
CreateTree(pat->item_root);
|
||||
}
|
||||
|
||||
@@ -875,21 +886,142 @@ int c;
|
||||
}
|
||||
|
||||
|
||||
void PatternParser::CreateTreeReadDirectiveExpression(Item & item, wchar_t starting_terminator, wchar_t ending_terminator)
|
||||
{
|
||||
long terminator_counter = 1;
|
||||
|
||||
while( *itext )
|
||||
{
|
||||
wchar_t c = *itext;
|
||||
|
||||
if( c == 10 || c == 13 )
|
||||
c = ' ';
|
||||
|
||||
if( c == starting_terminator )
|
||||
{
|
||||
terminator_counter += 1;
|
||||
}
|
||||
|
||||
if( c == ending_terminator )
|
||||
{
|
||||
terminator_counter -= 1;
|
||||
|
||||
if( terminator_counter == 0 )
|
||||
{
|
||||
itext += 1;
|
||||
return; // end of expression;
|
||||
}
|
||||
}
|
||||
|
||||
if( !IsWhite(c) || item.text.empty() || !IsWhite(item.text.back()) )
|
||||
item.text += c;
|
||||
|
||||
itext += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool PatternParser::CreateTreeCheckProgramDirective(Item & item)
|
||||
{
|
||||
if( PT::IsSubStringNoCasep(L"if", itext) )
|
||||
{
|
||||
itext += 2;
|
||||
SkipWhite();
|
||||
|
||||
if( *itext == '(' )
|
||||
{
|
||||
itext += 1;
|
||||
item.type = Item::item_if;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.type = Item::item_err;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( PT::IsSubStringNoCasep(L"while", itext) )
|
||||
{
|
||||
itext += 5;
|
||||
SkipWhite();
|
||||
|
||||
if( *itext == '(' )
|
||||
{
|
||||
itext += 1;
|
||||
item.type = Item::item_for;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.type = Item::item_err;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PatternParser::CreateTreeReadExpression(Item & item)
|
||||
{
|
||||
SkipWhite();
|
||||
|
||||
if( *itext == 0 )
|
||||
return false;
|
||||
|
||||
if( *itext == '{' )
|
||||
{
|
||||
item.type = Item::item_container;
|
||||
itext += 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if( *itext == '}' )
|
||||
{
|
||||
item.type = Item::item_end;
|
||||
itext += 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
if( CreateTreeCheckProgramDirective(item) )
|
||||
{
|
||||
CreateTreeReadDirectiveExpression(item, '(', ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
if( item.type == Item::item_err )
|
||||
return false;
|
||||
|
||||
item.type = Item::item_function;
|
||||
CreateTreeReadDirectiveExpression(item, 0, ';');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PatternParser::CreateTreeReadItem(Item & item)
|
||||
{
|
||||
item.Clear();
|
||||
|
||||
if( *itext == '[' )
|
||||
if( program_mode )
|
||||
{
|
||||
CreateTreeReadItemDirective(item);
|
||||
return true;
|
||||
return CreateTreeReadExpression(item);
|
||||
}
|
||||
else
|
||||
if( *itext )
|
||||
{
|
||||
CreateTreeReadItemText(item);
|
||||
return true;
|
||||
if( *itext == '[' )
|
||||
{
|
||||
CreateTreeReadItemDirective(item);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if( *itext )
|
||||
{
|
||||
CreateTreeReadItemText(item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// the end of the string
|
||||
@@ -931,7 +1063,11 @@ void PatternParser::CreateTreeReadIncludeSkipAllowFlag(Item & item)
|
||||
|
||||
const wchar_t * itext_old = itext;
|
||||
itext = file_text.c_str();
|
||||
|
||||
item.Clear();
|
||||
item.type = Item::item_container;
|
||||
CreateTree(item);
|
||||
|
||||
itext = itext_old;
|
||||
--include_level;
|
||||
}
|
||||
@@ -941,14 +1077,35 @@ void PatternParser::CreateTreeReadIncludeSkipAllowFlag(Item & item)
|
||||
void PatternParser::CreateTreeReadIf(Item & item)
|
||||
{
|
||||
Item * pitem = item.AddItem();
|
||||
pitem->Clear();
|
||||
|
||||
if( program_mode )
|
||||
pitem->type = Item::item_none;
|
||||
else
|
||||
pitem->type = Item::item_container;
|
||||
|
||||
CreateTree(*pitem);
|
||||
|
||||
if( pitem->LastItemType() == Item::item_else )
|
||||
if( program_mode )
|
||||
{
|
||||
pitem->DeleteLastItem();
|
||||
SkipWhite();
|
||||
|
||||
pitem = item.AddItem();
|
||||
CreateTree(*pitem);
|
||||
if( PT::IsSubStringNoCasep(L"else", itext) )
|
||||
{
|
||||
itext += 4;
|
||||
pitem = item.AddItem();
|
||||
CreateTree(*pitem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( pitem->LastItemType() == Item::item_else )
|
||||
{
|
||||
pitem->DeleteLastItem();
|
||||
|
||||
pitem = item.AddItem();
|
||||
CreateTree(*pitem);
|
||||
}
|
||||
}
|
||||
|
||||
if( pitem->LastItemType() == Item::item_end )
|
||||
@@ -961,6 +1118,9 @@ void PatternParser::CreateTreeReadBlock(Item & item)
|
||||
{
|
||||
Item item_block;
|
||||
|
||||
item_block.Clear();
|
||||
item_block.type = Item::item_container;
|
||||
|
||||
CreateTree(item_block);
|
||||
|
||||
if( item_block.LastItemType() == Item::item_end )
|
||||
@@ -976,6 +1136,13 @@ Item item_block;
|
||||
void PatternParser::CreateTreeReadFor(Item & item)
|
||||
{
|
||||
Item * pitem = item.AddItem();
|
||||
pitem->Clear();
|
||||
|
||||
if( program_mode )
|
||||
pitem->type = Item::item_none;
|
||||
else
|
||||
pitem->type = Item::item_container;
|
||||
|
||||
CreateTree(*pitem);
|
||||
|
||||
if( pitem->LastItemType() == Item::item_end )
|
||||
@@ -986,18 +1153,22 @@ void PatternParser::CreateTreeReadFor(Item & item)
|
||||
|
||||
void PatternParser::CreateTree(Item & item)
|
||||
{
|
||||
item.Clear();
|
||||
item.type = Item::item_container;
|
||||
|
||||
while( true )
|
||||
do
|
||||
{
|
||||
Item * pitem = item.AddItem();
|
||||
Item * pitem;
|
||||
|
||||
if( item.type != Item::item_container )
|
||||
pitem = &item;
|
||||
else
|
||||
pitem = item.AddItem();
|
||||
|
||||
do
|
||||
{
|
||||
if( !CreateTreeReadItem(*pitem) )
|
||||
{
|
||||
item.DeleteLastItem();
|
||||
if( item.type == Item::item_container )
|
||||
item.DeleteLastItem();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1021,6 +1192,8 @@ void PatternParser::CreateTree(Item & item)
|
||||
if( pitem->type == Item::item_include )
|
||||
CreateTreeReadInclude(*pitem);
|
||||
}
|
||||
while( item.type == Item::item_container );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user