Beispiel #1
0
        public override object /* NodeList */ VisitContent(XMLParser.ContentContext context)
        {
            var result = new AntlrNodeList();

            for (int i = 0; i < context.ChildCount; ++i)
            {
                var c = context.GetChild(i);
                if (c is XMLParser.ChardataContext cc)
                {
                    var rc = VisitChardata(cc) as XmlText;
                    result.Add(rc);
                }
                else if (c is XMLParser.ElementContext e)
                {
                    var re = VisitElement(e) as XmlElement;
                    result.Add(re);
                }
            }
            return(result);
        }
Beispiel #2
0
        public override object /* XmlDocument */ VisitDocument(XMLParser.DocumentContext context)
        {
            var document = new XmlDocument();

            document.NodeType = NodeConstants.DOCUMENT_NODE;
            var           element = VisitElement(context.element()) as XmlElement;
            AntlrNodeList nl      = new AntlrNodeList();

            nl.Add(element);
            document.ChildNodes = nl;
            element.ParentNode  = document;
            return(document);
        }
Beispiel #3
0
        private static XmlNode BottomUpConvert(IParseTree tree, Parser parser)
        {
            if (tree is TerminalNodeImpl)
            {
                var result = new XmlElement();
                result.AntlrIParseTree = tree;
                TerminalNodeImpl t        = tree as TerminalNodeImpl;
                Interval         interval = t.SourceInterval;
                result.NodeType = NodeConstants.ELEMENT_NODE;
                var common_token_stream = parser.InputStream as CommonTokenStream;
                var lexer      = common_token_stream.TokenSource as Lexer;
                var fixed_name = parser.Vocabulary.GetSymbolicName(t.Symbol.Type);
                result.LocalName = fixed_name;
                var nl = new AntlrNodeList();
                result.ChildNodes = nl;

                var child = new XmlText();
                child.AntlrIParseTree = tree;
                child.NodeType        = NodeConstants.TEXT_NODE;
                child.Data            = new xpath.org.eclipse.wst.xml.xpath2.processor.@internal.OutputParseTree().PerformEscapes(/*"'" + */ tree.GetText() /*+ "'"*/);
                child.ParentNode      = result;
                nl.Add(child);

                {
                    var attr        = new XmlAttr();
                    var child_count = t.ChildCount;
                    attr.NodeType   = NodeConstants.ATTRIBUTE_NODE;
                    attr.Name       = "ChildCount";
                    attr.Value      = child_count.ToString();
                    attr.ParentNode = result;
                    nl.Add(attr);
                }

                {
                    var attr = new XmlAttr();
                    attr.NodeType = NodeConstants.ATTRIBUTE_NODE;
                    var source_interval = t.SourceInterval;
                    var a = source_interval.a;
                    var b = source_interval.b;
                    attr.Name       = "SourceInterval";
                    attr.Value      = "[" + a + "," + b + "]";
                    attr.ParentNode = result;
                    nl.Add(attr);
                }

                return(result);
            }
            else
            {
                var result = new XmlElement();
                var t      = tree as ParserRuleContext;
                result.AntlrIParseTree = tree;
                result.NodeType        = NodeConstants.ELEMENT_NODE;
                var x    = tree as RuleContext;
                var ri   = x.RuleIndex;
                var name = parser.RuleNames[ri];
                result.LocalName = name;
                var nl = new AntlrNodeList();
                result.ChildNodes = nl;

                var map = new AntlrNamedNodeMap();
                result.Attributes = map;

                {
                    var attr        = new XmlAttr();
                    var child_count = t.ChildCount;
                    attr.NodeType   = NodeConstants.ATTRIBUTE_NODE;
                    attr.Name       = "ChildCount";
                    attr.LocalName  = "ChildCount";
                    attr.Value      = child_count.ToString();
                    attr.ParentNode = result;
                    nl.Add(attr);
                    map.Add(attr);
                }

                {
                    var attr = new XmlAttr();
                    attr.NodeType = NodeConstants.ATTRIBUTE_NODE;
                    var source_interval = t.SourceInterval;
                    var a = source_interval.a;
                    var b = source_interval.b;
                    attr.Name       = "Start";
                    attr.LocalName  = "Start";
                    attr.Value      = a.ToString();
                    attr.ParentNode = result;
                    nl.Add(attr);
                    map.Add(attr);
                }
                {
                    var attr = new XmlAttr();
                    attr.NodeType = NodeConstants.ATTRIBUTE_NODE;
                    var source_interval = t.SourceInterval;
                    var a = source_interval.a;
                    var b = source_interval.b;
                    attr.Name       = "End";
                    attr.LocalName  = "End";
                    attr.Value      = b.ToString();
                    attr.ParentNode = result;
                    nl.Add(attr);
                    map.Add(attr);
                }

                for (int i = 0; i < tree.ChildCount; ++i)
                {
                    var child   = tree.GetChild(i);
                    var convert = BottomUpConvert(child, parser);
                    nl.Add(convert);
                    convert.ParentNode = result;
                }

                return(result);
            }
        }