示例#1
0
文件: Scanner.cs 项目: mind0n/hive
		bool commentStartEnd_MatchCallback(Role<Lex> sender, Lex[] buffer, int index)
		{
			Lex curt = buffer[index];
			Lex prev = buffer[index - 1];
			Lex next = buffer[index + 1];

			if (curt.Content == '/' && next.Content == '/')
			{
				if (prev != null && (prev.Type == ElementType.MultiLineComment || prev.Type == ElementType.MultiLineCommentStart))
				{
					curt.Type = ElementType.MultiLineComment;
					return false;
				}
				return true;
			}
			else if (next.Content == '*')
			{
				if (prev != null)
				{
					if (prev.Type == ElementType.SingleLineComment || prev.Type == ElementType.SingleLineCommentStart)
					{
						curt.Type = ElementType.SingleLineComment;
						return false;
					}
					else if (prev.Type == ElementType.MultiLineComment)
					{
						curt.Type = ElementType.MultiLineComment;
						return false;
					}
				}
				return true;
			}
			else if (curt.Content == '\r')
			{
				if (prev != null && (prev.Type == ElementType.MultiLineComment || prev.Type == ElementType.MultiLineCommentStart))
				{
					curt.Type = ElementType.MultiLineComment;
					return false;
				}
				return true;
			}
			else if (curt.Content == '*')
			{
				if (prev != null && (prev.Type == ElementType.SingleLineComment || prev.Type == ElementType.SingleLineCommentStart))
				{
					curt.Type = ElementType.SingleLineComment;
					return false;
				}
				return true;
			}
			else
			{
				return false;
			}
		}
示例#2
0
文件: Scanner.cs 项目: mind0n/hive
		bool digitalPoint_MatchCallback(Role<Lex> role, Lex[] buffer, int index)
		{
			for (int i = index; i >= 0; i--)
			{
				if (buffer[i].Type == ElementType.Integer)
				{
					buffer[i].Type = ElementType.Float;
				}
			}

			return true;
		}
示例#3
0
文件: Token.cs 项目: mind0n/hive
		public bool Add(Lex item)
		{
			if (item != null)
			{
				if (item.Type == ElementType.Ignore)
				{
					return false;
				}
				if (Type == ElementType.Unknown || (item.Type == Type && item.Type != ElementType.ContextBegin && item.Type != ElementType.ContextEnd && item.Type != ElementType.RightCycle))
				{
					builder.Append(item.Content);
					Type = item.Type;
					return true;
				}
			}
			return false;
		}
示例#4
0
文件: Scanner.cs 项目: mind0n/hive
		protected void reader_BufferFullCallback(BufferedReader<Lex, char> sender, Lex[] buffer)
		{
			Lexes.Add(buffer[0]);
		}
示例#5
0
文件: Scanner.cs 项目: mind0n/hive
		bool stringStartEnd_ValidateCallback(Lex[] buffer, Lex prev, int index, bool ismatch)
		{
			Lex curt = buffer[index];
			if (index < 1 && curt.Type != ElementType.SingleLineComment && curt.Type != ElementType.MultiLineComment)
			{
				curt.Type = ElementType.StringStart;
			}
			else
			{
				prev = buffer[index - 1];
			}
			if (prev != null && prev.Type != ElementType.SingleLineCommentStart && prev.Type != ElementType.SingleLineComment && prev.Type != ElementType.MultiLineCommentStart && prev.Type != ElementType.MultiLineComment)
			{
				if (prev.Content == '\\')
				{
					curt.Type = prev.Type;
				}
				else if (prev.Type == ElementType.StringStart || prev.Type == ElementType.String)
				{
					curt.Type = ElementType.StringEnd;
				}
				else
				{
					curt.Type = ElementType.StringStart;
				}
				return true;
			}
			return false;
		}
示例#6
0
文件: Scanner.cs 项目: mind0n/hive
		bool stringCommentContent_ValidateCallback(Lex[] buffer, Lex prev, int index, bool ismatch)
		{
			Lex curt = buffer[index];
			if (prev != null && curt != null
				&& prev.Type != ElementType.StringEnd
				&& prev.Type != ElementType.SingleLineCommentEnd
				&& prev.Type != ElementType.MultiLineCommentEnd
				&& curt.Type != ElementType.SingleLineCommentStart
				&& curt.Type != ElementType.MultiLineCommentStart
			)
			{
				if (prev.Type == ElementType.StringStart || prev.Type == ElementType.String)
				{
					buffer[index].Type = ElementType.String;
				}
				else if (prev.Type == ElementType.SingleLineCommentStart || prev.Type == ElementType.SingleLineComment)
				{
					buffer[index].Type = ElementType.SingleLineComment;
				}
				else if (prev.Type == ElementType.MultiLineCommentStart || prev.Type == ElementType.MultiLineComment)
				{
					buffer[index].Type = ElementType.MultiLineComment;
				}
				else
				{
					return false;
				}
				return true;
			}
			return false;
		}
