예제 #1
0
파일: Parser.cs 프로젝트: sboriskin287/sku
 public SympleParser()
 {
     b_Brackets          = false;
     elements            = new SympleElement[0];
     CurrentState        = state.START;
     brackets            = new SympleElement();
     brackets.StartIndex = -1;
     brackets.EndIndex   = -1;
 }
예제 #2
0
파일: Parser.cs 프로젝트: sboriskin287/sku
        public parceResult Start(String Input)
        {
            elements       = new SympleElement[0];
            CurrentState   = state.START;
            currentElement = -1;
            str            = Input.ToLower();

            for (int i = 0; i < str.Length; i++)
            {
                switch (CurrentState)
                {
                case state.START: if (str[i] == '#')
                    {
                        Array.Resize(ref elements,elements.Length + 1);
                        currentElement++;
                        elements[currentElement]            = new SympleElement();
                        elements[currentElement].StartIndex = i;
                        CurrentState = state.COMMENT;
                    }
                    else if (Regex.IsMatch(str[i].ToString(),"[a-z]"))
                    {
                        Array.Resize(ref elements,elements.Length + 1);
                        currentElement++;
                        elements[currentElement]            = new SympleElement();
                        elements[currentElement].StartIndex = i;
                        CurrentState = state.SIGNAL;
                    }
                    else if (str[i] == '(')
                    {
                        Array.Resize(ref elements,elements.Length + 1);
                        currentElement++;
                        elements[currentElement]            = new SympleElement();
                        elements[currentElement].StartIndex = i;
                        elements[currentElement].EndIndex   = i;
                        elements[currentElement].Style      = System.Drawing.FontStyle.Bold;
                        CurrentState = state.START;
                    }
                    else if (str[i] == ')')
                    {
                        Array.Resize(ref elements,elements.Length + 1);
                        currentElement++;
                        elements[currentElement]            = new SympleElement();
                        elements[currentElement].StartIndex = i;
                        elements[currentElement].EndIndex   = i;
                        elements[currentElement].Style      = System.Drawing.FontStyle.Bold;
                        CurrentState = state.START;
                    }
                    else if (str[i] == '[')
                    {
                        Array.Resize(ref elements,elements.Length + 1);
                        currentElement++;
                        elements[currentElement]            = new SympleElement();
                        elements[currentElement].StartIndex = i;
                        CurrentState = state.OPT;
                    }
                    break;

                case state.COMMENT: if (str[i] == '#')
                    {
                        elements[currentElement].EndIndex  = i;
                        elements[currentElement].TextColor = Settings.Default.TextFieldCommentColor;
                        elements[currentElement].Style     = 0;
                        CurrentState = state.START;
                    }
                    break;

                case state.OPT: if (str[i] == ']')
                    {
                        elements[currentElement].EndIndex  = i;
                        elements[currentElement].TextColor = Settings.Default.TextFieldOptionColor;
                        elements[currentElement].Style     = 0;
                        CurrentState = state.START;
                    }
                    break;

                case state.SIGNAL: if (str[i] != ';' && str[i] != '(' && str[i] != ')' && str[i] != '&' && str[i] != '|' && str[i] != '~' && str[i] != '#' && str[i] != '=')
                    {
                        break;
                    }
                    else
                    {
                        elements[currentElement].EndIndex = i - 1;
                        if (str.Substring(elements[currentElement].StartIndex,elements[currentElement].EndIndex - elements[currentElement].StartIndex + 1) == "t+1")
                        {
                            elements[currentElement].TextColor = System.Drawing.Color.Red;
                            elements[currentElement].Style     = 0;
                        }
                        else
                        {
                            elements[currentElement].TextColor = Settings.Default.TextFieldSignalColor;
                            elements[currentElement].Style     = 0;
                        }
                        if (str[i] == '#')
                        {
                            Array.Resize(ref elements,elements.Length + 1);
                            currentElement++;
                            elements[currentElement]            = new SympleElement();
                            elements[currentElement].StartIndex = i;
                            CurrentState = state.COMMENT;
                        }

                        if (str[i] == '(')
                        {
                            Array.Resize(ref elements,elements.Length + 1);
                            currentElement++;
                            elements[currentElement]            = new SympleElement();
                            elements[currentElement].StartIndex = i;
                            elements[currentElement].EndIndex   = i;
                            elements[currentElement].Style      = System.Drawing.FontStyle.Bold;
                            CurrentState = state.START;
                        }
                        if (str[i] == ')')
                        {
                            Array.Resize(ref elements,elements.Length + 1);
                            currentElement++;
                            elements[currentElement]            = new SympleElement();
                            elements[currentElement].StartIndex = i;
                            elements[currentElement].EndIndex   = i;
                            elements[currentElement].Style      = System.Drawing.FontStyle.Bold;
                            CurrentState = state.START;
                        }

                        CurrentState = state.START;
                    }
                    break;
                }
            }

            return(parceResult.PARSE_OK);
        }
