// * // * Copyright (C) 2008 Roger Alsing : http://www.RogerAlsing.com // * // * This library is free software; you can redistribute it and/or modify it // * under the terms of the GNU Lesser General Public License 2.1 or later, as // * published by the Free Software Foundation. See the included license.txt // * or http://www.gnu.org/copyleft/lesser.html for details. // * // * using System.Text.RegularExpressions; namespace Alsing.SourceCode { /// /// A Pattern is a specific string or a RegEx pattern that is used by the parser. /// There are two types of patterns , Simple and Complex. /// /// Simple Patterns are patterns that consists of a simple fixed string eg. "void" or "for". /// Complex Patterns are patterns that consists of RegEx patterns , eg hex numbers or urls can be described as regex patterns. /// public sealed partial class Pattern { public static readonly string DefaultSeparators = ".,+-*^\\/()[]{}@:;'?�$#%& \t=<>"; #region PUBLIC PROPERTY SEPARATORS private string _Separators = DefaultSeparators; public string Separators { get { return _Separators; } set { _Separators = value; } } #endregion private string _StringPattern = ""; public BracketType BracketType = BracketType.None; /// /// Category of the pattern /// Built in categories are: /// URL /// MAIL /// FILE /// public string Category; /// /// Gets if the pattern is a simple string or a RegEx pattern /// public bool IsComplex; /// /// Get or Sets if this pattern needs separator chars before and after it in order to be valid. /// public bool IsKeyword; public bool IsMultiLineBracket = true; /// /// Gets or Sets if the pattern is a separator pattern . /// A separator pattern can be "End Sub" in VB6 , whenever that pattern is found , the SyntaxBoxControl will render a horizontal separator line. /// NOTE: this should not be mixed up with separator chars. /// public bool IsSeparator; /// /// For internal use only /// public string LowerStringPattern = ""; public Pattern MatchingBracket; /// /// The owning PatternList , eg a specific KeywordList or OperatorList /// public PatternList Parent; internal Regex rx; /// /// /// /// /// public Pattern(string pattern, bool iscomplex) { StringPattern = pattern; if (iscomplex) { IsComplex = true; rx = new Regex(StringPattern, RegexOptions.Compiled); } else { IsComplex = false; } } /// /// /// /// /// /// /// public Pattern(string pattern, bool iscomplex, bool separator, bool keyword) { Init(pattern, iscomplex, separator, keyword); } /// /// /// /// /// /// /// public Pattern(string pattern, bool separator, bool keyword, string escapeChar) { escapeChar = Regex.Escape(escapeChar); string escapePattern = string.Format("(?<=((? /// Gets or Sets the the text of the pattern /// this only applies if the pattern is a simple pattern. /// public string StringPattern { get { return _StringPattern; } set { _StringPattern = value; LowerStringPattern = _StringPattern.ToLowerInvariant(); } } /// /// Returns true if the pattern contains separator chars
/// (This is used by the parser) ///
public bool ContainsSeparator { get { foreach (char c in StringPattern) { if (Separators.IndexOf(c) >= 0) return true; } return false; } } private void Init(string pattern, bool isComplex, bool separator, bool keyword) { StringPattern = pattern; IsSeparator = separator; IsKeyword = keyword; IsComplex = isComplex; if (isComplex) rx = new Regex(StringPattern, RegexOptions.Compiled); } } }