public override void WriteKeyword(Role role, string keyword)
		{
			WriteIndentation();
			column += keyword.Length;
			textWriter.Write(keyword);
			isAtStartOfLine = false;
		}
Пример #2
0
		public override void WriteKeyword(Role role, string keyword)
		{
			if (role != null) {
				WriteSpecialsUpToRole(role);
			}
			base.WriteKeyword(role, keyword);
		}
		public override void WriteToken(Role role, string token)
		{
			WriteIndentation();
			column += token.Length;
			textWriter.Write(token);
			isAtStartOfLine = false;
		}
		public override void WriteToken(Role role, string token, TextTokenType tokenType)
		{
			// Avoid that two +, - or ? tokens are combined into a ++, -- or ?? token.
			// Note that we don't need to handle tokens like = because there's no valid
			// C# program that contains the single token twice in a row.
			// (for +, - and &, this can happen with unary operators;
			// for ?, this can happen in "a is int? ? b : c" or "a as int? ?? 0";
			// and for /, this can happen with "1/ *ptr" or "1/ //comment".)
			if (lastWritten == LastWritten.Plus && token[0] == '+' ||
			    lastWritten == LastWritten.Minus && token[0] == '-' ||
			    lastWritten == LastWritten.Ampersand && token[0] == '&' ||
			    lastWritten == LastWritten.QuestionMark && token[0] == '?' ||
			    lastWritten == LastWritten.Division && token[0] == '*') {
				base.Space();
			}
			base.WriteToken(role, token, tokenType);
			if (token == "+") {
				lastWritten = LastWritten.Plus;
			} else if (token == "-") {
				lastWritten = LastWritten.Minus;
			} else if (token == "&") {
				lastWritten = LastWritten.Ampersand;
			} else if (token == "?") {
				lastWritten = LastWritten.QuestionMark;
			} else if (token == "/") {
				lastWritten = LastWritten.Division;
			} else {
				lastWritten = LastWritten.Other;
			}
		}
		public override void WriteKeyword(Role role, string keyword)
		{
			if (lastWritten == LastWritten.KeywordOrIdentifier) {
				Space();
			}
			base.WriteKeyword(role, keyword);
			lastWritten = LastWritten.KeywordOrIdentifier;
		}
Пример #6
0
		public override void WriteToken(Role role, string token)
		{
			CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role);
			EmptyStatement node = nodes.Peek().LastOrDefault() as EmptyStatement;
			if (node == null)
				currentList.Add(t);
			else {
				node.Location = locationProvider.Location;
			}
			base.WriteToken(role, token);
		}
		public override void WriteKeyword(Role role, string keyword)
		{
			TextLocation start = locationProvider.Location;
			CSharpTokenNode t = null;
			if (role is TokenRole)
				t = new CSharpTokenNode(start, (TokenRole)role);
			else if (role == EntityDeclaration.ModifierRole)
				t = new CSharpModifierToken(start, CSharpModifierToken.GetModifierValue(keyword));
			else if (keyword == "this") {
				ThisReferenceExpression node = nodes.Peek().LastOrDefault() as ThisReferenceExpression;
				if (node != null)
					node.Location = start;
			} else if (keyword == "base") {
				BaseReferenceExpression node = nodes.Peek().LastOrDefault() as BaseReferenceExpression;
				if (node != null)
					node.Location = start;
			}
			if (t != null) currentList.Add(t);
			base.WriteKeyword(role, keyword);
		}
Пример #8
0
		public void WriteTokenBrace(Role tokenRole, string token)
		{
			WriteToken(tokenRole, token, BoxedTextColor.Punctuation);
		}
Пример #9
0
		void WriteSpecialsUpToRole(Role role, AstNode nextNode)
		{
			if (positionStack.Count == 0) {
				return;
			}
			// Look for the role between the current position and the nextNode.
			for (AstNode pos = positionStack.Peek(); pos != null && pos != nextNode; pos = pos.NextSibling) {
				if (pos.Role == role) {
					WriteSpecials(positionStack.Pop(), pos);
					// Push the next sibling because the node matching the role is not a special,
					// and should be considered to be already handled.
					positionStack.Push(pos.NextSibling);
					// This is necessary for OptionalComma() to work correctly.
					break;
				}
			}
		}
Пример #10
0
			public void AddAttributeSection(AstNode parent, Attributes attrs, Role<AttributeSection> role)
			{
				if (attrs == null)
					return;
				foreach (var attr in attrs.Sections) {
					var section = ConvertAttributeSection(attr);
					if (section == null)
						continue;
					parent.AddChild(section, role);
				}
			}