예제 #3
0
        public parceResult Start(String Input)
        {
            elements       = new SympleElement[0];
            CurrentState   = state.H;
            currentElement = -1;
            str            = Input.ToLower();

            for (int i = 0; i < str.Length; i++)
            {
                switch (CurrentState)
                {
                case state.H: if (str[i] == '#')
                    {
                        Array.Resize(ref elements,elements.Length + 1);
                        currentElement++;
                        elements[currentElement]            = new SympleElement();
                        elements[currentElement].StartIndex = i;
                        CurrentState = state.COMMENT;
                    }
                    else if (str[i] == 'a' || str[i] == 'b' || str[i] == 'c' || str[i] == 'd' || str[i] == 'e' || str[i] == 'f' || str[i] == 'g' || str[i] == 'h' || str[i] == 'i' || str[i] == 'j' || str[i] == 'k' || str[i] == 'l' || str[i] == 'm' || str[i] == 'n' || str[i] == 'o' || str[i] == 'p' || str[i] == 'q' || str[i] == 'r' || str[i] == 's' || str[i] == 't' || str[i] == 'u' || str[i] == 'v' || str[i] == 'w' || str[i] == 'x' || str[i] == 'y' || str[i] == 'z')
                    {
                        Array.Resize(ref elements,elements.Length + 1);
                        currentElement++;
                        elements[currentElement]            = new SympleElement();
                        elements[currentElement].StartIndex = i;
                        CurrentState = state.SIGNAL;
                    }
                    break;

                case state.COMMENT: if (str[i] == '#')
                    {
                        elements[currentElement].EndIndex  = i;
                        elements[currentElement].TextColor = Settings.Default.TextFieldCommentColor;
                        CurrentState = state.H;
                    }
                    break;

                case state.SIGNAL: if (str[i] != ';' && str[i] != '(' && str[i] != ')' && str[i] != '&' && str[i] != '|' && str[i] != '~' && str[i] != '#')
                    {
                    }
                    else
                    {
                        elements[currentElement].EndIndex = i - 1;
                        if (str.Substring(elements[currentElement].StartIndex,elements[currentElement].EndIndex - elements[currentElement].StartIndex + 1) == "t+1")
                        {
                            elements[currentElement].TextColor = System.Drawing.Color.Red;
                        }
                        else
                        {
                            elements[currentElement].TextColor = Settings.Default.TextFieldSignalColor;
                        }
                        if (str[i] == '#')
                        {
                            Array.Resize(ref elements,elements.Length + 1);
                            currentElement++;
                            elements[currentElement]            = new SympleElement();
                            elements[currentElement].StartIndex = i;
                            CurrentState = state.COMMENT;
                        }
                        CurrentState = state.H;
                    }
                    break;
                }
            }

            return(parceResult.PARSE_OK);
        }