/// <summary> /// Iterate over each part of the model file, and letting the caller handle them. /// /// This allows much faster reading of a file if you're only interested in one /// specific part of it. /// </summary> /// <param name="filepath">The name of the file to open</param> public static void VisitModel(string filepath, SectionVisitor visitor) { using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs)) { List <SectionHeader> headers = ReadHeaders(br); foreach (SectionHeader header in headers) { fs.Position = header.Start; visitor(br, header); } } } }
public override FormNode VisitFormDeclaration([NotNull] FormDeclarationContext context) { if (context.children.Any(x => x.GetType() == typeof(ErrorNodeImpl))) { return(null); } // Construct FormNode object to store the results in. var name = context.formName().GetText(); FormNode node = new FormNode(Location.FromContext(context), name); // Get the sections SectionContext[] sectionContext = context.section(); SectionVisitor visitor = new SectionVisitor(); foreach (SectionContext ctx in sectionContext) { node.AddNode(visitor.VisitSection(ctx)); } return(node); }
public override IElement VisitElement([NotNull] ElementContext context) { var sectionContext = context.section(); if (sectionContext != null) { var sectionVisitor = new SectionVisitor().Inherit(this); var section = sectionVisitor.VisitSection(sectionContext); return(section); } var sectionElementContext = context.sectionElement(); if (sectionElementContext != null) { var elementVisitor = new ElementVisitor().Inherit(this); var element = elementVisitor.VisitSectionElement(context.sectionElement()); return(element); } //TODO: throw a better exception. throw new InvalidOperationException(); }