Example #1
0
        protected void ToDOTDefineNodes(object tree, ITreeAdaptor adaptor, StringTemplate treeST)
        {
            if (tree == null)
            {
                return;
            }
            int n = adaptor.GetChildCount(tree);

            if (n == 0)
            {
                // must have already dumped as child from previous
                // invocation; do nothing
                return;
            }

            // define parent node
            StringTemplate parentNodeST = GetNodeST(adaptor, tree);

            treeST.SetAttribute("nodes", parentNodeST);

            // for each child, do a "<unique-name> [label=text]" node def
            for (int i = 0; i < n; i++)
            {
                object         child  = adaptor.GetChild(tree, i);
                StringTemplate nodeST = GetNodeST(adaptor, child);
                treeST.SetAttribute("nodes", nodeST);
                ToDOTDefineNodes(child, adaptor, treeST);
            }
        }
Example #2
0
        protected void ToDOTDefineEdges(object tree, ITreeAdaptor adaptor, StringTemplate treeST)
        {
            if (tree == null)
            {
                return;
            }
            int n = adaptor.GetChildCount(tree);

            if (n == 0)
            {
                // must have already dumped as child from previous
                // invocation; do nothing
                return;
            }

            string parentName = "n" + GetNodeNumber(tree);

            // for each child, do a parent -> child edge using unique node names
            string parentText = adaptor.GetNodeText(tree);

            for (int i = 0; i < n; i++)
            {
                object         child     = adaptor.GetChild(tree, i);
                string         childText = adaptor.GetNodeText(child);
                string         childName = "n" + GetNodeNumber(child);
                StringTemplate edgeST    = _edgeST.GetInstanceOf();
                edgeST.SetAttribute("parent", parentName);
                edgeST.SetAttribute("child", childName);
                edgeST.SetAttribute("parentText", parentText);
                edgeST.SetAttribute("childText", childText);
                treeST.SetAttribute("edges", edgeST);
                ToDOTDefineEdges(child, adaptor, treeST);
            }
        }
 public DebugTreeNodeStream(ITreeNodeStream input, IDebugEventListener dbg)
 {
     this.input   = input;
     this.adaptor = input.TreeAdaptor;
     this.input.HasUniqueNavigationNodes = true;
     SetDebugListener(dbg);
 }
 public DebugTreeNodeStream(ITreeNodeStream input, IDebugEventListener dbg)
 {
     this.input = input;
     this.adaptor = input.TreeAdaptor;
     this.input.HasUniqueNavigationNodes = true;
     SetDebugListener(dbg);
 }
        protected void ExtractInformationFromTreeNodeStream(IIntStream input)
        {
            ITreeNodeStream nodes = (ITreeNodeStream)input;

            this.node = nodes.LT(1);
            ITreeAdaptor adaptor = nodes.TreeAdaptor;
            IToken       payload = adaptor.GetToken(node);

            if (payload != null)
            {
                this.token = payload;
                if (payload.Line <= 0)
                {
                    // imaginary node; no line/pos info; scan backwards
                    int    i         = -1;
                    object priorNode = nodes.LT(i);
                    while (priorNode != null)
                    {
                        IToken priorPayload = adaptor.GetToken(priorNode);
                        if ((priorPayload != null) && (priorPayload.Line > 0))
                        {
                            // we found the most recent real line / pos info
                            this.line = priorPayload.Line;
                            this.charPositionInLine  = priorPayload.CharPositionInLine;
                            this.approximateLineInfo = true;
                            break;
                        }
                        --i;
                        priorNode = nodes.LT(i);
                    }
                }
                else
                {
                    // node created from real token
                    this.line = payload.Line;
                    this.charPositionInLine = payload.CharPositionInLine;
                }
            }
            else if (this.node is ITree)
            {
                this.line = ((ITree)this.node).Line;
                this.charPositionInLine = ((ITree)this.node).CharPositionInLine;
                if (this.node is CommonTree)
                {
                    this.token = ((CommonTree)this.node).Token;
                }
            }
            else
            {
                int    type = adaptor.GetNodeType(this.node);
                string text = adaptor.GetNodeText(this.node);
                this.token = new CommonToken(type, text);
            }
        }
        public BaseTreeVisualizerForm(ITreeAdaptor adaptor, object tree, ITokenStream tokenStream, string sourceText)
        {
            if (adaptor == null)
                throw new ArgumentNullException("adaptor");
            if (tree == null)
                throw new ArgumentNullException("tree");

            InitializeComponent();

            TreeVisualizerViewModel viewModel = new TreeVisualizerViewModel(adaptor, tree, tokenStream, sourceText);
            ((BaseTreeVisualizerViewControl)elementHost1.Child).ViewModel = viewModel;
        }
Example #7
0
        protected StringTemplate GetNodeST(ITreeAdaptor adaptor, object t)
        {
            string         text       = adaptor.GetNodeText(t);
            StringTemplate nodeST     = _nodeST.GetInstanceOf();
            string         uniqueName = "n" + GetNodeNumber(t);

            nodeST.SetAttribute("name", uniqueName);
            if (text != null)
            {
                text = text.Replace("\"", "\\\\\"");
            }
            nodeST.SetAttribute("text", text);
            return(nodeST);
        }
Example #8
0
        public static void Visualize(this ITreeAdaptor treeAdaptor, object tree, ITokenStream tokenStream, IWin32Window owner)
        {
            if (treeAdaptor == null)
            {
                throw new ArgumentNullException("treeAdaptor");
            }
            if (tree == null)
            {
                throw new ArgumentNullException("tree");
            }

            BaseTreeVisualizerForm visualizer = new BaseTreeVisualizerForm(treeAdaptor, tree, tokenStream);

            visualizer.ShowDialog(owner);
        }
Example #9
0
        public StringTemplate ToDOT(object tree, ITreeAdaptor adaptor, StringTemplate _treeST, StringTemplate _edgeST)
        {
            StringTemplate treeST = _treeST.GetInstanceOf();

            nodeNumber = 0;
            ToDOTDefineNodes(tree, adaptor, treeST);
            nodeNumber = 0;
            ToDOTDefineEdges(tree, adaptor, treeST);

            /*
             * if ( adaptor.GetChildCount(tree)==0 ) {
             *      // single node, don't do edge.
             *      treeST.SetAttribute("nodes", adaptor.GetNodeText(tree));
             * }
             */
            return(treeST);
        }
Example #10
0
        public BaseTreeVisualizerForm(ITreeAdaptor adaptor, object tree, ITokenStream tokenStream, string sourceText)
        {
            if (adaptor == null)
            {
                throw new ArgumentNullException("adaptor");
            }
            if (tree == null)
            {
                throw new ArgumentNullException("tree");
            }

            InitializeComponent();

            TreeVisualizerViewModel viewModel = new TreeVisualizerViewModel(adaptor, tree, tokenStream, sourceText);

            ((BaseTreeVisualizerViewControl)elementHost1.Child).ViewModel = viewModel;
        }
 public BaseTreeVisualizerForm(ITreeAdaptor adaptor, object tree)
     : this(adaptor, tree, null, null)
 {
 }
Example #12
0
 public BaseTreeVisualizerForm(ITreeAdaptor adaptor, object tree, string sourceText)
     : this(adaptor, tree, null, sourceText)
 {
 }
		public DebugEventSocketProxy(BaseRecognizer recognizer, ITreeAdaptor adaptor)
			: this(recognizer, DEFAULT_DEBUGGER_PORT, adaptor)
		{
		}
