Esempio n. 1
0
        public override void Parse(string text, int caret_position)
        {
            _tokens.Clear();
            var tokenizer = Engine.GetService <TokenCategorizer>();

            if (tokenizer == null)
            {
                return;
            }

            // init with whole text
            tokenizer.Initialize(null, Engine.CreateScriptSourceFromString(text), SourceLocation.MinValue);

            var t = tokenizer.ReadToken();

            while (t.Category != Microsoft.Scripting.TokenCategory.EndOfStream)
            {
                CodeTokenType type = CodeTokenType.None;

                switch (t.Category)
                {
                case TokenCategory.Comment:
                case TokenCategory.LineComment:
                case TokenCategory.DocComment:
                    type = CodeTokenType.Comment;
                    break;

                case TokenCategory.Keyword:
                    type = CodeTokenType.Keyword;
                    break;

                case TokenCategory.StringLiteral:
                case TokenCategory.CharacterLiteral:
                    type = CodeTokenType.String;
                    break;

                case TokenCategory.NumericLiteral:
                    type = CodeTokenType.Number;
                    break;

                case TokenCategory.Operator:
                    type = CodeTokenType.Operator;
                    break;

                case TokenCategory.Identifier:
                    type = CodeTokenType.Indentifier;
                    break;
                }

                _tokens.Add(new CodeToken()
                {
                    TokenType = type, Start = t.SourceSpan.Start.Index, End = t.SourceSpan.End.Index
                });
                t = tokenizer.ReadToken();
            }
        }