Пример #11
0
			void AddStatementOrList(ForStatement forStatement, Mono.CSharp.Statement init, Role<Statement> role)
			{
				if (init == null)
					return;
				var stmtList = init as StatementList;
				if (stmtList != null) {
					foreach (var stmt in stmtList.Statements) {
						forStatement.AddChild((Statement)stmt.Accept(this), role);
					}
				} else if (init is Mono.CSharp.EmptyStatement) {
					
				} else {
					forStatement.AddChild((Statement)init.Accept(this), role);
				}
			}
Пример #12
0
 public void InsertChildAfter <T> (AstNode prevSibling, T child, Role <T> role) where T : AstNode
 {
     InsertChildBefore((prevSibling == null || prevSibling.IsNull) ? firstChild : prevSibling.nextSibling, child, role);
 }
Пример #13
0
		void WriteToken(string token, Role tokenRole)
		{
			writer.WriteToken(tokenRole, token);
			isAtStartOfLine = false;
		}
Пример #14
0
		/// <summary>
		/// Writes a token to the output.
		/// </summary>
		public abstract void WriteToken(Role role, string token);
Пример #15
0
		/// <summary>
		/// Writes a keyword to the output.
		/// </summary>
		public abstract void WriteKeyword(Role role, string keyword);
Пример #16
0
		public override void WriteToken(Role role, string token)
		{
			decoratedWriter.WriteToken(role, token);
		}
Пример #17
0
		public override void WriteKeyword(Role role, string keyword)
		{
			decoratedWriter.WriteKeyword(role, keyword);
		}
Пример #18
0
		/// <summary>
		/// Writes a token to the output.
		/// </summary>
		public abstract void WriteToken(Role role, string token, object data);
Пример #19
0
		public override void WriteToken(Role role, string token, object data)
		{
			decoratedWriter.WriteToken(role, token, data);
		}
Пример #20
0
		public void WriteTokenNumber(Role tokenRole, string token)
		{
			WriteToken(tokenRole, token, BoxedTextColor.Number);
		}
Пример #21
0
 bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
 {
     return(child.DoMatchCollection(role, pos, match, backtrackingInfo));
 }
Пример #22
0
		void WriteKeyword(string token, Role tokenRole = null)
		{
			writer.WriteKeyword(tokenRole, token);
			isAtStartOfLine = false;
		}
Пример #23
0
		public override void WriteToken(Role role, string token, object data)
		{
			WriteSpecialsUpToRole(role);
			base.WriteToken(role, token, data);
		}
Пример #24
0
        bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
        {
            AstNode o = pos as AstNode;

            return((pos == null || o != null) && DoMatch(o, match));
        }
Пример #25
0
/*		void WriteKeyword (string keyword, Role tokenRole)
		{
			WriteSpecialsUpToRole (tokenRole);
			if (lastWritten == LastWritten.KeywordOrIdentifier)
				formatter.Space ();
			formatter.WriteKeyword (keyword);
			lastWritten = LastWritten.KeywordOrIdentifier;
		}*/
		
		void WriteIdentifier(string identifier, Role<Identifier> identifierRole = null)
		{
			WriteSpecialsUpToRole(identifierRole ?? Roles.Identifier);
			if (IsKeyword(identifier, containerStack.Peek())) {
				if (lastWritten == LastWritten.KeywordOrIdentifier) {
					Space();
				}
				// this space is not strictly required, so we call Space()
				formatter.WriteToken("@");
			} else if (lastWritten == LastWritten.KeywordOrIdentifier) {
				formatter.Space();
				// this space is strictly required, so we directly call the formatter
			}
			formatter.WriteIdentifier(identifier);
			lastWritten = LastWritten.KeywordOrIdentifier;
		}
Пример #26
0
 public void AddAttributeSection(AstNode parent, Attributes attrs, Role role)
 {
     if (attrs == null)
         return;
     foreach (var attr in attrs.Sections) {
         parent.AddChild (ConvertAttributeSection (attr), EntityDeclaration.AttributeRole);
     }
 }
Пример #27
0
 public AstNodeCollection <T> GetChildrenByRole <T> (Role <T> role) where T : AstNode
 {
     return(new AstNodeCollection <T> (this, role));
 }