Example #14
0
        public virtual void Rewrite( ITreeAdaptor adaptor, CommonTree t, string[] tokenNames )
        {
            TreeWizard wiz = new TreeWizard( adaptor, tokenNames );

            // ACTIONS STUFF
            wiz.Visit( t, ANTLRParser.ACTION, ( tree ) =>
            {
                ACTION( tokens, (CommonTree)tree );
            } );

            // ^('@' id ACTION) rule actions
            wiz.Visit( t, ANTLRParser.AMPERSAND, ( tree ) =>
            {
                CommonTree a = (CommonTree)t;
                CommonTree action = null;
                if (a.ChildCount == 2)
                {
                    action = (CommonTree)a.GetChild(1);
                }
                else if (a.ChildCount == 3)
                {
                    action = (CommonTree)a.GetChild(2);
                }

                if ( action.Type == ANTLRParser.ACTION )
                {
                    tokens.Delete( a.TokenStartIndex, a.TokenStopIndex );
                    KillTrailingNewline( tokens, action.TokenStopIndex );
                }
            } );

            wiz.Visit( t, ANTLRParser.ACTION, ( tree ) =>
            {
            } );

            // wipe rule arguments
            wiz.Visit( t, ANTLRParser.ARG, ( tree ) =>
            {
                CommonTree a = (CommonTree)t;
                a = (CommonTree)a.GetChild( 0 );
                tokens.Delete( a.Token.TokenIndex );
                KillTrailingNewline( tokens, a.Token.TokenIndex );
            } );

            // wipe rule return declarations
            wiz.Visit( t, ANTLRParser.RET, ( tree ) =>
            {
                CommonTree a = (CommonTree)t;
                CommonTree ret = (CommonTree)a.GetChild( 0 );
                tokens.Delete( a.Token.TokenIndex, ret.Token.TokenIndex );
            } );

            // comment out semantic predicates
            wiz.Visit( t, ANTLRParser.SEMPRED, ( tree ) =>
            {
                CommonTree a = (CommonTree)t;
                tokens.Replace( a.Token.TokenIndex, "/*" + a.Text + "*/" );
            } );

            // comment out semantic predicates
            wiz.Visit( t, ANTLRParser.GATED_SEMPRED, ( tree ) =>
            {
                CommonTree a = (CommonTree)t;
                string text = tokens.ToString( a.TokenStartIndex, a.TokenStopIndex );
                tokens.Replace( a.TokenStartIndex, a.TokenStopIndex, "/*" + text + "*/" );
            } );

            // comment scope specs
            wiz.Visit( t, ANTLRParser.SCOPE, ( tree ) =>
            {
                CommonTree a = (CommonTree)t;
                tokens.Delete( a.TokenStartIndex, a.TokenStopIndex );
                KillTrailingNewline( tokens, a.TokenStopIndex );
            } );

            // args r[x,y] -> ^(r [x,y])
            wiz.Visit( t, ANTLRParser.ARG_ACTION, ( tree ) =>
            {
                CommonTree a = (CommonTree)t;
                if ( a.Parent.Type == ANTLRParser.RULE_REF )
                    tokens.Delete( a.TokenStartIndex, a.TokenStopIndex );
            } );

            #if false // what is this token type in the C# ported version of the V3 grammar?
            // ^('=' id ^(RULE_REF [arg])), ...
            wiz.Visit( t, ANTLRParser.LABEL_ASSIGN, ( tree ) =>
            {
                CommonTree a = (CommonTree)t;
                if ( !a.HasAncestor( ANTLRParser.OPTIONS ) )
                {
                    // avoid options
                    CommonTree child = (CommonTree)a.GetChild( 0 );
                    // kill "id="
                    tokens.Delete( a.token.TokenIndex );
                    tokens.Delete( child.token.TokenIndex );
                }
            } );
            #endif

            #if false // what is this token type in the C# ported version of the V3 grammar?
            // ^('+=' id ^(RULE_REF [arg])), ...
            wiz.Visit( t, ANTLRParser.LIST_LABEL_ASSIGN, ( tree ) =>
            {
                CommonTree a = (CommonTree)t;
                CommonTree child = (CommonTree)a.GetChild( 0 );
                // kill "id+="
                tokens.Delete( a.token.TokenIndex );
                tokens.Delete( child.token.TokenIndex );
            } );
            #endif

            // AST STUFF

            wiz.Visit( t, ANTLRParser.REWRITE, ( tree ) =>
            {
                CommonTree a = (CommonTree)t;
                CommonTree child = (CommonTree)a.GetChild( 0 );
                int stop = child.TokenStopIndex;
                if ( child.Type == ANTLRParser.SEMPRED )
                {
                    CommonTree rew = (CommonTree)a.GetChild( 1 );
                    stop = rew.TokenStopIndex;
                }
                tokens.Delete( a.Token.TokenIndex, stop );
                KillTrailingNewline( tokens, stop );
            } );

            wiz.Visit( t, ANTLRParser.ROOT, ( tree ) =>
            {
                tokens.Delete( ( (CommonTree)t ).Token.TokenIndex );
            } );

            wiz.Visit( t, ANTLRParser.BANG, ( tree ) =>
            {
                tokens.Delete( ( (CommonTree)t ).Token.TokenIndex );
            } );
        }
