/// <summary>TODO: not sure this is what we want for trees. </summary> public virtual string ToString(object start, object stop) { if (start == null) { return(null); } // if we have the token stream, use that to dump text in order if (tokens != null) { // don't trust stop node as it's often an UP node etc... // walk backwards until you find a non-UP, non-DOWN node // and ask for it's token index. int beginTokenIndex = adaptor.GetTokenStartIndex(start); int endTokenIndex = adaptor.GetTokenStopIndex(stop); if ((stop != null) && (adaptor.GetNodeType(stop) == Token.UP)) { endTokenIndex = adaptor.GetTokenStopIndex(start); } else { endTokenIndex = Count - 1; } return(tokens.ToString(beginTokenIndex, endTokenIndex)); } StringBuilder buf = new StringBuilder(); ToStringWork(start, stop, buf); return(buf.ToString()); }
public string text(LSLAst t) { string ts = ""; //if (t.evalType != null) ts = ":<" + t.evalType + ">"; return(_tokens.ToString(t.TokenStartIndex, t.TokenStopIndex) + ts); }
public virtual string ToString(object start, object stop) { Console.Out.WriteLine("toString"); if (start == null || stop == null) { return(null); } if (p == -1) { throw new InvalidOperationException("Buffer is not yet filled."); } //Console.Out.WriteLine( "stop: " + stop ); if (start is CommonTree) { Console.Out.Write("toString: " + ((CommonTree)start).Token + ", "); } else { Console.Out.WriteLine(start); } if (stop is CommonTree) { Console.Out.WriteLine(((CommonTree)stop).Token); } else { Console.Out.WriteLine(stop); } // if we have the token stream, use that to dump text in order if (tokens != null) { int beginTokenIndex = adaptor.GetTokenStartIndex(start); int endTokenIndex = adaptor.GetTokenStopIndex(stop); // if it's a tree, use start/stop index from start node // else use token range from start/stop nodes if (adaptor.GetType(stop) == TokenTypes.Up) { endTokenIndex = adaptor.GetTokenStopIndex(start); } else if (adaptor.GetType(stop) == TokenTypes.EndOfFile) { endTokenIndex = Count - 2; // don't use EOF } return(tokens.ToString(beginTokenIndex, endTokenIndex)); } // walk nodes looking for start object t = null; int i = 0; for ( ; i < nodes.Count; i++) { t = nodes[i]; if (t == start) { break; } } // now walk until we see stop, filling string buffer with text StringBuilder buf = new StringBuilder(); t = nodes[i]; while (t != stop) { string text = adaptor.GetText(t); if (text == null) { text = " " + adaptor.GetType(t).ToString(); } buf.Append(text); i++; t = nodes[i]; } // include stop node too string text2 = adaptor.GetText(stop); if (text2 == null) { text2 = " " + adaptor.GetType(stop).ToString(); } buf.Append(text2); return(buf.ToString()); }
public override string ToString() { return(input.ToString()); }