Exemplo n.º 1
0
        /// <summary>
        /// Scans for all the grammar rules that are considered for the token at the specified text position.
        /// </summary>
        private Parser <LexicalToken> GetBestGrammarAtPosition(int position)
        {
            var offset = _code.GetTokenIndex(position);
            var source = new ArraySource <LexicalToken>(_code.GetLexicalTokens());

            Parser <LexicalToken> bestGrammar = null;
            int bestLength = -1;

            _code.Grammar.Search(source, (_parser, _source, _start, _prevWasMissing) =>
            {
                // capture the best grammar
                if (_start == offset && _parser.Tag != null)
                {
                    var scanLength = _parser.Scan(source, _start);
                    if (scanLength > bestLength)
                    {
                        bestGrammar = _parser;
                        bestLength  = scanLength;
                    }
                }
            });

            return(bestGrammar);
        }