示例#7
0
文件: Scanner.cs 项目: mind0n/hive
		void stringRole_MatchCallback(Role<Lex> sender, Lex[] buffer, int index)
		{
			for (int i = index + 1; i < buffer.Length; i++)
			{
				buffer[i].Type = ElementType.String;
			}
		}
示例#8
0
文件: Scanner.cs 项目: mind0n/hive
		bool ignore_ValidateCallback(Lex[] buffer, Lex prev, int index, bool ismatch)
		{
			if (prev == null
				|| (prev.Type != ElementType.String
					&& prev.Type != ElementType.StringStart
					&& prev.Type != ElementType.MultiLineCommentStart
					&& prev.Type != ElementType.SingleLineCommentStart
					&& prev.Type != ElementType.SingleLineComment
					&& prev.Type != ElementType.MultiLineComment))
			{
				buffer[index].Type = ElementType.Ignore;
				return true;
			}
			return false;
		}
示例#9
0
文件: Scanner.cs 项目: mind0n/hive
		bool symbolCondition_ValidateCallback(Lex[] buffer, Lex prev, int index, bool ismatch)
		{
			Lex curt = buffer[index];
			if (curt.Content == ';')
			{
				curt.Type = ElementType.StatementEnd;
			}
			else if (curt.Content == '{')
			{
				curt.Type = ElementType.ContextBegin;
			}
			else if (curt.Content == '}')
			{
				curt.Type = ElementType.ContextEnd;
			}
			else if (curt.Content == '(')
			{
				if (prev != null && prev.Type == ElementType.Variable)
				{
					curt.Type = ElementType.ParamenterBegin;
				}
				else
				{
					curt.Type = ElementType.LeftCycle;
				}
				pairqueue.Insert(0, curt);
			}
			else if (curt.Content == ')')
			{
				Lex pair = null;
				if (pairqueue.Count > 0)
				{
					pair = pairqueue[0];
					pairqueue.RemoveAt(0);
				}
				if (pair != null)
				{
					if (pair.Type == ElementType.ParamenterBegin)
					{
						curt.Type = ElementType.ParameterEnd;
					}
					else if (pair.Type == ElementType.LeftCycle)
					{
						curt.Type = ElementType.RightCycle;
					}
					else
					{
						return false;
					}
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
			return true;
		}
示例#10
0
文件: Scanner.cs 项目: mind0n/hive
		protected void ScriptScanner_OnReadCallback(ScriptScanner sender, Token lexes, Lex lex)
		{
			if (!curtToken.Add(lex))
			{
				Tokens.Add(curtToken);
				if (OnReadTokenCallback != null)
				{
					OnReadTokenCallback(this, Tokens, curtToken);
				}
				curtToken = new Token();
				curtToken.Add(lex);
			}
		}
示例#11
0
文件: Scanner.cs 项目: mind0n/hive
		protected void reader_BufferFullCallback(BufferedReader<Lex, char> sender, Lex[] buffer)
		{
			if (OnReadCallback != null)
			{
				OnReadCallback(this, curtToken, buffer[0]);
			}
		}
示例#12
0
文件: Scanner.cs 项目: mind0n/hive
		bool ignore_ValidateCallback(Lex[] buffer, Lex prev, int index, bool ismatch)
		{
			ElementType type = ElementType.Unknown;
			if (index + 1 < buffer.Length && buffer[index + 1] != null)
			{
				type = buffer[index + 1].Type;
			}
			if (prev == null
				|| (prev.Type != ElementType.String
					&& prev.Type != ElementType.StringStart
					&& prev.Type != ElementType.MultiLineCommentStart
					&& prev.Type != ElementType.SingleLineCommentStart
					&& prev.Type != ElementType.SingleLineComment
					&& prev.Type != ElementType.MultiLineComment))
			{
				buffer[index].Type = ElementType.Ignore;
				if (type != prev.Type)
				{
					reader.RemoveIgnore(index);
				}
				return true;
			}
			return false;
		}