Esempio n. 1
0
        /// <summary>
        /// Sets the terminal.
        /// </summary>
        /// <param name="terminal">The terminal.</param>
        public void SetTerminal(Terminal terminal)
        {
            Terminal = terminal;

            // Set to term's EditorInfo by default
            EditorInfo = Terminal.EditorInfo;
        }
Esempio n. 2
0
 public override void Initialize(GrammarData grammarData)
 {
     base.Initialize(grammarData);
     if (EditorInfo == null)
     {
         EditorInfo = new TokenEditorInfo(TokenType.Unknown, TokenColor.Text, TokenTriggers.None);
     }
 }
 public override void Init(GrammarData grammarData)
 {
     base.Init(grammarData);
     var workPattern = @"\G(" + Pattern + ")";
     var options = (Grammar.CaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);
     Expression = new Regex(workPattern, options);
     if (EditorInfo == null)
         EditorInfo = new TokenEditorInfo(TokenType.Unknown, TokenColor.Text, TokenTriggers.None);
 }
Esempio n. 4
0
        public override void Initialize(GrammarData grammarData)
        {
            base.Initialize(grammarData);

            // initialize string of start characters for fast lookup
            _startSymbolsFirsts = new string(StartSymbols.Select(s => s.First()).ToArray());

            if (EditorInfo == null)
            {
                EditorInfo = new TokenEditorInfo(TokenType.Delimiter, TokenColor.Comment, TokenTriggers.None);
            }
        }
Esempio n. 5
0
        public override void Initialize(GrammarData grammarData)
        {
            base.Initialize(grammarData);
            var workPattern = @"\G(" + Pattern + ")";
            var options     = (Grammar.CaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase);

            _expression = new Regex(workPattern, options);
            if (EditorInfo == null)
            {
                EditorInfo = new TokenEditorInfo(TokenType.Unknown, TokenColor.Text, TokenTriggers.None);
            }
        }
        public override void Init(GrammarData grammarData)
        {
            base.Init(grammarData);

            // initialize string of start characters for fast lookup
            _startSymbolsFirsts = new string(StartSymbols.Select(s => s.First()).ToArray());

            if (EditorInfo == null)
            {
                EditorInfo = new TokenEditorInfo(TokenType.Delimiter, TokenColor.Comment, TokenTriggers.None);
            }
        }
Esempio n. 7
0
 public override void Initialize(GrammarData grammarData)
 {
     base.Initialize(grammarData);
     //Default Exponent symbols if table is empty
     if (_exponentsTable.Count == 0 && !IsSet(NumberOptions.IntOnly))
     {
         _exponentsTable['e'] = DefaultFloatType;
         _exponentsTable['E'] = DefaultFloatType;
     }
     if (EditorInfo == null)
     {
         EditorInfo = new TokenEditorInfo(TokenType.Literal, TokenColor.Number, TokenTriggers.None);
     }
 }
 public override void Init(GrammarData grammarData)
 {
     base.Init(grammarData);
     //_endSymbolsFirsts char array is used for fast search for end symbols using String's method IndexOfAny(...)
     _endSymbolsFirsts = new char[EndSymbols.Count];
     for (var i = 0; i < EndSymbols.Count; i++)
     {
         var sym = EndSymbols[i];
         _endSymbolsFirsts[i] = sym[0];
         _isLineComment |= sym.Contains("\n");
         if (!_isLineComment)
             SetFlag(TermFlags.IsMultiline);
     }
     if (EditorInfo == null)
     {
         var ttype = _isLineComment ? TokenType.LineComment : TokenType.Comment;
         EditorInfo = new TokenEditorInfo(ttype, TokenColor.Comment, TokenTriggers.None);
     }
 }
Esempio n. 9
0
 public override void Initialize(GrammarData grammarData)
 {
     base.Initialize(grammarData);
     //_endSymbolsFirsts char array is used for fast search for end symbols using String's method IndexOfAny(...)
     _endSymbolsFirsts = new char[EndSymbols.Count];
     for (var i = 0; i < EndSymbols.Count; i++)
     {
         var sym = EndSymbols[i];
         _endSymbolsFirsts[i] = sym[0];
         _isLineComment      |= sym.Contains("\n");
         if (!_isLineComment)
         {
             SetFlag(TermFlags.IsMultiline);
         }
     }
     if (EditorInfo == null)
     {
         var ttype = _isLineComment ? TokenType.LineComment : TokenType.Comment;
         EditorInfo = new TokenEditorInfo(ttype, TokenColor.Comment, TokenTriggers.None);
     }
 }
Esempio n. 10
0
        private void SetupEditorInfo()
        {
            //Setup editor info
            if (EditorInfo != null)
            {
                return;
            }

            var tknType = TokenType.Identifier;

            if (Flags.IsSet(TermFlags.IsOperator))
            {
                tknType |= TokenType.Operator;
            }
            else if (Flags.IsSet(TermFlags.IsDelimiter | TermFlags.IsPunctuation))
            {
                tknType |= TokenType.Delimiter;
            }

            var triggers = TokenTriggers.None;

            if (Flags.IsSet(TermFlags.IsBrace))
            {
                triggers |= TokenTriggers.MatchBraces;
            }

            if (Flags.IsSet(TermFlags.IsMemberSelect))
            {
                triggers |= TokenTriggers.MemberSelect;
            }

            var color = TokenColor.Text;

            if (Flags.IsSet(TermFlags.IsKeyword))
            {
                color = TokenColor.Keyword;
            }

            EditorInfo = new TokenEditorInfo(tknType, color, triggers);
        }
Esempio n. 11
0
        public override void Initialize(GrammarData grammarData)
        {
            base.Initialize(grammarData);
            _allCharsSet = new CharHashSet(Grammar.CaseSensitive);
            _allCharsSet.UnionWith(AllChars.ToCharArray());

            //Adjust case restriction. We adjust only first chars; if first char is ok, we will scan the rest without restriction
            // and then check casing for entire identifier
            switch (CaseRestriction)
            {
            case CaseRestriction.AllLower:
            case CaseRestriction.FirstLower:
                _allFirstCharsSet = new CharHashSet(true);
                _allFirstCharsSet.UnionWith(AllFirstChars.ToLowerInvariant().ToCharArray());
                break;

            case CaseRestriction.AllUpper:
            case CaseRestriction.FirstUpper:
                _allFirstCharsSet = new CharHashSet(true);
                _allFirstCharsSet.UnionWith(AllFirstChars.ToUpperInvariant().ToCharArray());
                break;

            default:
                //None
                _allFirstCharsSet = new CharHashSet(Grammar.CaseSensitive);
                _allFirstCharsSet.UnionWith(AllFirstChars.ToCharArray());
                break;
            }
            //if there are "first" chars defined by categories, add the terminal to FallbackTerminals
            if (StartCharCategories.Count > 0)
            {
                grammarData.NoPrefixTerminals.Add(this);
            }

            if (EditorInfo == null)
            {
                EditorInfo = new TokenEditorInfo(TokenType.Identifier, TokenColor.Identifier, TokenTriggers.None);
            }
        }
Esempio n. 12
0
 public void SetTerminal(Terminal terminal)
 {
     Terminal        = terminal;
     this.EditorInfo = Terminal.EditorInfo; //set to term's EditorInfo by default
 }
Esempio n. 13
0
 public GherkinIdentifier(string name)
     : base(name, FreeTextOptions.AllowEof, "\n", "\r")
 {
     Priority = LowestPriority + 100;
     EditorInfo = new TokenEditorInfo(TokenType.Identifier, TokenColor.Identifier, TokenTriggers.None);
 }
Esempio n. 14
0
        public override void Initialize(GrammarData grammarData)
        {
            base.Initialize(grammarData);

            _startSymbolsFirsts = new CharHashSet(CaseSensitivePrefixesSuffixes);

            if (_subTypes.Count == 0)
            {
                //"Error in heredoc literal [{0}]: No start/end symbols specified."
                grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrInvHereDocDef, Name);
                return;
            }

            MergeSubTypes();

            _subTypes.Sort(HereDocSubType.LongerStartFirst);

            var quoteStrings = new StringSet(QuoteCaseSensitive ? StringComparer.InvariantCulture : StringComparer.InvariantCultureIgnoreCase);

            foreach (var subType in _subTypes)
            {
                if (quoteStrings.Overlaps(subType.Quotes))
                {
                    //"Duplicate start symbol {0} in heredoc literal [{1}]."
                    grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrDupStartSymbolHereDoc, subType.Start, Name);
                }
                quoteStrings.UnionWith(subType.Quotes);
            }

            // Cases are merged, no need to check duplicated entries.
            var isTemplate = false;

            foreach (var subType in _subTypes)
            {
                _startSymbolsFirsts.Add(subType.Start[0]);
                if ((subType.Flags & HereDocOptions.IsTemplate) != 0)
                {
                    isTemplate = true;
                }
            }

            // Always allow multiline.
            SetFlag(TermFlags.IsMultiline);

            if (isTemplate)
            {
                //Check that template settings object is provided
                var templateSettings = AstConfig.Data as StringTemplateSettings;
                if (templateSettings == null)
                {
                    //"Error in string literal [{0}]: IsTemplate flag is set, but TemplateSettings is not provided."
                    grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrTemplNoSettings, Name);
                }
                else if (templateSettings.ExpressionRoot == null)
                {
                    //""
                    grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrTemplMissingExprRoot, Name);
                }
                else if (!Grammar.SnippetRoots.Contains(templateSettings.ExpressionRoot))
                {
                    //""
                    grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrTemplExprNotRoot, Name);
                }
            }

            //Create editor info
            if (EditorInfo == null)
            {
                EditorInfo = new TokenEditorInfo(TokenType.String, TokenColor.String, TokenTriggers.None);
            }
        }
Esempio n. 15
0
        public override void Initialize(GrammarData grammarData)
        {
            base.Initialize(grammarData);
            _startSymbolsFirsts = new CharHashSet(CaseSensitivePrefixesSuffixes);
            if (_subtypes.Count == 0)
            {
                //"Error in string literal [{0}]: No start/end symbols specified."
                grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrInvStrDef, Name);
                return;
            }
            //collect all start-end symbols in lists and create strings of first chars
            var allStartSymbols = new StringSet(); //to detect duplicate start symbols

            _subtypes.Sort(StringSubType.LongerStartFirst);
            var isTemplate = false;

            foreach (var subType in _subtypes)
            {
                if (allStartSymbols.Contains(subType.Start))
                {
                    //"Duplicate start symbol {0} in string literal [{1}]."
                    grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrDupStartSymbolStr, subType.Start, Name);
                }

                allStartSymbols.Add(subType.Start);
                _startSymbolsFirsts.Add(subType.Start[0]);
                if ((subType.Flags & StringOptions.IsTemplate) != 0)
                {
                    isTemplate = true;
                }
            }

            //Set multiline flag
            if (_subtypes.Any(info => (info.Flags & StringOptions.AllowsLineBreak) != 0))
            {
                SetFlag(TermFlags.IsMultiline);
            }

            //For templates only
            if (isTemplate)
            {
                //Check that template settings object is provided
                var templateSettings = AstConfig.Data as StringTemplateSettings;
                if (templateSettings == null)
                {
                    //"Error in string literal [{0}]: IsTemplate flag is set, but TemplateSettings is not provided."
                    grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrTemplNoSettings, Name);
                }
                else if (templateSettings.ExpressionRoot == null)
                {
                    //""
                    grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrTemplMissingExprRoot, Name);
                }
                else if (!Grammar.SnippetRoots.Contains(templateSettings.ExpressionRoot))
                {
                    //""
                    grammarData.Language.Errors.Add(GrammarErrorLevel.Error, null, Resources.ErrTemplExprNotRoot, Name);
                }
            }

            //Create editor info
            if (EditorInfo == null)
            {
                EditorInfo = new TokenEditorInfo(TokenType.String, TokenColor.String, TokenTriggers.None);
            }
        }