Ejemplo n.º 1
0
        public override void Init(GrammarData grammarData)
        {
            base.Init(grammarData);
            var stopCharSet = new CharHashSet();

            foreach (var term in grammarData.Terminals)
            {
                var firsts = term.GetFirsts();
                if (firsts == null)
                {
                    continue;
                }
                foreach (var first in firsts)
                {
                    if (!string.IsNullOrEmpty(first))
                    {
                        stopCharSet.Add(first[0]);
                    }
                }
            }//foreach term
            if (EscapeChar != NoEscape)
            {
                stopCharSet.Add(EscapeChar);
            }
            _stopChars = stopCharSet.ToArray();
        }
Ejemplo n.º 2
0
 public override void Init(GrammarData grammarData) {
   base.Init(grammarData);
   var stopChars = new CharHashSet();
   foreach (var key in Escapes.Keys)
     stopChars.Add(key[0]);
   foreach (var t in Terminators)
     stopChars.Add(t[0]);
   _stopChars = stopChars.ToArray();
 }
Ejemplo n.º 3
0
 public override void Init(GrammarData grammarData) {
   base.Init(grammarData);
   _isSimple = Terminators.Count == 1 && Escapes.Count == 0;
   if (_isSimple) {
     _singleTerminator = Terminators.First(); 
     return;
   }
   var stopChars = new CharHashSet();
   foreach (var key in Escapes.Keys)
     stopChars.Add(key[0]);
   foreach (var t in Terminators)
     stopChars.Add(t[0]);
   _stopChars = stopChars.ToArray();
 }
Ejemplo n.º 4
0
 public override void Init(GrammarData grammarData) {
   base.Init(grammarData);
   var stopCharSet = new CharHashSet();
   foreach(var term in grammarData.Terminals) {
     var firsts = term.GetFirsts(); 
     if (firsts == null) continue; 
     foreach (var first in firsts)
       if (!string.IsNullOrEmpty(first))
         stopCharSet.Add(first[0]); 
   }//foreach term
   if (EscapeChar != NoEscape)  
     stopCharSet.Add(EscapeChar);
   _stopChars = stopCharSet.ToArray(); 
 }
Ejemplo n.º 5
0
        public override void Init(GrammarData grammarData)
        {
            base.Init(grammarData);
            var stopChars = new CharHashSet();

            foreach (var key in Escapes.Keys)
            {
                stopChars.Add(key[0]);
            }
            foreach (var t in Terminators)
            {
                stopChars.Add(t[0]);
            }
            _stopChars = stopChars.ToArray();
        }
Ejemplo n.º 6
0
        public override void Initialize(GrammarData grammarData)
        {
            base.Initialize(grammarData);
            //collect all suffixes, prefixes in lists and create sets of first chars for both
            Prefixes.Sort(StringList.LongerFirst);
            Suffixes.Sort(StringList.LongerFirst);

            _prefixesFirsts = new CharHashSet(CaseSensitivePrefixesSuffixes);
            _suffixesFirsts = new CharHashSet(CaseSensitivePrefixesSuffixes);
            foreach (var pfx in Prefixes)
            {
                _prefixesFirsts.Add(pfx[0]);
            }
            foreach (var sfx in Suffixes)
            {
                _suffixesFirsts.Add(sfx[0]);
            }
        }
Ejemplo n.º 7
0
        public override void Init(GrammarData grammarData)
        {
            base.Init(grammarData);
            _isSimple = Terminators.Count == 1 && Escapes.Count == 0;
            if (_isSimple)
            {
                _singleTerminator = Terminators.First();
                return;
            }
            var stopChars = new CharHashSet();

            foreach (var key in Escapes.Keys)
            {
                stopChars.Add(key[0]);
            }
            foreach (var t in Terminators)
            {
                stopChars.Add(t[0]);
            }
            _stopChars = stopChars.ToArray();
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
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);
            }
        }