示例#1
0
        /// <summary>
        /// Apped a string with highlighting to the assembly output
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Type"></param>
        private void AppendSyntax(string Text, Parse.SyntaxType.eType Type)
        {
            int ss = Output.Length;

            Output.Append(Text);
            var tp = new TextPortion(ss, Text.Length);
            var so = SyntaxOccurences[Type];

            so.Length += tp.Length;
            var soo = SyntaxOccurences[Type].Occurences;

            if (soo.Count > 0)
            {
                var oc = soo[soo.Count - 1];
                if (oc.End == tp.Begin)
                {
                    oc.End = tp.End;
                    soo.RemoveAt(soo.Count - 1);
                    soo.Add(oc);
                }
                else
                {
                    SyntaxOccurences[Type].Occurences.Add(tp);
                }
            }
            else
            {
                SyntaxOccurences[Type].Occurences.Add(tp);
            }
        }
 public ParseError(string NewDescription, int NewBegin, int NewLength)
 {
     TextPortion = new TextPortion();
     Description = NewDescription;
     TextPortion.Begin = NewBegin;
     TextPortion.Length = NewLength;
 }
 public ParseError(string newDescription, Match LastMatch, int newLength = 10)
 {
     TextPortion = new TextPortion();
     Description = newDescription;
     if (LastMatch != null)
         TextPortion.Begin = LastMatch.Index + LastMatch.Length;
     else
         TextPortion.Begin = 0;
     TextPortion.Length = newLength;
 }
        private void timParseUndoWait_Tick(object sender, EventArgs e)
        {
            //Disable timers
            timParseUndoIdleWait.Enabled = false;
            timParseUndoMaxWait.Enabled  = false;

            //Create undo action
            TextPortion tp = tbParse_Source.Text;

            tp.FromRTB(tbParse_Source);
            _parse_source_undo_history.Change(tp);
        }
示例#5
0
		protected float DrawLine(TextPortion.TextLine _textLine,
		                         FColor _color,
		                         int _lineNumber,
		                         float _indent,
		                         EAlignment _alignment)
		{
			var line = _textLine.Text;
			var part = line.Split(TextPortion.Punctuation).ToArray();
			var processedChars = 0;
			var x = (float) ContentRct.Left*Constants.TILE_SIZE;

			var lineSize = DrawHelper.MeasureString(Font, line);
			switch (_alignment)
			{
				case EAlignment.NORMAL:
					x += _indent + _textLine.Left;
					break;
				case EAlignment.LEFT:
					x += _indent;
					break;
				case EAlignment.RIGHT:
					x += ContentRct.Width*Constants.TILE_SIZE - lineSize.Width - _indent;
					break;
				case EAlignment.CENTER:
					x += ContentRct.Width*Constants.TILE_SIZE/2f - lineSize.Width/2f;
					break;
			}

			var y = ContentRct.Top*Constants.TILE_SIZE + _lineNumber*LineHeight;

			for (var partIndex = 0; partIndex < part.Length; partIndex++)
			{
				var color = _color;
				var addStr = part[partIndex];
				FColor highlight;
				if (_textLine.Highlights != null && _textLine.Highlights.TryGetValue(addStr, out highlight))
				{
					color = highlight;
					processedChars += addStr.Length;
				}
				else
				{
					processedChars += addStr.Length;
					addStr += (processedChars >= line.Length) ? "" : line[processedChars].ToString();
					processedChars++;
				}
				var size = DrawHelper.MeasureString(Font, addStr);
				DrawHelper.DrawString(Font, addStr, x, y, color);
				x += size.Width + 2;
			}
			return x;
		}
 private void MessageManagerNewWorldMessage(object _sender, WorldMessage _message)
 {
     if (_message.Type == WorldMessage.EType.AVATAR_BEGINS_TURN)
     {
         m_turnMessages.Clear();
         m_lines.Clear();
         m_linesShown = 0;
         m_tp         = null;
     }
     if (_message.Type == WorldMessage.EType.MICRO_TURN)
     {
         m_diff = true;
     }
 }
		private void MessageManagerNewWorldMessage(object _sender, WorldMessage _message)
		{
			if (_message.Type == WorldMessage.EType.AVATAR_BEGINS_TURN)
			{
				m_turnMessages.Clear();
				m_lines.Clear();
				m_linesShown = 0;
				m_tp = null;
			}
			if (_message.Type == WorldMessage.EType.MICRO_TURN)
			{
				m_diff = true;
			}
		}
        private void PrepareText()
        {
            var strings = new List <string>();
            var xlist   = new List <XLangMessage>();

            foreach (var message in m_turnMessages)
            {
                if (message is XLangMessage)
                {
                    xlist.Add((XLangMessage)message);
                }
                else
                {
                    strings.AddRange(CompileXLangMessages(xlist));
                    xlist.Clear();
                }

                if (message is SimpleTextMessage)
                {
                    var tm = (SimpleTextMessage)message;
                    strings.Add(tm.Text);
                }
                else if (message is SoundTextMessage)
                {
                    var tm = (SoundTextMessage)message;
                    strings.Add("где-то " + tm.Text);
                }
            }

            strings.AddRange(CompileXLangMessages(xlist));
            xlist.Clear();

            var str = string.Join(", ", strings).Trim();

            if (!string.IsNullOrEmpty(str))
            {
                str  = char.ToUpper(str[0]) + str.Substring(1);
                m_tp = new TextPortion(str, null);
            }

            m_turnMessages.Clear();
            m_diff = false;
        }
