Click here to Skip to main content
15,885,309 members
Articles / Desktop Programming / Windows Forms

Storm - the world's best IDE framework for .NET

Rate me:
Please Sign up or sign in to vote.
4.96/5 (82 votes)
4 Feb 2010LGPL311 min read 274.4K   6.5K   340  
Create fast, flexible, and extensible IDE applications easily with Storm - it takes nearly no code at all!
//
//    ___ _____ ___  ___ __  __ 
//   / __|_   _/ _ \| _ \  \/  |
//   \__ \ | || (_) |   / |\/| |
//   |___/ |_| \___/|_|_\_|  |_|
// 
//   Storm.TextEditor.dll
//   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
//     Storm.TabControl.dll was created under the LGPL 
//     license. Some of the code was created from scratch, 
//     some was not. Code not created from scratch was 
//     based on the DotNetFireball framework and evolved 
//     from that. 
//     
//     What I mostly did in this library was that I 
//     cleaned up the code, structured it, documentated 
//     it and added new features. 
//     
//     Although it might not sound like it, it was very
//     hard and took a long (pretty much a shitload)
//     time. Why? Well, this was* some of the crappiest,
//     most unstructured, undocumentated, ugly code I've
//     ever seen. It would actually have taken me less 
//     time to create it from scratch, but I figured that
//     out too late. Figuring out what the code actually
//     did and then documentating it was (mostly) a 
//     day-long process. Well, I hope you enjoy some of
//     my hard work. /rant
//     
//     Of course some/most of it is made from scratch by me.
//     *Yes, was. It isn't now. :) Some of the naming 
//     conventions might still seem a little bit off though.
//
//   What is Storm?
//   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
//     Storm is a set of dynamic link libraries used in 
//     Theodor "Vestras" Storm Kristensen's application 
//     "Moonlite".
//     
//
//   Thanks:
//   ¯¯¯¯¯¯¯
//     - The DotNetFireball team for creating and publishing 
//       DotNetFireball which I based some of my code on.
//
//
//   Copyright (c) Theodor "Vestras" Storm Kristensen 2009
//   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
//


namespace Storm.TextEditor.ContentInfo
{
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.ComponentModel;
	using System.ComponentModel.Design;
	using System.Drawing;
	using System.Drawing.Design;
	using System.IO;
	using System.Reflection;
	using System.Resources;
	using System.Text;
	using System.Text.RegularExpressions;
	using System.Windows.Forms;

	using Storm.TextEditor;
	using Storm.TextEditor.ContentInfo;
	using Storm.TextEditor.Controls;
	using Storm.TextEditor.Controls.Core;
	using Storm.TextEditor.Controls.Core.Globalization;
	using Storm.TextEditor.Controls.Core.Timers;
	using Storm.TextEditor.Controls.IntelliMouse;
	using Storm.TextEditor.Document;
	using Storm.TextEditor.Document.Exporters;
	using Storm.TextEditor.Forms;
	using Storm.TextEditor.Interacting;
	using Storm.TextEditor.Painting;
	using Storm.TextEditor.Parsing;
	using Storm.TextEditor.Parsing.Base;
	using Storm.TextEditor.Parsing.Classes;
	using Storm.TextEditor.Parsing.Language;
	using Storm.TextEditor.Preset;
	using Storm.TextEditor.Preset.Painting;
	using Storm.TextEditor.Preset.TextDraw;
	using Storm.TextEditor.Printing;
	using Storm.TextEditor.Utilities;
	using Storm.TextEditor.Win32;

	/// <summary>
	/// Class used to hold information about a word.
	/// </summary>
	public class WordData
	{
		#region Members
		// Const members.
		private const string VJASS_FUNCTION_PATTERN = @"((?<scope>(private|public))\s+)?(?<constant>constant\s+)?func(tion)?\s(?<interface>interface\s+)?(?<name>[a-zA-Z]\w*)\s+takes\s+(?<arguments>[\w\s,]+)\sreturns\s+(?<return>\w+)";
		private const string VJASS_METHOD_PATTERN = @"((?<scope>(private|public))\s+)?(?<static>static\s+)?(?<constant>constant\s+)?method\s+(?<name>[a-zA-Z]\w*)\s+takes\s+(?<arguments>[\w\s,]+)\sreturns\s+(?<return>\w+)";

		private const string GALAXY_PATTERN = @""; // NOT IMPLEMENTED.