Example #15
0
 public static void Visualize(this ITreeAdaptor treeAdaptor, object tree, IWin32Window owner)
 {
     Visualize(treeAdaptor, tree, null, owner);
 }
Example #16
0
        protected void ToDOTDefineNodes(object tree, ITreeAdaptor adaptor, StringTemplate treeST)
        {
            if ( tree == null )
            {
                return;
            }
            int n = adaptor.GetChildCount(tree);
            if ( n == 0 )
            {
                // must have already dumped as child from previous
                // invocation; do nothing
                return;
            }

            // define parent node
            StringTemplate parentNodeST = GetNodeST(adaptor, tree);
            treeST.SetAttribute("nodes", parentNodeST);

            // for each child, do a "<unique-name> [label=text]" node def
            for (int i = 0; i < n; i++)
            {
                object child = adaptor.GetChild(tree, i);
                StringTemplate nodeST = GetNodeST(adaptor, child);
                treeST.SetAttribute("nodes", nodeST);
                ToDOTDefineNodes(child, adaptor, treeST);
            }
        }
 public BaseTreeVisualizerForm(ITreeAdaptor adaptor, object tree, ITokenStream tokenStream)
     : this(adaptor, tree, tokenStream, null)
 {
 }
Example #18
0
 public TraceDebugEventListener(ITreeAdaptor adaptor) {
     this.adaptor = adaptor;
 }
Example #19
0
 public DebugEventSocketProxy(BaseRecognizer recognizer, ITreeAdaptor adaptor)
     : this(recognizer, DEFAULT_DEBUGGER_PORT, adaptor)
 {
 }
Example #20
0
 public DebugEventSocketProxy(BaseRecognizer recognizer, ITreeAdaptor adaptor) :
     this(recognizer, DefaultDebuggerPort, adaptor)
 {
 }
Example #21
0
 public BaseTreeVisualizerForm(ITreeAdaptor adaptor, object tree, ITokenStream tokenStream)
     : this(adaptor, tree, tokenStream, null)
 {
 }
Example #22
0
 public BaseTreeVisualizerForm(ITreeAdaptor adaptor, object tree)
     : this(adaptor, tree, null, null)
 {
 }
 public BaseTreeVisualizerForm(ITreeAdaptor adaptor, object tree, string sourceText)
     : this(adaptor, tree, null, sourceText)
 {
 }
 public TraceDebugEventListenerEx(ITreeAdaptor adaptor)
     : base(adaptor)
 {
 }
Example #25
0
 public TraceDebugEventListener(ITreeAdaptor adaptor)
 {
     this.adaptor = adaptor;
 }
Example #26
0
 public DebugEventSocketProxy(BaseRecognizer recognizer, int port, ITreeAdaptor adaptor)
 {
     this.grammarFileName = recognizer.GrammarFileName;
     this.port            = port;
     this.adaptor         = adaptor;
 }
Example #27
0
 public StringTemplate ToDOT(object tree, ITreeAdaptor adaptor, StringTemplate _treeST, StringTemplate _edgeST)
 {
     StringTemplate treeST = _treeST.GetInstanceOf();
     nodeNumber = 0;
     ToDOTDefineNodes(tree, adaptor, treeST);
     nodeNumber = 0;
     ToDOTDefineEdges(tree, adaptor, treeST);
     /*
     if ( adaptor.GetChildCount(tree)==0 ) {
         // single node, don't do edge.
         treeST.SetAttribute("nodes", adaptor.GetNodeText(tree));
     }
     */
     return treeST;
 }
Example #28
0
 public DebugEventSocketProxy(BaseRecognizer recognizer, ITreeAdaptor adaptor) :
     this(recognizer, DefaultDebuggerPort, adaptor) {
 }
Example #29
0
 protected StringTemplate GetNodeST(ITreeAdaptor adaptor, object t)
 {
     string text = adaptor.GetNodeText(t);
     StringTemplate nodeST = _nodeST.GetInstanceOf();
     string uniqueName = "n" + GetNodeNumber(t);
     nodeST.SetAttribute("name", uniqueName);
     if (text != null)
         text = text.Replace("\"", "\\\\\"");
     nodeST.SetAttribute("text", text);
     return nodeST;
 }
Example #30
0
 partial void CreateTreeAdaptor(ref ITreeAdaptor adaptor)
 {
     adaptor = new StringTemplateTreeAdaptor();
 }
Example #31
0
 public static void Visualize(this ITreeAdaptor treeAdaptor, object tree)
 {
     Visualize(treeAdaptor, tree, default(ITokenStream));
 }
Example #32
0
 public StringTemplate ToDOT(object tree, ITreeAdaptor adaptor)
 {
     return ToDOT(tree, adaptor, _treeST, _edgeST);
 }
Example #33
0
        public virtual void Rewrite(ITreeAdaptor adaptor, CommonTree t, string[] tokenNames)
        {
            TreeWizard wiz = new TreeWizard(adaptor, tokenNames);

            // ACTIONS STUFF
            wiz.Visit(t, ANTLRParser.ACTION, (tree) =>
            {
                ACTION(tokens, (CommonTree)tree);
            });

            // ^('@' id ACTION) rule actions
            wiz.Visit(t, ANTLRParser.AMPERSAND, (tree) =>
            {
                CommonTree a      = (CommonTree)t;
                CommonTree action = null;
                if (a.ChildCount == 2)
                {
                    action = (CommonTree)a.GetChild(1);
                }
                else if (a.ChildCount == 3)
                {
                    action = (CommonTree)a.GetChild(2);
                }

                if (action.Type == ANTLRParser.ACTION)
                {
                    tokens.Delete(a.TokenStartIndex, a.TokenStopIndex);
                    KillTrailingNewline(tokens, action.TokenStopIndex);
                }
            });

            wiz.Visit(t, ANTLRParser.ACTION, (tree) =>
            {
            });

            // wipe rule arguments
            wiz.Visit(t, ANTLRParser.ARG, (tree) =>
            {
                CommonTree a = (CommonTree)t;
                a            = (CommonTree)a.GetChild(0);
                tokens.Delete(a.token.TokenIndex);
                KillTrailingNewline(tokens, a.token.TokenIndex);
            });

            // wipe rule return declarations
            wiz.Visit(t, ANTLRParser.RET, (tree) =>
            {
                CommonTree a   = (CommonTree)t;
                CommonTree ret = (CommonTree)a.GetChild(0);
                tokens.Delete(a.token.TokenIndex, ret.token.TokenIndex);
            });

            // comment out semantic predicates
            wiz.Visit(t, ANTLRParser.SEMPRED, (tree) =>
            {
                CommonTree a = (CommonTree)t;
                tokens.Replace(a.token.TokenIndex, "/*" + a.Text + "*/");
            });

            // comment out semantic predicates
            wiz.Visit(t, ANTLRParser.GATED_SEMPRED, (tree) =>
            {
                CommonTree a = (CommonTree)t;
                string text  = tokens.ToString(a.TokenStartIndex, a.TokenStopIndex);
                tokens.Replace(a.TokenStartIndex, a.TokenStopIndex, "/*" + text + "*/");
            });

            // comment scope specs
            wiz.Visit(t, ANTLRParser.SCOPE, (tree) =>
            {
                CommonTree a = (CommonTree)t;
                tokens.Delete(a.TokenStartIndex, a.TokenStopIndex);
                KillTrailingNewline(tokens, a.TokenStopIndex);
            });

            // args r[x,y] -> ^(r [x,y])
            wiz.Visit(t, ANTLRParser.ARG_ACTION, (tree) =>
            {
                CommonTree a = (CommonTree)t;
                if (a.Parent.Type == ANTLRParser.RULE_REF)
                {
                    tokens.Delete(a.TokenStartIndex, a.TokenStopIndex);
                }
            });

#if false // what is this token type in the C# ported version of the V3 grammar?
            // ^('=' id ^(RULE_REF [arg])), ...
            wiz.Visit(t, ANTLRParser.LABEL_ASSIGN, (tree) =>
            {
                CommonTree a = (CommonTree)t;
                if (!a.HasAncestor(ANTLRParser.OPTIONS))
                {
                    // avoid options
                    CommonTree child = (CommonTree)a.GetChild(0);
                    // kill "id="
                    tokens.Delete(a.token.TokenIndex);
                    tokens.Delete(child.token.TokenIndex);
                }
            });
#endif

#if false // what is this token type in the C# ported version of the V3 grammar?
            // ^('+=' id ^(RULE_REF [arg])), ...
            wiz.Visit(t, ANTLRParser.LIST_LABEL_ASSIGN, (tree) =>
            {
                CommonTree a     = (CommonTree)t;
                CommonTree child = (CommonTree)a.GetChild(0);
                // kill "id+="
                tokens.Delete(a.token.TokenIndex);
                tokens.Delete(child.token.TokenIndex);
            });
#endif

            // AST STUFF

            wiz.Visit(t, ANTLRParser.REWRITE, (tree) =>
            {
                CommonTree a     = (CommonTree)t;
                CommonTree child = (CommonTree)a.GetChild(0);
                int stop         = child.TokenStopIndex;
                if (child.Type == ANTLRParser.SEMPRED)
                {
                    CommonTree rew = (CommonTree)a.GetChild(1);
                    stop           = rew.TokenStopIndex;
                }
                tokens.Delete(a.token.TokenIndex, stop);
                KillTrailingNewline(tokens, stop);
            });

            wiz.Visit(t, ANTLRParser.ROOT, (tree) =>
            {
                tokens.Delete(((CommonTree)t).token.TokenIndex);
            });

            wiz.Visit(t, ANTLRParser.BANG, (tree) =>
            {
                tokens.Delete(((CommonTree)t).token.TokenIndex);
            });
        }
