Beispiel #1
0
        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();
            }