示例#9
0
		protected void DrawLine(TextPortion.TextLine _textLine, FColor _color, float _x, float _y)
		{
			var line = _textLine.Text;
			var part = line.Split(TextPortion.Punctuation).ToArray();
			var processedChars = 0;
			var x = _x + _textLine.Left;
			for (var partIndex = 0; partIndex < part.Length; partIndex++)
			{
				var color = _color;
				var addStr = part[partIndex];
				FColor highlight;
				if (_textLine.Highlights != null && _textLine.Highlights.TryGetValue(addStr, out highlight))
				{
					color = highlight;
				}
				processedChars += addStr.Length;
				addStr += (processedChars == 0 || processedChars >= line.Length) ? "" : line[processedChars].ToString();
				processedChars++;
				var size = DrawHelper.MeasureString(Font, addStr);
				DrawHelper.DrawString(Font, addStr, x, _y, color);
				x += size.Width;
			}
		}
 public void ThrowParseError(string Description, TextPortion TextPortion)
 {
     ParseErrors.Add(new ParseError(Description, TextPortion));
 }
 /// <summary>
 /// Apped a string with highlighting to the assembly output
 /// </summary>
 /// <param name="Text"></param>
 /// <param name="Type"></param>
 private void AppendSyntax(string Text, Parse.SyntaxType.eType Type)
 {
     int ss = Output.Length;
     Output.Append(Text);
     var tp = new TextPortion(ss, Text.Length);
     var so = SyntaxOccurences[Type];
     so.Length += tp.Length;
     var soo = SyntaxOccurences[Type].Occurences;
     if (soo.Count > 0)
     {
         var oc = soo[soo.Count - 1];
         if (oc.End == tp.Begin)
         {
             oc.End = tp.End;
             soo.RemoveAt(soo.Count - 1);
             soo.Add(oc);
         }
         else
             SyntaxOccurences[Type].Occurences.Add(tp);
     }
     else
         SyntaxOccurences[Type].Occurences.Add(tp);
 }
示例#12
0
		private void PrepareText()
		{
			var strings = new List<string>();
			var xlist = new List<XLangMessage>();
			foreach (var message in m_turnMessages)
			{
				if (message is XLangMessage)
				{
					xlist.Add((XLangMessage) message);
				}
				else
				{
					strings.AddRange(CompileXLangMessages(xlist));
					xlist.Clear();
				}

				if (message is SimpleTextMessage)
				{
					var tm = (SimpleTextMessage) message;
					strings.Add(tm.Text);
				}
				else if (message is SoundTextMessage)
				{
					var tm = (SoundTextMessage) message;
					strings.Add("где-то " + tm.Text);
				}
			}

			strings.AddRange(CompileXLangMessages(xlist));
			xlist.Clear();

			var str = string.Join(", ", strings).Trim();

			if (!string.IsNullOrEmpty(str))
			{
				str = char.ToUpper(str[0]) + str.Substring(1);
				m_tp = new TextPortion(str, null);
			}

			m_turnMessages.Clear();
			m_diff = false;
		}
        /// <summary>
        /// Parse an identifier between two Borders (eg %variable%, #block#, etc). Check if it is a proper name, 
        /// and reports an error if the trailing border is absent
        /// </summary>
        /// <param name="Border">The character (or regex) that must be before and after the identifier</param>
        /// <param name="SyntaxName">The syntax highlighting name</param>
        /// <param name="Name">The identifier</param>
        /// <param name="NameIsProper">If the identifier is a proper name</param>
        /// <param name="TextPortion">Syntax TextPosition</param>
        /// <returns>True if it finds the first border, false otherwise</returns>
        private bool PEIdentifier(string Border, string SyntaxName, out string Name, out bool NameIsProper, out TextPortion TextPortion)
        {
            Name = "";
            NameIsProper = false;
            TextPortion = new TextPortion();

            //Must begin with Border
            if (!_caret.WS().Match(@"(?<begin>" + Border + @")"))
                return false;

            TextPortion.Begin = _caret.LastMatch.Groups["begin"].Index;

            //Names must begin with a letter
            NameIsProper = _caret.Match(@"(?<" + SyntaxName + @">[a-zA-Z]\w*)");
            //Should at lest specify a name
            if (!NameIsProper)
                _caret.Match(@"(?<" + SyntaxName + @">\w+)");

            //Get name
            Name = _caret.LastMatch.Groups[SyntaxName].Value;

            //Must have a trailing Border
            if (!_caret.WS().Match(@"(?<end>" + Border + @")"))
                ThrowParseError("Missing trailing " + Border, new TextPortion(TextPortion.Begin, new TextPortion(_caret.LastMatch).End - TextPortion.Begin));

            TextPortion.End = new TextPortion(_caret.LastMatch).End;

            return true;
        }
 public ParseError(string newDescription, TextPortion NewTextPortion)
 {
     Description = newDescription;
     TextPortion = NewTextPortion;
 }
 public void ThrowParseError(string Description, TextPortion TextPortion)
 {
     ParseErrors.Add(new ParseError(Description, TextPortion));
 }
