static void TermToThisBlock(ETF_TextBlock block,Term term) { //this is Block if (!string.IsNullOrEmpty(term.TupleVal[0].StrVal)) block.Name = term.TupleVal[0].StrVal; //other for (int i = 1; i < term.TupleVal.Count; i++) { if (term.TupleVal[i].GetTermType() == TermType.SMALL_TUPLE) { //this is Attribute //TODO : Может и стоит добавить пару лишних проверок)), но пока можно // отлаживать, это тут мы увидем, а потом нахуй) block.SetAttribute(term.TupleVal[i].TupleVal[0].StrVal, //atom Name term.TupleVal[i].TupleVal[1].ToString(), //Some value term.TupleVal[i].TupleVal[1].GetTermType());//type } else if (term.TupleVal[i].GetTermType() == TermType.LIST) { //this is childrens foreach (Term t in term.TupleVal[i].TupleVal) { ETF_TextBlock tmp = block.AddChild("t"); TermToThisBlock(tmp, t); } } else throw new Exception("TermToBlock: wait List, have" + term.TupleVal[i].GetTermType().ToString() + " at:" + i.ToString() + "\n Term: " + term.ToString()); } }
static bool LoadChild( ETF_TextBlock child, bool ifEmptyLexReturnTrue ) { while( true ) { bool lexIntoQuotes; string lex = GetLexeme( false, out lexIntoQuotes ); if( lex.Length == 0 )//if( lex == "" ) { if( ifEmptyLexReturnTrue ) return true; Error( "Unexpected end of file" ); return false; } if( lex == "}" ) return true; string lex2 = GetLexeme( false ); if( lex2.Length == 0 )//if( lex2 == "" ) { Error( "Unexpected end of file" ); return false; } if( lex2 == "=" ) { string s_type = GetLexeme( true ); TermType t_type=ETF_TextBlock.StringToTermType(s_type,true); if (t_type==TermType.ERROR) { Error( "Invalid type description" ); return false; } if (t_type==TermType.ERLANG_BINARY) child.SetAttribute( lex, s_type,TermType.STRING ); else { string value = GetLexeme( true ); child.SetAttribute( lex, value,t_type ); } continue; } if( lex2 == "{" ) { ETF_TextBlock c = child.AddChild(lex); if( !LoadChild( c, false ) ) return false; continue; } string lex3 = GetLexeme( false ); if( lex3.Length == 0 )//if( lex3 == "" ) { Error( "Unexpected end of file" ); return false; } if( lex3 == "{" ) { ETF_TextBlock c = child.AddChild(lex, lex2); if( !LoadChild( c, false ) ) return false; continue; } Error( "Invalid file format" ); return false; } }