Пример #28
0
		static void InsertComment(ref AstNode insertionPoint, AstNode newNode, Role role, bool isDocumentationComment, AstNode rootNode)
		{
			TextLocation insertAt = newNode.StartLocation;
			// Advance insertionPoint to the first node that has a start location >= insertAt
			while (insertionPoint != null && insertionPoint.StartLocation < insertAt) {
				// Enter the current node if insertAt is within
				while (insertAt < insertionPoint.EndLocation && insertionPoint.FirstChild != null) {
					insertionPoint = insertionPoint.FirstChild;
				}
				// Go to next node (insertionPoint.NextSibling if it exists; otherwise the next sibling of the parent node etc.)
				insertionPoint = insertionPoint.GetNextNode();
			}
			// As a special case, XmlDoc gets inserted at the beginning of the entity declaration
			if (isDocumentationComment && insertionPoint is EntityDeclaration && insertionPoint.FirstChild != null) {
				insertionPoint = insertionPoint.FirstChild;
			}
			if (insertionPoint == null) {
				// we're at the end of the compilation unit
				rootNode.AddChildUnsafe(newNode, role);
			} else {
				insertionPoint.Parent.InsertChildBeforeUnsafe(insertionPoint, newNode, role);
			}
		}
Пример #29
0
			void AddStatementOrList (ForStatement forStatement, Mono.CSharp.Statement init, Role<Statement> role)
			{
				if (init == null)
					return;
				if (init is StatementList) {
					foreach (var stmt in ((StatementList)init).Statements) {
						Console.WriteLine ("stmt:" + stmt);
						forStatement.AddChild ((Statement)stmt.Accept (this), role);
					}
				} else if (init is Mono.CSharp.EmptyStatement) {
					
				} else {
					forStatement.AddChild ((Statement)init.Accept (this), role);
				}
			}
Пример #30
0
		/// <summary>
		/// Writes all specials between the current position (in the positionStack) and the next
		/// node with the specified role. Advances the current position.
		/// </summary>
		void WriteSpecialsUpToRole(Role role)
		{
			WriteSpecialsUpToRole(role, null);
		}
Пример #31
0
			void AddStatementOrList (ForStatement forStatement, Mono.CSharp.Statement init, Role<Statement> role)
			{
				if (init == null)
					return;
				if (init is StatementList) {
					foreach (var stmt in ((StatementList)init).Statements) {
						forStatement.AddChild ((Statement)stmt.Accept (this), role);
					}
				} else {
					forStatement.AddChild ((Statement)init.Accept (this), role);
				}
			}
Пример #32
0
		void WriteKeyword(string token, Role tokenRole = null)
		{
			if (tokenRole != null) {
				WriteSpecialsUpToRole(tokenRole);
			}
			if (lastWritten == LastWritten.KeywordOrIdentifier) {
				formatter.Space();
			}
			formatter.WriteKeyword(token);
			lastWritten = LastWritten.KeywordOrIdentifier;
		}
Пример #33
0
		public void WriteTokenOperator(Role tokenRole, string token)
		{
			WriteToken(tokenRole, token, BoxedTextColor.Operator);
		}
Пример #34
0
		void WriteToken(string token, Role tokenRole)
		{
			WriteSpecialsUpToRole(tokenRole);
			// Avoid that two +, - or ? tokens are combined into a ++, -- or ?? token.
			// Note that we don't need to handle tokens like = because there's no valid
			// C# program that contains the single token twice in a row.
			// (for +, - and &, this can happen with unary operators;
			// for ?, this can happen in "a is int? ? b : c" or "a as int? ?? 0";
			// and for /, this can happen with "1/ *ptr" or "1/ //comment".)
			// If a destructor has modifiers then there should be a space before ~
			if (lastWritten == LastWritten.Plus && token [0] == '+'
				|| lastWritten == LastWritten.Minus && token [0] == '-'
				|| lastWritten == LastWritten.Ampersand && token [0] == '&'
				|| lastWritten == LastWritten.QuestionMark && token [0] == '?'
				|| lastWritten == LastWritten.Division && token [0] == '*'
				|| lastWritten == LastWritten.KeywordOrIdentifier && token[0] == '~') {
				formatter.Space();
			}
			formatter.WriteToken(token);
			if (token == "+") {
				lastWritten = LastWritten.Plus;
			} else if (token == "-") {
				lastWritten = LastWritten.Minus;
			} else if (token == "&") {
				lastWritten = LastWritten.Ampersand;
			} else if (token == "?") {
				lastWritten = LastWritten.QuestionMark;
			} else if (token == "/") {
				lastWritten = LastWritten.Division;
			} else {
				lastWritten = LastWritten.Other;
			}
		}
Пример #35
0
 void SetRole(Role role)
 {
     flags = (flags & ~roleIndexMask) | role.Index;
 }