Example #34
0
        protected void ToDOTDefineEdges(object tree, ITreeAdaptor adaptor, StringTemplate treeST)
        {
            if ( tree == null )
            {
                return;
            }
            int n = adaptor.GetChildCount(tree);
            if ( n == 0 )
            {
                // must have already dumped as child from previous
                // invocation; do nothing
                return;
            }

            string parentName = "n" + GetNodeNumber(tree);

            // for each child, do a parent -> child edge using unique node names
            string parentText = adaptor.GetNodeText(tree);
            for (int i = 0; i < n; i++)
            {
                object child = adaptor.GetChild(tree, i);
                string childText = adaptor.GetNodeText(child);
                string childName = "n" + GetNodeNumber(child);
                StringTemplate edgeST = _edgeST.GetInstanceOf();
                edgeST.SetAttribute("parent", parentName);
                edgeST.SetAttribute("child", childName);
                edgeST.SetAttribute("parentText", parentText);
                edgeST.SetAttribute("childText", childText);
                treeST.SetAttribute("edges", edgeST);
                ToDOTDefineEdges(child, adaptor, treeST);
            }
        }
Example #35
0
 public StringTemplate ToDOT(object tree, ITreeAdaptor adaptor)
 {
     return(ToDOT(tree, adaptor, _treeST, _edgeST));
 }
Example #36
0
 public DebugTreeAdaptor(IDebugEventListener dbg, ITreeAdaptor adaptor) {
     this.dbg = dbg;
     this.adaptor = adaptor;
 }
Example #37
0
 public Test2ContextVisitor(ITreeAdaptor adaptor, IList list)
 {
     this.adaptor = adaptor;
     this.list = list;
 }
		public DebugEventSocketProxy(BaseRecognizer recognizer, int port, ITreeAdaptor adaptor)
		{
			this.grammarFileName = recognizer.GrammarFileName;
			this.port = port;
			this.adaptor = adaptor;
		}
Example #39
0
 public Test1ContextVisitor(ITreeAdaptor adaptor, IList list)
 {
     this.adaptor = adaptor;
     this.list    = list;
 }
Example #40
0
 public DebugTreeAdaptor(IDebugEventListener dbg, ITreeAdaptor adaptor)
 {
     this.dbg     = dbg;
     this.adaptor = adaptor;
 }
Example #41
0
 partial void CreateTreeAdaptor(ref Antlr.Runtime.Tree.ITreeAdaptor adaptor)
 {
     adaptor = new StringTreeAdaptor();
 }