Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@180 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
26 changed files with 892 additions and 674 deletions
@ -1,14 +1,17 @@ |
|||||||
using System; |
using System; |
||||||
using System.Text; |
using System.Drawing; |
||||||
using System.CodeDom; |
|
||||||
using System.Collections; |
|
||||||
|
|
||||||
namespace ICSharpCode.NRefactory.Parser |
namespace ICSharpCode.NRefactory.Parser |
||||||
{ |
{ |
||||||
public class BlankLine |
public class BlankLine : AbstractSpecial |
||||||
{ |
{ |
||||||
public BlankLine() |
public BlankLine(Point point) : base(point) |
||||||
{ |
{ |
||||||
} |
} |
||||||
|
|
||||||
|
public override object AcceptVisitor(ISpecialVisitor visitor, object data) |
||||||
|
{ |
||||||
|
return visitor.Visit(this, data); |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|||||||
@ -0,0 +1,74 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Daniel Grunwald |
||||||
|
* Date: 15.07.2005 |
||||||
|
* Time: 12:05 |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Drawing; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.Parser |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interface for all specials.
|
||||||
|
/// </summary>
|
||||||
|
public interface ISpecial |
||||||
|
{ |
||||||
|
Point StartPosition { get; } |
||||||
|
Point EndPosition { get; } |
||||||
|
|
||||||
|
object AcceptVisitor(ISpecialVisitor visitor, object data); |
||||||
|
} |
||||||
|
|
||||||
|
public interface ISpecialVisitor |
||||||
|
{ |
||||||
|
object Visit(ISpecial special, object data); |
||||||
|
object Visit(BlankLine special, object data); |
||||||
|
object Visit(Comment special, object data); |
||||||
|
object Visit(PreProcessingDirective special, object data); |
||||||
|
} |
||||||
|
|
||||||
|
public abstract class AbstractSpecial : ISpecial |
||||||
|
{ |
||||||
|
public abstract object AcceptVisitor(ISpecialVisitor visitor, object data); |
||||||
|
|
||||||
|
Point startPosition, endPosition; |
||||||
|
|
||||||
|
public AbstractSpecial(Point position) |
||||||
|
{ |
||||||
|
this.startPosition = position; |
||||||
|
this.endPosition = position; |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractSpecial(Point startPosition, Point endPosition) |
||||||
|
{ |
||||||
|
this.startPosition = startPosition; |
||||||
|
this.endPosition = endPosition; |
||||||
|
} |
||||||
|
|
||||||
|
public Point StartPosition { |
||||||
|
get { |
||||||
|
return startPosition; |
||||||
|
} |
||||||
|
set { |
||||||
|
startPosition = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public Point EndPosition { |
||||||
|
get { |
||||||
|
return endPosition; |
||||||
|
} |
||||||
|
set { |
||||||
|
endPosition = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override string ToString() |
||||||
|
{ |
||||||
|
return String.Format("[{0}: Start = {1}, End = {2}]", |
||||||
|
GetType().Name, StartPosition, EndPosition); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -1,13 +0,0 @@ |
|||||||
using System; |
|
||||||
using System.Text; |
|
||||||
using System.CodeDom; |
|
||||||
using System.Collections; |
|
||||||
|
|
||||||
namespace ICSharpCode.NRefactory.Parser |
|
||||||
{ |
|
||||||
public enum SpecialType { |
|
||||||
SingleLine, |
|
||||||
Documentation, |
|
||||||
Block |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,118 @@ |
|||||||
|
/* |
||||||
|
* Created by SharpDevelop. |
||||||
|
* User: Daniel Grunwald |
||||||
|
* Date: 15.07.2005 |
||||||
|
* Time: 12:29 |
||||||
|
*/ |
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Drawing; |
||||||
|
using System.Collections.Generic; |
||||||
|
using ICSharpCode.NRefactory.Parser; |
||||||
|
using ICSharpCode.NRefactory.Parser.AST; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.PrettyPrinter |
||||||
|
{ |
||||||
|
public class SpecialOutputVisitor : ISpecialVisitor |
||||||
|
{ |
||||||
|
AbstractOutputFormatter formatter; |
||||||
|
|
||||||
|
public SpecialOutputVisitor(AbstractOutputFormatter formatter) |
||||||
|
{ |
||||||
|
this.formatter = formatter; |
||||||
|
} |
||||||
|
|
||||||
|
public object Visit(ISpecial special, object data) |
||||||
|
{ |
||||||
|
Console.WriteLine("Warning: SpecialOutputVisitor.Visit(ISpecial) called with " + special); |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
public object Visit(BlankLine special, object data) |
||||||
|
{ |
||||||
|
formatter.NewLine(); |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
public object Visit(Comment special, object data) |
||||||
|
{ |
||||||
|
formatter.PrintComment(special); |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
public object Visit(PreProcessingDirective special, object data) |
||||||
|
{ |
||||||
|
formatter.PrintPreProcessingDirective(special); |
||||||
|
return data; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This class inserts specials between INodes.
|
||||||
|
/// </summary>
|
||||||
|
public class SpecialNodesInserter |
||||||
|
{ |
||||||
|
IEnumerator<ISpecial> enumerator; |
||||||
|
SpecialOutputVisitor visitor; |
||||||
|
bool available; // true when more specials are available
|
||||||
|
|
||||||
|
public SpecialNodesInserter(IEnumerable<ISpecial> specials, SpecialOutputVisitor visitor) |
||||||
|
{ |
||||||
|
if (specials == null) throw new ArgumentNullException("specials"); |
||||||
|
if (visitor == null) throw new ArgumentNullException("visitor"); |
||||||
|
enumerator = specials.GetEnumerator(); |
||||||
|
this.visitor = visitor; |
||||||
|
available = enumerator.MoveNext(); |
||||||
|
} |
||||||
|
|
||||||
|
void WriteCurrent() |
||||||
|
{ |
||||||
|
enumerator.Current.AcceptVisitor(visitor, null); |
||||||
|
available = enumerator.MoveNext(); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes all specials up to the start position of the node.
|
||||||
|
/// </summary>
|
||||||
|
public void AcceptNodeStart(INode node) |
||||||
|
{ |
||||||
|
Console.Write("Start node " + node.GetType().Name + ": "); |
||||||
|
AcceptPoint(node.StartLocation); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes all specials up to the end position of the node.
|
||||||
|
/// </summary>
|
||||||
|
public void AcceptNodeEnd(INode node) |
||||||
|
{ |
||||||
|
Console.Write("End node " + node.GetType().Name + ": "); |
||||||
|
AcceptPoint(node.EndLocation); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes all specials up to the specified location.
|
||||||
|
/// </summary>
|
||||||
|
public void AcceptPoint(Point a) |
||||||
|
{ |
||||||
|
Console.WriteLine(a.Y + ", " + a.X); |
||||||
|
while (available) { |
||||||
|
Point b = enumerator.Current.StartPosition; |
||||||
|
if (b.Y < a.Y || (b.Y == a.Y && b.X <= a.X)) { |
||||||
|
WriteCurrent(); |
||||||
|
} else { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Outputs all missing specials to the writer.
|
||||||
|
/// </summary>
|
||||||
|
public void Finish() |
||||||
|
{ |
||||||
|
while (available) { |
||||||
|
WriteCurrent(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue