コード例 #1
0
ファイル: WikiTextTerminal.cs プロジェクト: Jmerk523/Irony
        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();
        }
コード例 #2
0
ファイル: FreeTextLiteral.cs プロジェクト: cg123/xenko
 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();
 }
コード例 #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();
 }
コード例 #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(); 
 }
コード例 #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();
        }
コード例 #6
0
ファイル: FreeTextLiteral.cs プロジェクト: DevMk/Irony
        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();
        }
コード例 #7
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]);
            }
        }
コード例 #8
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);
            }
        }
コード例 #9
0
ファイル: StringLiteral.cs プロジェクト: hozuki/irony-vs
        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);
            }
        }