Esempio n. 1
0
        public Lexer(ITokenTypes <TokenClassificationType> tokenTypes)
        {
            var comment      = ParserComment.Select(value => tokenTypes.Comment);
            var preprocessor = ParserPreprocessor.Select(value => tokenTypes.PreprocessorKeyword);

            TokenClassificationType CheckGlslSpecifics(string word)
            {
                if (GlslSpecification.IsKeyword(word))
                {
                    return(tokenTypes.Keyword);
                }
                if (GlslSpecification.IsFunction(word))
                {
                    return(tokenTypes.Function);
                }
                if (GlslSpecification.IsVariable(word))
                {
                    return(tokenTypes.Variable);
                }
                if (GlslSpecification.IsUserKeyWord(word))
                {
                    return(tokenTypes.UserKeyWord);
                }
                return(tokenTypes.Identifier);
            }

            var number     = ParserNumber.Select(value => tokenTypes.Number);
            var identifier = ParserIdentifier.Select(value => CheckGlslSpecifics(value));
            var op         = ParserOperator.Select(value => tokenTypes.Operator);
            var token      = comment.Or(preprocessor).Or(number).Or(identifier).Or(op);

            tokenParser = token.WithPosition().Token().XMany();
        }
        private static SnapshotPoint NonIdentifierPositionBefore(SnapshotPoint triggerPoint)
        {
            var line = triggerPoint.GetContainingLine();

            SnapshotPoint start = triggerPoint;

            while (start > line.Start && GlslSpecification.IsIdentifierChar((start - 1).GetChar()))
            {
                start -= 1;
            }

            return(start);
        }
Esempio n. 3
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            bool handled = false;
            int  hresult = VSConstants.S_OK;

            // 1. Pre-process
            if (pguidCmdGroup == VSConstants.VSStd2K)
            {
                switch ((VSConstants.VSStd2KCmdID)nCmdID)
                {
                case VSConstants.VSStd2KCmdID.AUTOCOMPLETE:
                case VSConstants.VSStd2KCmdID.COMPLETEWORD:
                    handled = StartSession();
                    break;

                case VSConstants.VSStd2KCmdID.RETURN:
                    handled = Complete(false);
                    break;

                case VSConstants.VSStd2KCmdID.TAB:
                    handled = Complete(true);
                    break;

                case VSConstants.VSStd2KCmdID.CANCEL:
                    handled = Cancel();
                    break;

                case VSConstants.VSStd2KCmdID.COMMENTBLOCK:
                case VSConstants.VSStd2KCmdID.COMMENT_BLOCK:
                    Comment(TextView);
                    handled = true;
                    break;

                case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
                case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
                    UnComment(TextView);
                    handled = true;
                    break;
                }
            }
            ThreadHelper.ThrowIfNotOnUIThread();
            if (!handled)
            {
                hresult = Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
            }

            if (ErrorHandler.Succeeded(hresult))
            {
                if (pguidCmdGroup == VSConstants.VSStd2K)
                {
                    switch ((VSConstants.VSStd2KCmdID)nCmdID)
                    {
                    case VSConstants.VSStd2KCmdID.TYPECHAR:
                        var c = GetTypeChar(pvaIn);
                        if (!GlslSpecification.IsIdentifierChar(c))
                        {
                            Cancel();
                        }
                        else if (_currentSession != null)
                        {
                            Filter();
                        }
                        else if (GlslSpecification.IsIdentifierStartChar(c))
                        {
                            StartSession();
                        }
                        break;

                    case VSConstants.VSStd2KCmdID.BACKSPACE:
                        Filter();
                        break;
                    }
                }
            }

            return(hresult);
        }