示例#16
0
 internal void ThrowParseError(string Description, TextPortion TextPortion)
 {
     IDE.ExecutionTree.ParseErrors.Add(new ParseError(Description, TextPortion));
 }
            public void CopyFrom(Annotation Other)
            {
                Element = Other.Element;
                FirstRunnable = Other.FirstRunnable;
                RunnableParentBlock = Other.RunnableParentBlock;
                RunnablesCount = Other.RunnablesCount;

                TreeViewNode = Other.TreeViewNode;
                ListViewItem = Other.ListViewItem;

                SourcePosition = Other.SourcePosition;
                CompiledPosition = Other.CompiledPosition;

                IDE = Other.IDE;
            }
        /// <summary>
        /// Escape characters inside a text literal
        /// </summary>
        private string PELEscape(TextPortion SourcePosition, char EscapeChar)
        {
            StringBuilder sb = new StringBuilder(SourcePosition.Length);

            //Last position in the string
            var old_pos = SourcePosition.Begin;
            //Caret for finding \
            var crt = new Caret();
            crt.Source = SourcePosition.Text;
            string esc_char = EscapeChar.ToString(), esc_chars = esc_char + esc_char;

            for (var pos = SourcePosition.Text.IndexOf('\\', SourcePosition.Begin, SourcePosition.Length); pos >= 0; pos = SourcePosition.Text.IndexOf('\\', pos, SourcePosition.End - pos))
            {
                //Append in-between text
                if (pos != old_pos)
                    sb.Append(SourcePosition.Text.Substring(old_pos, pos - old_pos).Replace(esc_chars, esc_char));

                if (pos == SourcePosition.End)
                {
                    ThrowParseError("Expected a character to escape", new TextPortion(pos, 1));
                    break;
                }

                pos++;

                //End of file
                if (pos >= SourcePosition.End)
                    break;

                switch (SourcePosition.Text[pos])
                {
                case '\\':
                    sb.Append('\\');
                    pos++;
                    break;
                case 'r':
                case 'R':
                    sb.Append('\r');
                    pos++;
                    break;
                case 'n':
                case 'N':
                    sb.Append('\n');
                    pos++;
                    break;
                case 't':
                case 'T':
                    sb.Append('\t');
                    pos++;
                    break;
                case 'x':
                case 'X':
                    pos++;
                    crt.Position = pos;
                    if (!crt.Match(@"(?<cap>([0-9a-fA-F]{2})+)\\"))
                        ThrowParseError(
                            "Expected one or more consecutive 2-digit hexadecimal values, followed by a \\ (eg \\x2A\\, or \\x02A5F2\\)",
                            new TextPortion(pos, 1));
                    else
                    {
                        var cap = crt.LastMatch.Groups["cap"].Value;

                        for (int i = 0; i < cap.Length; i += 2)
                            sb.Append((char) Int16.Parse(cap.Substring(i, 2), NumberStyles.HexNumber));

                        pos = crt.Position;
                    }
                    break;
                case 'u':
                case 'U':
                    pos++;
                    crt.Position = pos;
                    if (!crt.Match(@"(?<cap>([0-9a-fA-F]{4})+)\\"))
                        ThrowParseError(
                            "Expected one or more consecutive 4-digit hexadecimal values, followed by a \\ (eg \\u002A\\, or \\u000200A510F2\\)",
                            new TextPortion(pos, 1));
                    else
                    {
                        var cap = crt.LastMatch.Groups["cap"].Value;

                        for (int i = 0; i < cap.Length; i += 4)
                            sb.Append((char) Int16.Parse(cap.Substring(i, 4), NumberStyles.HexNumber));

                        pos = crt.Position;
                    }
                    break;
                default:
                    ThrowParseError("Unexpected escape character", new TextPortion(pos, 1));
                    break;
                }

                old_pos = pos;
            }

            //Append remaining text
            if (old_pos != SourcePosition.End)
                sb.Append(SourcePosition.Text, old_pos, SourcePosition.End - old_pos);

            return sb.ToString();
        }
 /// <summary>
 /// Error with description and position defined
 /// </summary>
 internal void ThrowParseError(string Description, TextPortion TextPortion)
 {
     IDE.GrammarTree.ThrowParseError(Description, TextPortion);
 }
 internal void ThrowParseError(string Description, TextPortion TextPortion)
 {
     IDE.ExecutionTree.ParseErrors.Add(new ParseError(Description, TextPortion));
 }