AST Builder is confusing

52 views
Skip to first unread message

Chris Anders

unread,
Jan 18, 2015, 7:28:11 AM1/18/15
to eto-...@googlegroups.com
ive solved with a new literal string.

ive tried to build an AST-Builder.

It creates the correct class and sets correct a string property, but when i have another AST-Object as property it doesnt work.


using System;
using System.Reflection;
using Eto.Parse;

namespace etosql
{
   
public class SyntaxTree
   
{
       
public static object Build(Match m)
       
{
           
foreach (var mm in m.Matches)
           
{
               
foreach (var mmm in mm.Matches)
               
{
                   
foreach (var type in Assembly.GetEntryAssembly().GetTypes())
                   
{
                       
if (type.BaseType != null) {
                           
if (type.BaseType.Name == typeof(IAst).Name)
                           
{
                               
var obj = (IAst)Activator.CreateInstance(type);

                               
if (obj.Name == mm.Name)
                               
{
                                   
var props = type.GetProperties();
                                   
for (int i = 0; i < props.Length; i++)
                                   
{
                                       
if (props[i].PropertyType.BaseType.Name == typeof(IAst).Name)
                                       
{
                                            props
[i].SetValue(obj, SyntaxTree.Build(mm), null);

                                           
continue;
                                       
}
                                       
else if (props[i].Name == mmm.Name)
                                       
{
                                            props
[i].SetValue(obj, mmm.StringValue, null);
                                       
}
                                   
}
                                   
return obj;
                               
}
                           
}
                       
}
                   
}
               
}
           
}

           
return null;
       
}
   
}
}


Reply all
Reply to author
Forward
0 new messages