Пример #1
0
        private Lexer(string text, TextReader reader, LexerBehavior behavior, LexerSettings settings)
        {
            if (settings == null)
            {
                settings = LexerSettings.Default;
            }
            else
            {
                settings = settings.Clone();
            }

            this.text     = text;
            this.reader   = reader;
            this.behavior = behavior;
            this.settings = settings;

            if (settings.Symbols != null)
            {
                foreach (KeyValuePair <string, int> entry in settings.Symbols)
                {
                    int len = entry.Key.Length;
                    if (len > maxSymLen)
                    {
                        maxSymLen = len;
                    }
                }
            }

            Reset();
        }
Пример #2
0
 public Lexer(string text, LexerSettings settings)
     : this(text, null, LexerBehavior.Default, settings)
 {
 }
Пример #3
0
 public Lexer(string text, LexerBehavior behavior, LexerSettings settings)
     : this(text, null, behavior, settings)
 {
 }
Пример #4
0
        public LexerSettings Clone()
        {
            LexerSettings settings = (LexerSettings)MemberwiseClone();

            if (settings.CultureInfo == null)
            {
                settings.CultureInfo = CultureInfo.InvariantCulture;
            }

            if (settings.CompareInfo == null)
            {
                settings.CompareInfo = settings.CultureInfo.CompareInfo;
            }

            if (string.IsNullOrEmpty(settings.DecimalSeparator))
            {
                settings.DecimalSeparator = settings.CultureInfo.NumberFormat.NumberDecimalSeparator;
            }

            if (settings.Symbols != null && settings.Symbols.Count > 0)
            {
                settings.Symbols = new Dictionary <string, int>(settings.Symbols);
            }
            else
            {
                settings.Symbols = null;
            }

            if (settings.Keywords != null && settings.Keywords.Count > 0)
            {
                bool ignoreCase = (settings.Options & LexerOptions.IdentIgnoreCase) != 0;
                settings.Keywords = new Dictionary <string, int>(settings.Keywords, StringComparer.Create(settings.CultureInfo, ignoreCase));
            }
            else
            {
                settings.Keywords = null;
            }

            if (settings.StringQuotes != null)
            {
                settings.StringQuotes = (char[])settings.StringQuotes.Clone();
            }

            if (settings.IdentChars != null)
            {
                settings.IdentChars = (char[])settings.IdentChars.Clone();
            }

            string[] inlineComments = settings.InlineComments;
            if (inlineComments != null)
            {
                int length = inlineComments.Length;
                int count  = 0;
                for (int i = 0; i < length; i++)
                {
                    string inlineComment = inlineComments[i];
                    if (inlineComment == null)
                    {
                        continue;
                    }

                    if (i != count)
                    {
                        inlineComments[count] = inlineComment;
                    }

                    count++;
                }

                if (count == 0)
                {
                    settings.InlineComments = null;
                }
                else
                {
                    string[] arr = new string[count];
                    Array.Copy(inlineComments, 0, arr, 0, count);
                }
            }

            if (!string.IsNullOrEmpty(settings.CommentBegin) && string.IsNullOrEmpty(settings.CommentEnd))
            {
                settings.CommentEnd = settings.CommentBegin;
            }

            return(settings);
        }
Пример #5
0
 public Lexer(TextReader reader, LexerSettings settings)
     : this(null, reader, LexerBehavior.Default, settings)
 {
 }
Пример #6
0
 public Lexer(TextReader reader, LexerBehavior behavior, LexerSettings settings)
     : this(null, reader, behavior, settings)
 {
 }