コード例 #1
0
        public bool Store(LexemType type, string content)
        {
            char       character;
            LexemState state;

            if (content.Length > 0)
            {
                character = content[0];

                if (!this.branches.TryGetValue(character, out state))
                {
                    state = new LexemState();

                    this.branches[character] = state;
                }

                return(state.Store(type, content.Substring(1)));
            }
            else if (this.type == LexemType.None)
            {
                this.type = type;

                return(true);
            }

            return(false);
        }
コード例 #2
0
ファイル: LexemState.cs プロジェクト: omarisai/cottle
        public bool Store(LexemType type, string content)
        {
            LexemState current;
            LexemState next;

            current = this;

            foreach (char character in content)
            {
                if (current.branches == null)
                {
                    current.branches = new Dictionary <char, LexemState> ();
                }

                if (!current.branches.TryGetValue(character, out next))
                {
                    next = new LexemState();

                    current.branches[character] = next;
                }

                current = next;
            }

            if (current.type != LexemType.None)
            {
                return(false);
            }

            current.type = type;

            return(true);
        }
コード例 #3
0
ファイル: LexemState.cs プロジェクト: r3c/cottle
        public bool Store(LexemType type, string content)
        {
            char		character;
            LexemState	state;

            if (content.Length > 0)
            {
                character = content[0];

                if (!this.branches.TryGetValue (character, out state))
                {
                    state = new LexemState ();

                    this.branches[character] = state;
                }

                return state.Store (type, content.Substring (1));
            }
            else if (this.type == LexemType.None)
            {
                this.type = type;

                return true;
            }

            return false;
        }
コード例 #4
0
ファイル: LexemState.cs プロジェクト: pierotibou/cottle
        public bool Store(LexemType type, string content)
        {
            LexemState current;
            LexemState next;

            current = this;

            foreach (char character in content)
            {
                if (character < LexemState.BRANCH_LIMIT)
                {
                    if (current.branchesLow == null)
                    {
                        current.branchesLow = new LexemState[LexemState.BRANCH_LIMIT];
                    }

                    next = current.branchesLow[character];

                    if (next == null)
                    {
                        next = new LexemState();

                        current.branchesLow[character] = next;
                    }
                }
                else
                {
                    if (current.branchesHigh == null)
                    {
                        current.branchesHigh = new Dictionary <char, LexemState> ();
                    }

                    if (!current.branchesHigh.TryGetValue(character, out next))
                    {
                        next = new LexemState();

                        current.branchesHigh[character] = next;
                    }
                }

                current = next;
            }

            if (current.type != LexemType.None)
            {
                return(false);
            }

            current.type = type;

            return(true);
        }
コード例 #5
0
ファイル: Lexer.cs プロジェクト: r3c/cottle
        public Lexer(string blockBegin, string blockContinue, string blockEnd, char escape)
        {
            this.cursors = new Queue<LexemCursor> ();
            this.escape = escape;
            this.pending = new Queue<char> ();
            this.root = new LexemState ();

            if (!this.root.Store (LexemType.BlockBegin, blockBegin))
                throw new ConfigException ("blockBegin", blockBegin, "block delimiter used twice");

            if (!this.root.Store (LexemType.BlockContinue, blockContinue))
                throw new ConfigException ("blockContinue", blockContinue, "block delimiter used twice");

            if (!this.root.Store (LexemType.BlockEnd, blockEnd))
                throw new ConfigException ("blockEnd", blockEnd, "block delimiter used twice");
        }
コード例 #6
0
        public Lexer(string blockBegin, string blockContinue, string blockEnd, char escape)
        {
            this.cursors = new List <LexemCursor> ();
            this.escape  = escape;
            this.pending = new Queue <char> ();
            this.root    = new LexemState();

            if (!this.root.Store(LexemType.BlockBegin, blockBegin))
            {
                throw new ConfigException("blockBegin", blockBegin, "block delimiter used twice");
            }

            if (!this.root.Store(LexemType.BlockContinue, blockContinue))
            {
                throw new ConfigException("blockContinue", blockContinue, "block delimiter used twice");
            }

            if (!this.root.Store(LexemType.BlockEnd, blockEnd))
            {
                throw new ConfigException("blockEnd", blockEnd, "block delimiter used twice");
            }
        }