		// Basic members.
		private string _name = "";
		private string _description = "";
		private string _declaration = "";
		private string _arguments = "";
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the name of the Word
		/// </summary>
		public string Name
		{
			get { return _name; }
			set { _name = value; }
		}

		/// <summary>
		/// Gets or sets the description of the Word.
		/// </summary>
		public string Description
		{
			get { return _description; }
			set { _description = value; }
		}

		/// <summary>
		/// Gets or sets the declaration of the Word.
		/// </summary>
		public string Declaration
		{
			get { return _declaration; }
			set { _declaration = value; }
		}

		/// <summary>
		/// Gets or sets the arguments of the Word.
		/// </summary>
		public string Arguments
		{
			get { return _arguments; }
			set { _arguments = value; }
		}
		#endregion

		#region Methods
		/// <summary>
		/// Instead of setting Name, Declaration and Arguments manually, you can let this method do it for you. "Squishes" a string so we can get the information we want.
		/// </summary>
		/// <remarks>
		/// NOTE: Uses Regular Expressions!
		/// </remarks>
		/// <param name="pattern">Language you want to find the match for, eg. vJass or Galaxy.</param>
		/// <param name="findWhat">If pattern is RegexPattern.vJass, you will need to specify whether you want to find a function or a method. For Galaxy, use RegexFind.None.</param>
		/// <param name="text">Text you want to be searched.</param>
		public void SquishDataFromString(RegexPattern pattern, RegexFind findWhat, string text)
		{
			// Declare our MatchCollection.
			MatchCollection matches = null;

			// Check whether the user wants a vJass or a Galaxy match
			// and set our MatchCollection to check for matches, 
			// following the defined pattern.
			if (pattern == RegexPattern.vJass)
			{
				// The pattern was vJass, we will now check what the
				// user wants us to search for.
				if (findWhat == RegexFind.Function)
					matches = Regex.Matches(text, VJASS_FUNCTION_PATTERN);
				else if (findWhat == RegexFind.Method)
					matches = Regex.Matches(text, VJASS_METHOD_PATTERN);
				else if (findWhat == RegexFind.None)
					// The user specified RegexPattern.vJass and RegexFind.None, tell him/her that he/she can't.
					throw new ArgumentNullException("findWhat can't be 'RegexFind.None' when pattern is 'RegexPattern.vJass'.");
			}
			else if (pattern == RegexPattern.Galaxy)
				matches = Regex.Matches(text, GALAXY_PATTERN);

			// Check whether we found a match, and if we did, take
			// the first found match and do magik trikz to it.
			if (matches.Count > 0)
			{
				// Squish the data out of the found match. :)
				_name = matches[0].Groups["name"].Value;
				_arguments = matches[0].Groups["arguments"].Value;
				_declaration = text.Trim(); // Trim the text that the user specified 
				// so we can use it for our declaration.
			}
		}

		/// <summary>
		/// Instead of setting Name, Declaration and Arguments manually, you can let this method do it for you. "Squishes" a string so we can get the information we want.
		/// </summary>
		/// <remarks>
		/// NOTE: If you want the method to squish correctly, you will have to give the pattern a "name" and "arguments" group.
		/// Eg.: "((?<scope>(private|public))\s+)?(?<constant>constant\s+)?func(tion)?\s(?<interface>interface\s+)?(?<name>[a-zA-Z]\w*)\s+takes\s+(?<arguments>[\w\s,]+)\sreturns\s+(?<return>\w+)"
		/// </remarks>
		/// <param name="regexPattern">Regular Expression pattern to use for searching the specified text.</param>
		/// <param name="text">Text you want to be searched.</param>
		public void SquishDataFromString(string regexPattern, string text)
		{
			// Declare our MatchCollection with the specified Regular Expression pattern.
			MatchCollection matches = Regex.Matches(text, regexPattern);

			// Check whether we found a match, and if we did, take
			// the first found match and do magik trikz to it.
			if (matches.Count > 0)
			{
				// Squish the data out of the found match. :)
				_name = matches[0].Groups["name"].Value;
				_arguments = matches[0].Groups["arguments"].Value;
				_declaration = text.Trim(); // Trim the text that the user specified 
				// so we can use it for our declaration.
			}
		}
		#endregion

		/// <summary>
		/// Initializes the WordData.
		/// </summary>
		public WordData()
		{ }

		/// <summary>
		/// Initializes the WordData.
		/// </summary>
		public WordData(string name,
						string description,
						string declaration,
						string arguments)
		{
			_name = name;
			_description = description;
			_declaration = declaration;
			_arguments = arguments;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)



Comments and Discussions