Exemple #1
0
		public Segment(List<Segment> segments)
		{
			if (segments != null && segments.Count >= 1)
			{
				Segment prev = segments[segments.Count - 1];
				prevSegment = prev;
				prev.nextSegment = this;
			}
		}
Exemple #2
0
		private void AppendSegment(Segment rlt)
		{
			if (rlt.SegmentType != SegmentMode.Ignore)
			{
				Segments.Add(rlt);
			}
		}
Exemple #3
0
		public Segment ReadNextSegment()
		{
			if (!string.IsNullOrEmpty(rawScript) && index >= 0 && index < rawScript.Length)
			{
				Segment rlt = new Segment(Segments);

				for (; index <= rawScript.Length; index++)
				{
					if (cacheIndex < 1)
					{
						cacheIndex++;
					}
					if (index == rawScript.Length)
					{
						cache[cacheIndex] = '\0';
					}
					else
					{
						cache[cacheIndex] = rawScript[index];
						if (cacheIndex == 1 && index + 1 < rawScript.Length)
						{
							cache[cacheIndex + 1] = rawScript[index + 1];
							cacheIndex++;
							index++;
						}
					}
					if (rlt.Read(cache, index < rawScript.Length))
					{
						if ((cache[1] == '"' && rlt.SegmentType == SegmentMode.String)
							|| (cacheIndex == 2 && (cache[1] == ' ' && rlt.SegmentType != SegmentMode.String && rlt.SegmentType != SegmentMode.Comment))
							|| (rlt.SegmentType == SegmentMode.Comment && "/*".Equals(rlt.StartOpCode)))
						{
							index++;
							cache[0] = cache[1];
							cache[1] = cache[2];
						}
						break;
					}
					if (cacheIndex == 2)
					{
						cache[0] = cache[1];
						cache[1] = cache[2];
					}
				}

				if (Keywords.Contains(rlt.Content))
				{
					rlt.SegmentType = SegmentMode.Keyword;
				}
				else if (rlt.SegmentType == SegmentMode.NewLine)
				{
					rlt.SegmentType = SegmentMode.Ignore;
				}
				AppendSegment(rlt);
				return rlt;
			}
			else
			{
				Segment rlt = new Segment(null);
				if (index == rawScript.Length && cache[1] != '\0')
				{
					cache[2] = '\0';
					rlt.Read(cache, false);
					index++;
					AppendSegment(rlt);
					return rlt;
				}
				else
				{
					return null;
				}
			}
		}