public void OneTimeSetUp() { templateHandlerNew = TemplateHandlerBuilder.Build(null); ITemplateContextHandlerPackageProvider <ITemplateContextHandler> templateContextHandlerPackageProvider = new TemplateContextHandlerPackageProvider <ITemplateContextHandler>(templateHandlerNew, null); _tested = new ContextVisitor <ITemplateContextHandler>(templateContextHandlerPackageProvider); }
public TemplateHandler(IList <ITypeMapping> typeMappings) { typeMappingsField = typeMappings?.ToList() ?? new List <ITypeMapping>(); templateContextHandlerProvider = new TemplateContextHandlerPackageProvider <AbstractTemplateContextHandler>(this, typeMappings); templateValidator = new TemplateValidator(this, typeMappings); contextVisitor = new ContextVisitor <AbstractTemplateContextHandler>(templateContextHandlerProvider); templateContextProcessor = new TemplateContextProcessor(this, typeMappings); toQualifiedTemplateContextConverter = new ToQualifiedTemplateContextConverter(this, typeMappings); }
/// <summary> /// For all subtrees that match the pattern, execute the visit action. /// </summary> /// <remarks> /// The implementation uses the root node of the pattern in combination /// with visit(t, ttype, visitor) so nil-rooted patterns are not allowed. /// Patterns with wildcard roots are also not allowed. /// </remarks> public void Visit(object t, string pattern, ContextVisitor visitor) { // Create a TreePattern from the pattern TreePatternLexer tokenizer = new TreePatternLexer(pattern); TreePatternParser parser = new TreePatternParser(tokenizer, this, new TreePatternTreeAdaptor()); TreePattern tpattern = (TreePattern)parser.Pattern(); // don't allow invalid patterns if ((tpattern == null) || tpattern.IsNil || (tpattern.GetType() == typeof(WildcardTreePattern))) { return; } //IDictionary labels = new Hashtable(); // reused for each _parse int rootTokenType = tpattern.Type; Visit(t, rootTokenType, new TreeWizard.InvokeVisitorOnPatternMatchContextVisitor(this, tpattern, visitor)); }
/// <summary>Do the recursive work for visit</summary> protected void _Visit(object t, object parent, int childIndex, int ttype, ContextVisitor visitor) { if (t == null) { return; } if (adaptor.GetNodeType(t) == ttype) { visitor.Visit(t, parent, childIndex, null); } int n = adaptor.GetChildCount(t); for (int i = 0; i < n; i++) { object child = adaptor.GetChild(t, i); _Visit(child, t, i, ttype, visitor); } }
/// <summary> /// For all subtrees that match the pattern, execute the visit action. /// </summary> /// <remarks> /// The implementation uses the root node of the pattern in combination /// with visit(t, ttype, visitor) so nil-rooted patterns are not allowed. /// Patterns with wildcard roots are also not allowed. /// </remarks> public void Visit(object t, string pattern, ContextVisitor visitor) { // CreateInstance a TreePattern from the pattern TreePatternLexer tokenizer = new TreePatternLexer(pattern); TreePatternParser parser = new TreePatternParser(tokenizer, this, new TreePatternTreeAdaptor()); TreePattern tpattern = (TreePattern)parser.Pattern(); // don't allow invalid patterns if ((tpattern == null) || tpattern.IsNil || (tpattern.GetType() == typeof(WildcardTreePattern))) { return; } //IDictionary labels = new Hashtable(); // reused for each _parse int rootTokenType = tpattern.Type; Visit(t, rootTokenType, new TreeWizard.InvokeVisitorOnPatternMatchContextVisitor(this, tpattern, visitor)); }
/// <summary> /// Visit every ttype node in t, invoking the visitor. /// </summary> /// <remarks> /// This is a quicker /// version of the general visit(t, pattern) method. The labels arg /// of the visitor action method is never set (it's null) since using /// a token type rather than a pattern doesn't let us set a label. /// </remarks> public void Visit(object t, int ttype, ContextVisitor visitor) { _Visit(t, null, 0, ttype, visitor); }
public InvokeVisitorOnPatternMatchContextVisitor(TreeWizard owner, TreePattern pattern, ContextVisitor visitor) { this.owner = owner; this.pattern = pattern; this.visitor = visitor; }
public TemplatePreprocessor(ITemplateHandler templateHandlerNew, IList <ITypeMapping> typeMappings) { preprocessorContextHandlerRegister = new TemplateContextHandlerPackageProvider <AbstactPreprocessorContextHandler>(templateHandlerNew, typeMappings); contextVisitor = new ContextVisitor <AbstactPreprocessorContextHandler>(preprocessorContextHandlerRegister); }