示例#1
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // OBJECT
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <c>SimpleLexer</c> class.
        /// </summary>
        /// <param name="caseSensitive">Whether the language is case sensitive.</param>
        public SimpleLexer(bool caseSensitive)
        {
            // This is added for demo purposes... normally a language knows whether it is case sensitive or not
            this.caseSensitive = caseSensitive;

            // Create ID providers
            this.LexicalStateIdProviderCore = new SimpleLexicalStateId();
            this.TokenIdProviderCore        = new SimpleTokenId();

            // Initialize keywords
            if (keywords.Count == 0)
            {
                for (int tokenId = this.TokenIdProviderCore.MinId; tokenId <= this.TokenIdProviderCore.MaxId; tokenId++)
                {
                    // If the token ID is in the range of keyword IDs, add it to the keywords dictionary
                    if ((tokenId >= SimpleTokenId.Function) && (tokenId <= SimpleTokenId.Var))
                    {
                        keywords.Add(this.TokenIdProviderCore.GetKey(tokenId).ToLowerInvariant(), tokenId);
                    }
                }
            }

            // Create the default lexical state
            ProgrammaticLexicalState lexicalState = new ProgrammaticLexicalState(SimpleLexicalStateId.Default, "Default");

            lexicalStates = new LexicalStateCollection(this);
            lexicalStates.Add(lexicalState);
            this.DefaultLexicalStateCore = lexicalState;
        }
示例#2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // OBJECT
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <c>ParentLexer</c> class.
        /// </summary>
        /// <param name="childLanguage">The child language.</param>
        public ParentLexer(ISyntaxLanguage childLanguage)
        {
            // Initialize lexical states
            lexicalStates = new LexicalStateCollection(this);

            ProgrammaticLexicalState defaultState = new ProgrammaticLexicalState(ParentLexicalStateId.Default, "Default");

            lexicalStates.Add(defaultState);
            this.DefaultLexicalStateCore = defaultState;

            ProgrammaticLexicalState childOutputBlockTransitionState = new ProgrammaticLexicalState(ParentLexicalStateId.ChildOutputBlock, "Child output block transition");

            childOutputBlockTransitionState.LexicalScopes.Add(new ProgrammaticLexicalScope(new ProgrammaticLexicalScopeMatch(this.IsChildOutputBlockTransitionStateScopeStart),
                                                                                           new ProgrammaticLexicalScopeMatch(this.IsChildOutputBlockTransitionStateScopeEnd)));
            lexicalStates.Add(childOutputBlockTransitionState);
            defaultState.ChildLexicalStates.Add(childOutputBlockTransitionState);

            ProgrammaticLexicalState childCodeBlockTransitionState = new ProgrammaticLexicalState(ParentLexicalStateId.ChildCodeBlock, "Child code block transition");

            childCodeBlockTransitionState.LexicalScopes.Add(new ProgrammaticLexicalScope(new ProgrammaticLexicalScopeMatch(this.IsChildCodeBlockTransitionStateScopeStart),
                                                                                         new ProgrammaticLexicalScopeMatch(this.IsChildCodeBlockTransitionStateScopeEnd)));
            lexicalStates.Add(childCodeBlockTransitionState);
            defaultState.ChildLexicalStates.Add(childCodeBlockTransitionState);

            IMergableLexer lexer = childLanguage.GetLexer() as IMergableLexer;

            if (lexer != null)
            {
                childOutputBlockTransitionState.Transition = new LexicalStateTransition(childLanguage, lexer.DefaultLexicalState, null);
                childCodeBlockTransitionState.Transition   = new LexicalStateTransition(childLanguage, lexer.DefaultLexicalState, null);
            }
        }
        public ExecutionTargetSelectorLexer()
        {
            // Create ID providers
            this.LexicalStateIdProviderCore = new ExecutionTargetSelectorLexicalStateId();
            this.TokenIdProviderCore        = new ExecutionTargetSelectorTokenId();

            // Create the default lexical state
            ProgrammaticLexicalState lexicalState = new ProgrammaticLexicalState(ExecutionTargetSelectorLexicalStateId.Default, "Default");

            lexicalStates = new LexicalStateCollection(this);
            lexicalStates.Add(lexicalState);
            this.DefaultLexicalStateCore = lexicalState;
        }