コード例 #1
0
ファイル: TokenStringDFA.cs プロジェクト: netgrim/FleeSharp
        /**
         * Adds a string match to this automaton. New states and
         * transitions will be added to extend this automaton to
         * support the specified string.
         *
         * @param str              the string to match
         * @param caseInsensitive  the case-insensitive flag
         * @param value            the match value
         */
        public void AddMatch(string str, bool caseInsensitive, TokenPattern value) {
            DFAState  state;
            DFAState  next;
            char      c = str[0];
            int       start = 0;

            if (caseInsensitive) {
                c = Char.ToLower(c);
            }
            if (c < 128) {
                state = ascii[c];
                if (state == null) {
                    state = ascii[c] = new DFAState();
                }
                start++;
            } else {
                state = nonAscii;
            }
            for (int i = start; i < str.Length; i++) {
                next = state.tree.Find(str[i], caseInsensitive);
                if (next == null) {
                    next = new DFAState();
                    state.tree.Add(str[i], caseInsensitive, next);
                }
                state = next;
            }
            state.value = value;
        }
コード例 #2
0
        /// <summary>
        /// Adds a string match to this automaton. New states and
        /// transitions will be added to extend this automaton to
        /// support the specified string.
        /// </summary>
        /// <param name="str">The string to match</param>
        /// <param name="caseInsensitive">The case-insensitive flag</param>
        /// <param name="value">The match value</param>
        public void AddMatch(string str, bool caseInsensitive, TokenPattern value)
        {
            DFAState state;
            DFAState next;
            char     c     = str[0];
            int      start = 0;

            if (caseInsensitive)
            {
                c = char.ToLower(c);
            }

            if (c < 128)
            {
                state = this.ascii[c];
                if (state == null)
                {
                    state = this.ascii[c] = new DFAState();
                }

                start++;
            }
            else
            {
                state = this.nonAscii;
            }

            for (int i = start; i < str.Length; i++)
            {
                next = state.Tree.Find(str[i], caseInsensitive);
                if (next == null)
                {
                    next = new DFAState();
                    state.Tree.Add(str[i], caseInsensitive, next);
                }

                state = next;
            }

            // TODO: check that this is useful.
            state.Value = value;
        }
コード例 #3
0
 /**
  * Adds a transition to this tree. If the lower-case flag is
  * set, the character will be converted to lower-case before
  * being added.
  *
  * @param c              the character to transition for
  * @param lowerCase      the lower-case conversion flag
  * @param state          the state to transition to
  */
 public void Add(char c, bool lowerCase, DFAState state)
 {
     if (lowerCase)
     {
         c = Char.ToLower(c);
     }
     if (value == '\0')
     {
         this.value = c;
         this.state = state;
         this.left  = new TransitionTree();
         this.right = new TransitionTree();
     }
     else if (value > c)
     {
         left.Add(c, false, state);
     }
     else
     {
         right.Add(c, false, state);
     }
 }
コード例 #4
0
ファイル: TokenStringDFA.cs プロジェクト: netgrim/FleeSharp
 /**
  * Adds a transition to this tree. If the lower-case flag is
  * set, the character will be converted to lower-case before
  * being added.
  *
  * @param c              the character to transition for
  * @param lowerCase      the lower-case conversion flag
  * @param state          the state to transition to
  */
 public void Add(char c, bool lowerCase, DFAState state) {
     if (lowerCase) {
         c = Char.ToLower(c);
     }
     if (value == '\0') {
         this.value = c;
         this.state = state;
         this.left = new TransitionTree();
         this.right = new TransitionTree();
     } else if (value > c) {
         left.Add(c, false, state);
     } else {
         right.Add(c, false, state);
     }
 }