Esempio n. 2
0
        private void AddToken(IParsingTreeTerminal term, CodeTokenType type)
        {
            var from = term.From;

            while (_lines.Count <= from.Line)
            {
                _lines.Add(new List <KeyValuePair <IParsingTreeTerminal, HighlightingColor> >());
            }

            _lines[from.Line].Add(new KeyValuePair <IParsingTreeTerminal, HighlightingColor>(term, _brushes[type]));

            _tokens.Add(new SyntaxHighlight.CodeToken()
            {
                Start     = _currReader.GetPosition(term.From),
                End       = _currReader.GetPosition(term.To),
                TokenType = type
            });
        }
        public string AddCode(CodeTokenType type, int clientId, string userName, string scope)
        {
            using (var entities = IdentityServerConfigurationContext.Get())
            {
                var code = Guid.NewGuid().ToString("N");

                var refreshToken = new CodeToken
                {
                    Type = (int) type,
                    Code = code,
                    ClientId = clientId,
                    Scope = scope,
                    UserName = userName,
                    TimeStamp = DateTime.UtcNow
                };

                entities.CodeTokens.Add(refreshToken);
                entities.SaveChanges();

                return code;
            }
        }
        public string AddCode(CodeTokenType type, int clientId, string userName, string scope)
        {
            using (var entities = IdentityServerConfigurationContext.Get())
            {
                var code = Guid.NewGuid().ToString("N");

                var refreshToken = new CodeToken
                {
                    Type      = (int)type,
                    Code      = code,
                    ClientId  = clientId,
                    Scope     = scope,
                    UserName  = userName,
                    TimeStamp = DateTime.UtcNow
                };

                entities.CodeTokens.Add(refreshToken);
                entities.SaveChanges();

                return(code);
            }
        }
        public IEnumerable<Models.CodeToken> Search(int? clientId, string username, string scope, CodeTokenType type)
        {
            using (var entities = IdentityServerConfigurationContext.Get())
            {
                var query =
                    from t in entities.CodeTokens
                    where t.Type == (int) type
                    select t;

                if (clientId != null)
                {
                    query =
                        from t in query
                        where t.ClientId == clientId.Value
                        select t;
                }

                if (!string.IsNullOrWhiteSpace(username))
                {
                    query =
                        from t in query
                        where t.UserName.Contains(username)
                        select t;
                }

                if (!string.IsNullOrWhiteSpace(scope))
                {
                    query =
                        from t in query
                        where t.Scope.Contains(scope)
                        select t;
                }

                var results = query.ToArray().Select(x => x.ToDomainModel());
                return results;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Return syntax rule for category
        /// </summary>
        /// <param name="tc"></param>
        /// <returns></returns>
        private SyntaxRuleItem GetSyntaxRule(CodeTokenType tc)
        {
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                return(null);
            }

            // caching in dictionary
            if (_rules == null)
            {
                _rules = new Dictionary <CodeTokenType, SyntaxRuleItem>();
                foreach (SyntaxRuleItem i in SyntaxRules)
                {
                    _rules[i.RuleType] = i;
                }
            }

            if (_rules.ContainsKey(tc))
            {
                return(_rules[tc]);
            }

            return(null);
        }
        /// <summary>
        /// Parses the text form start_pos to end_pos
        /// </summary>
        /// <param name="text">Whole text of the textbox</param>
        /// <param name="start_pos">position where to start parsing</param>
        /// <param name="end_pos">position where to stop parsing</param>
        public void Parse(string text, int start_pos, int end_pos)
        {
            int line_start = start_pos;
            int line_end   = 0;

            int word_start = start_pos;
            int word_end   = 0;

            int com_start = start_pos;

            do
            {
                // get the end position of the current line
                line_end = text.IndexOf(Environment.NewLine, line_start);
                if (line_end == -1)
                {
                    line_end = text.Length;
                }

                do
                {
                    // get the end position of the current word
                    word_end = text.IndexOfAny(anyNewWord, word_start);
                    if (word_end == -1)
                    {
                        word_end = text.Length;
                    }

                    // check if there is a comment-charakter in the current word
                    com_start = text.IndexOf(';', word_start);
                    if (com_start != -1 && com_start < word_end)
                    {
                        // Remove all tokens from the start of the comment to the end of the line
                        _tokens.RemoveAll(t => { return((t.Start > com_start && t.Start < line_end) || (t.End > com_start && t.End < line_end)); });
                        // and add the comment token and stop parsing this line
                        _tokens.Add(new CodeToken()
                        {
                            Start = com_start, End = line_end, TokenType = CodeTokenType.Comment
                        });
                        break;
                    }

                    // extract the current word and check if it is a token
                    if (word_end > word_start)
                    {
                        string        word = text.Substring(word_start, word_end - word_start);
                        CodeTokenType type = getTokenType(word);
                        if (type != CodeTokenType.None)
                        {
                            _tokens.Add(new CodeToken()
                            {
                                Start = word_start, End = word_end, TokenType = type
                            });
                        }
                    }

                    // set the new word start position
                    word_start = word_end + 1;
                }while(word_start <= line_end);

                // set the new line start position
                line_start = line_end + 2;
                // set the new word start position
                word_start = line_start;
            } while(line_start <= end_pos);
        }
Esempio n. 8
0
        public IEnumerable <Models.CodeToken> Search(int?clientId, string username, string scope, CodeTokenType type)
        {
            using (var entities = IdentityServerConfigurationContext.Get())
            {
                var query =
                    from t in entities.CodeTokens
                    where t.Type == (int)type
                    select t;

                if (clientId != null)
                {
                    query =
                        from t in query
                        where t.ClientId == clientId.Value
                        select t;
                }

                if (!string.IsNullOrWhiteSpace(username))
                {
                    query =
                        from t in query
                        where t.UserName.Contains(username)
                        select t;
                }

                if (!string.IsNullOrWhiteSpace(scope))
                {
                    query =
                        from t in query
                        where t.Scope.Contains(scope)
                        select t;
                }

                var results = query.ToArray().Select(x => x.ToDomainModel());
                return(results);
            }
        }
 public IEnumerable<CodeToken> Search(int? clientId, string username, string scope, CodeTokenType type)
 {
     throw new NotImplementedException();
 }
 public string AddCode(CodeTokenType type, int clientId, string userName, string scope)
 {
     throw new NotImplementedException();
 }