Example #1
0
        /// <summary>
        /// Initializes a new instance of the <c>JsonTokenTagger</c> class.
        /// </summary>
        /// <param name="document">The specific <see cref="ICodeDocument"/> for which this token tagger will be used.</param>
        /// <param name="classificationTypeProvider">A <see cref="IJsonClassificationTypeProvider"/> that provides classification types used by this token tagger.</param>
        public JsonTokenTagger(ICodeDocument document, IJsonClassificationTypeProvider classificationTypeProvider) : base(document)
        {
            if ((classificationTypeProvider == null))
                throw new ArgumentNullException("classificationTypeProvider");

            // Initialize
            classificationTypeProviderValue = classificationTypeProvider;
        }
        /// <summary>
        /// Initializes a new instance of the <c>JsonTokenTaggerProvider</c> class.
        /// </summary>
        /// <param name="classificationTypeProvider">A <see cref="IJsonClassificationTypeProvider"/> that provides classification types.</param>
        public JsonTokenTaggerProvider(IJsonClassificationTypeProvider classificationTypeProvider)
        {
            if ((classificationTypeProvider == null))
            {
                throw new ArgumentNullException("classificationTypeProvider");
            }

            // Initialize
            classificationTypeProviderValue = classificationTypeProvider;
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <c>JsonLexer</c> class.
        /// </summary>
        /// <param name="classificationTypeProvider">A <see cref="IJsonClassificationTypeProvider"/> that provides classification types used by this lexer.</param>
        public JsonLexer(IJsonClassificationTypeProvider classificationTypeProvider)
        {
            if ((classificationTypeProvider == null))
            {
                throw new ArgumentNullException("classificationTypeProvider");
            }

            // Create lexical states
            IKeyedObservableCollection <DynamicLexicalState> lexicalStates = ((IKeyedObservableCollection <DynamicLexicalState>)(this.LexicalStates));

            this.DefaultLexicalState.Id = JsonLexicalStateId.Default;
            lexicalStates.Add(new DynamicLexicalState(JsonLexicalStateId.PrimaryString, "PrimaryString"));

            DynamicLexicalState        lexicalState        = null;
            DynamicLexicalScope        lexicalScope        = null;
            DynamicLexicalPatternGroup lexicalPatternGroup = null;

            // Initialize the Default lexical state
            lexicalState = lexicalStates["Default"];
            lexicalState.ChildLexicalStates.Add(lexicalStates["PrimaryString"]);
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "Whitespace", null);
            lexicalPatternGroup.TokenId = JsonTokenId.Whitespace;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("{LineTerminatorWhitespace}+"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "Comma", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.Comma;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(","));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "Colon", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.Colon;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(":"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "OpenCurlyBrace", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.OpenCurlyBrace;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("{"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "CloseCurlyBrace", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.CloseCurlyBrace;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("}"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "OpenSquareBrace", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.OpenSquareBrace;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("["));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "CloseSquareBrace", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.CloseSquareBrace;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("]"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup                 = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "True", classificationTypeProvider.Keyword);
            lexicalPatternGroup.TokenId         = JsonTokenId.True;
            lexicalPatternGroup.CaseSensitivity = CaseSensitivity.AutoCorrect;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("true"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup                 = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "False", classificationTypeProvider.Keyword);
            lexicalPatternGroup.TokenId         = JsonTokenId.False;
            lexicalPatternGroup.CaseSensitivity = CaseSensitivity.AutoCorrect;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("false"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup                 = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "Null", classificationTypeProvider.Keyword);
            lexicalPatternGroup.TokenId         = JsonTokenId.Null;
            lexicalPatternGroup.CaseSensitivity = CaseSensitivity.AutoCorrect;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("null"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup                  = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "Number", classificationTypeProvider.Number);
            lexicalPatternGroup.TokenId          = JsonTokenId.Number;
            lexicalPatternGroup.LookAheadPattern = "{NonWord}|\\z";
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[\\+\\-]?{Digit}* \\. {Digit}+ ([Ee] [\\+\\-]? {Digit}+)?"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[\\+\\-]?{Digit}+ [Ee] [\\+\\-]? {Digit}+"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[\\+\\-]?{Digit}+"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);

            // Initialize the PrimaryString lexical state
            lexicalState = lexicalStates["PrimaryString"];
            lexicalState.DefaultClassificationType = classificationTypeProvider.String;
            lexicalState.DefaultTokenId            = JsonTokenId.PrimaryStringText;
            lexicalState.DefaultTokenKey           = "PrimaryStringText";
            lexicalScope = new DynamicLexicalScope();
            lexicalState.LexicalScopes.Add(lexicalScope);
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "StringStartDelimiter", null);
            lexicalPatternGroup.TokenId = JsonTokenId.StringStartDelimiter;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\""));
            lexicalScope.StartLexicalPatternGroup = lexicalPatternGroup;
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "StringEndDelimiter", null);
            lexicalPatternGroup.TokenId = JsonTokenId.StringEndDelimiter;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\""));
            lexicalScope.EndLexicalPatternGroup = lexicalPatternGroup;
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "EscapedCharacter", null);
            lexicalPatternGroup.TokenId = JsonTokenId.EscapedCharacter;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\\""));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\\\"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\/"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\b"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\f"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\n"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\r"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\t"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "EscapedUnicode", null);
            lexicalPatternGroup.TokenId = JsonTokenId.EscapedUnicode;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\\\u[0-9a-fA-F]{4}"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup         = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "StringText", null);
            lexicalPatternGroup.TokenId = JsonTokenId.StringText;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[^\\\"\\\\\\n]+"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <c>JsonLexer</c> class.
        /// </summary>
        /// <param name="classificationTypeProvider">A <see cref="IJsonClassificationTypeProvider"/> that provides classification types used by this lexer.</param>
        public JsonLexer(IJsonClassificationTypeProvider classificationTypeProvider) {
            if ((classificationTypeProvider == null)) {
                throw new ArgumentNullException("classificationTypeProvider");
            }

            // Create lexical states
            IKeyedObservableCollection<DynamicLexicalState> lexicalStates = ((IKeyedObservableCollection<DynamicLexicalState>)(this.LexicalStates));
            this.DefaultLexicalState.Id = JsonLexicalStateId.Default;
            lexicalStates.Add(new DynamicLexicalState(JsonLexicalStateId.PrimaryString, "PrimaryString"));

            DynamicLexicalState lexicalState = null;
            DynamicLexicalScope lexicalScope = null;
            DynamicLexicalPatternGroup lexicalPatternGroup = null;

            // Initialize the Default lexical state
            lexicalState = lexicalStates["Default"];
            lexicalState.ChildLexicalStates.Add(lexicalStates["PrimaryString"]);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "Whitespace", null);
            lexicalPatternGroup.TokenId = JsonTokenId.Whitespace;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("{LineTerminatorWhitespace}+"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "Comma", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.Comma;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(","));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "Colon", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.Colon;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern(":"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "OpenCurlyBrace", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.OpenCurlyBrace;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("{"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "CloseCurlyBrace", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.CloseCurlyBrace;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("}"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "OpenSquareBrace", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.OpenSquareBrace;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("["));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "CloseSquareBrace", classificationTypeProvider.Delimiter);
            lexicalPatternGroup.TokenId = JsonTokenId.CloseSquareBrace;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("]"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "True", classificationTypeProvider.Keyword);
            lexicalPatternGroup.TokenId = JsonTokenId.True;
            lexicalPatternGroup.CaseSensitivity = CaseSensitivity.AutoCorrect;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("true"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "False", classificationTypeProvider.Keyword);
            lexicalPatternGroup.TokenId = JsonTokenId.False;
            lexicalPatternGroup.CaseSensitivity = CaseSensitivity.AutoCorrect;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("false"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "Null", classificationTypeProvider.Keyword);
            lexicalPatternGroup.TokenId = JsonTokenId.Null;
            lexicalPatternGroup.CaseSensitivity = CaseSensitivity.AutoCorrect;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("null"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "Number", classificationTypeProvider.Number);
            lexicalPatternGroup.TokenId = JsonTokenId.Number;
            lexicalPatternGroup.LookAheadPattern = "{NonWord}|\\z";
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[\\+\\-]?{Digit}* \\. {Digit}+ ([Ee] [\\+\\-]? {Digit}+)?"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[\\+\\-]?{Digit}+ [Ee] [\\+\\-]? {Digit}+"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[\\+\\-]?{Digit}+"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);

            // Initialize the PrimaryString lexical state
            lexicalState = lexicalStates["PrimaryString"];
            lexicalState.DefaultClassificationType = classificationTypeProvider.String;
            lexicalState.DefaultTokenId = JsonTokenId.PrimaryStringText;
            lexicalState.DefaultTokenKey = "PrimaryStringText";
            lexicalScope = new DynamicLexicalScope();
            lexicalState.LexicalScopes.Add(lexicalScope);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "StringStartDelimiter", null);
            lexicalPatternGroup.TokenId = JsonTokenId.StringStartDelimiter;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\""));
            lexicalScope.StartLexicalPatternGroup = lexicalPatternGroup;
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "StringEndDelimiter", null);
            lexicalPatternGroup.TokenId = JsonTokenId.StringEndDelimiter;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\""));
            lexicalScope.EndLexicalPatternGroup = lexicalPatternGroup;
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Explicit, "EscapedCharacter", null);
            lexicalPatternGroup.TokenId = JsonTokenId.EscapedCharacter;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\\""));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\\\"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\/"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\b"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\f"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\n"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\r"));
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\t"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "EscapedUnicode", null);
            lexicalPatternGroup.TokenId = JsonTokenId.EscapedUnicode;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("\\\\u[0-9a-fA-F]{4}"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
            lexicalPatternGroup = new DynamicLexicalPatternGroup(DynamicLexicalPatternType.Regex, "StringText", null);
            lexicalPatternGroup.TokenId = JsonTokenId.StringText;
            lexicalPatternGroup.Patterns.Add(new DynamicLexicalPattern("[^\\\"\\\\\\n]+"));
            lexicalState.LexicalPatternGroups.Add(lexicalPatternGroup);
        }