Exemplo n.º 1
0
        /// <summary>
        ///     Preforms an auto-complete parse on the specified stream of LSL source code, up to an arbitrary offset.
        /// </summary>
        /// <param name="code">The input source code.</param>
        /// <param name="toOffset">To offset to parse up to (the cursor offset).</param>
        /// <param name="options">Parse options.</param>
        /// <exception cref="ArgumentOutOfRangeException">if <paramref name="toOffset" /> is not greater than zero.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="code" /> is <c>null</c>.</exception>
        public override void Parse(string code, int toOffset, LSLAutoCompleteParseOptions options)
        {
            if (code == null)
            {
                throw new ArgumentNullException("code");
            }

            if (toOffset < 0)
            {
                throw new ArgumentOutOfRangeException("toOffset", "toOffset cannot be less than zero.");
            }

            var detectInStringOrComment = new LSLCommentAndStringDetector(code, toOffset);

            var visitor = new LSLAutoCompleteVisitor(toOffset);

            ParserState = visitor;


            var behind = LookBehindOffset(code, toOffset, 1, 1);



            if ((options & LSLAutoCompleteParseOptions.BlockOnInvalidPrefix) == LSLAutoCompleteParseOptions.BlockOnInvalidPrefix)
            {
                if (!IsValidSuggestionPrefix(behind))
                {
                    visitor.InvalidPrefix = true;

                    return;
                }
            }


            if ((options & LSLAutoCompleteParseOptions.BlockOnInvalidKeywordPrefix) ==
                LSLAutoCompleteParseOptions.BlockOnInvalidKeywordPrefix)
            {
                if (KeywordPriorBlocksCompletion(code, toOffset))
                {
                    visitor.InvalidKeywordPrefix = true;

                    return;
                }
            }


            if (detectInStringOrComment.InComment || detectInStringOrComment.InString)
            {
                visitor.InString       = detectInStringOrComment.InString;
                visitor.InComment      = detectInStringOrComment.InComment;
                visitor.InLineComment  = detectInStringOrComment.InLineComment;
                visitor.InBlockComment = detectInStringOrComment.InBlockComment;
                return;
            }


            var inputStream = new AntlrInputStream(new StringReader(code), toOffset);

            var lexer = new LSLLexer(inputStream);

            var tokenStream = new CommonTokenStream(lexer);

            var parser = new LSLParser(tokenStream);


            parser.RemoveErrorListeners();
            lexer.RemoveErrorListeners();

            visitor.Parse(parser.compilationUnit());
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Preforms an auto-complete parse on the specified stream of LSL source code, up to an arbitrary offset.
 /// </summary>
 /// <param name="code">The input source code.</param>
 /// <param name="toOffset">To offset to parse up to (the cursor offset).</param>
 /// <param name="options">Parse options.</param>
 public abstract void Parse(string code, int toOffset, LSLAutoCompleteParseOptions options);