Пример #1
0
        public bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state)
        {
            if (this.currentLine == null) return false;
            this.currentState = (OsloCodeGeneratorScannerState)state;
            if (this.currentOffset >= this.currentLine.Length)
            {
                if (this.currentState == OsloCodeGeneratorScannerState.InTemplateCommand)
                {
                    this.currentState = OsloCodeGeneratorScannerState.InTemplateOutput;
                }
                if (this.currentState == OsloCodeGeneratorScannerState.None && this.enterTemplateOutputMode)
                {
                    this.currentState = OsloCodeGeneratorScannerState.InTemplateOutput;
                    this.enterTemplateOutputMode = false;
                }
                state = (int)this.currentState;
                return false;
            }

            this.currentState = (OsloCodeGeneratorScannerState)state;

            if (this.currentOffset == 0)
            {
                if (this.currentState == OsloCodeGeneratorScannerState.InTemplateCommand)
                {
                    this.currentState = OsloCodeGeneratorScannerState.InTemplateOutput;
                }
            }
            int oldOffset = this.currentOffset;
            if (tokenInfo != null)
            {
                tokenInfo.StartIndex = this.currentOffset;
            }

            if (this.currentState == OsloCodeGeneratorScannerState.None ||
                this.currentState == OsloCodeGeneratorScannerState.InComment)
            {
                if (this.ProcessComment(tokenInfo))
                {
                    state = (int)this.currentState;
                    return true;
                }
            }
            if (this.currentState == OsloCodeGeneratorScannerState.None)
            {
                if (this.ProcessLineComment(tokenInfo))
                {
                    state = (int)this.currentState;
                    return true;
                }
            }
            if (this.currentState == OsloCodeGeneratorScannerState.None ||
                this.currentState == OsloCodeGeneratorScannerState.InTemplateCommand)
            {
                if (this.ProcessKeyword(tokenInfo))
                {
                    state = (int)this.currentState;
                    return true;
                }
                if (this.ProcessStringLiteral(tokenInfo))
                {
                    state = (int)this.currentState;
                    return true;
                }
                if (this.ProcessIdentifier(tokenInfo))
                {
                    state = (int)this.currentState;
                    return true;
                }
                if (this.ProcessNumber(tokenInfo))
                {
                    state = (int)this.currentState;
                    return true;
                }
                if (this.ProcessDelimiter(tokenInfo))
                {
                    state = (int)this.currentState;
                    return true;
                }
            }
            if (this.ProcessWhitespace(tokenInfo))
            {
                state = (int)this.currentState;
                return true;
            }
            if (this.currentState == OsloCodeGeneratorScannerState.InTemplateOutput)
            {
                if (this.ProcessTemplateOutput(tokenInfo))
                {
                    state = (int)this.currentState;
                    return true;
                }
            }

            if (this.currentOffset == oldOffset)
            {
                System.Windows.Forms.MessageBox.Show("Error!");
            }

            return false;
        }
Пример #2
0
 public OsloCodeGeneratorScanner()
 {
     this.currentState = OsloCodeGeneratorScannerState.None;
 }
Пример #3
0
 private bool ProcessDelimiter(TokenInfo tokenInfo)
 {
     int length = 0;
     string text = this.currentLine.Substring(this.currentOffset);
     if (text.Length > 0)
     {
         if (text[0] == '[')
         {
             ++this.bracketCount;
         }
         if (text[0] == ']')
         {
             --this.bracketCount;
             if (this.bracketCount < 0 && this.currentState == OsloCodeGeneratorScannerState.InTemplateCommand)
             {
                 this.currentState = OsloCodeGeneratorScannerState.InTemplateOutput;
             }
         }
         length = 1;
     }
     if (length > 0)
     {
         this.currentOffset += length;
         if (tokenInfo != null)
         {
             tokenInfo.EndIndex = this.currentOffset - 1;
             if (this.currentState == OsloCodeGeneratorScannerState.None ||
                 this.currentState == OsloCodeGeneratorScannerState.InTemplateCommand)
             {
                 tokenInfo.Color = (TokenColor)OsloTokenColor.Text;
                 tokenInfo.Type = TokenType.Delimiter;
             }
             else
             {
                 tokenInfo.Color = (TokenColor)OsloTokenColor.TemplateText;
                 tokenInfo.Type = TokenType.Text;
             }
         }
         return true;
     }
     return false;
 }
Пример #4
0
 private bool ProcessTemplateOutput(TokenInfo tokenInfo)
 {
     if (this.currentLine == "end template")
     {
         this.currentState = OsloCodeGeneratorScannerState.None;
         this.currentOffset += this.currentLine.Length;
         if (tokenInfo != null)
         {
             tokenInfo.EndIndex = this.currentOffset - 1;
             tokenInfo.Color = (TokenColor)OsloTokenColor.Keyword;
             tokenInfo.Type = TokenType.Keyword;
         }
         return true;
     }
     int length = 0;
     string text = this.currentLine.Substring(this.currentOffset);
     if (text.Length > 0)
     {
         int pos = text.IndexOf('[');
         if (pos >= 0)
         {
             length = pos + 1;
             this.currentState = OsloCodeGeneratorScannerState.InTemplateCommand;
             this.bracketCount = 0;
         }
         else
         {
             length = text.Length;
         }
     }
     if (length > 0)
     {
         this.currentOffset += length;
         if (tokenInfo != null)
         {
             tokenInfo.EndIndex = this.currentOffset - 1;
             tokenInfo.Color = (TokenColor)OsloTokenColor.TemplateText;
             tokenInfo.Type = TokenType.Text;
         }
         return true;
     }
     return false;
 }
Пример #5
0
 private bool ProcessComment(TokenInfo tokenInfo)
 {
     int length = 0;
     string text = this.currentLine.Substring(this.currentOffset);
     if (this.currentState == OsloCodeGeneratorScannerState.InComment)
     {
         int pos = text.IndexOf("*/");
         if (pos >= 0)
         {
             length = pos + 2;
             this.currentState = OsloCodeGeneratorScannerState.None;
         }
         else
         {
             length = text.Length;
             this.currentState = OsloCodeGeneratorScannerState.InComment;
         }
     }
     else
     {
         if (text.StartsWith("/*"))
         {
             int pos = text.Substring(2).IndexOf("*/");
             if (pos >= 0)
             {
                 length = pos + 4;
             }
             else
             {
                 length = text.Length;
                 this.currentState = OsloCodeGeneratorScannerState.InComment;
             }
         }
     }
     if (length > 0)
     {
         this.currentOffset += length;
         if (tokenInfo != null)
         {
             tokenInfo.EndIndex = this.currentOffset - 1;
             tokenInfo.Color = (TokenColor)OsloTokenColor.Comment;
             tokenInfo.Type = TokenType.Comment;
         }
         return true;
     }
     return false;
 }