Ejemplo n.º 1
0
        private LexToken parseBlockComment(LexToken token, string strBeginComment, string strEndComment)
        {
            token.setType(LexTokenTypes.COMMENT_BLOCK);
            StringBuilder stringBuilder = new StringBuilder();
            int           length        = strEndComment.Length;
            int           num           = strBeginComment.Length + strEndComment.Length;
            bool          flag          = false;

            while (base.current() != '\0')
            {
                if (stringBuilder.Length >= num && base.getPrevString(length).Equals(strEndComment))
                {
                    flag = true;
                    break;
                }
                stringBuilder.Append(base.current());
                base.next();
            }
            if (!flag)
            {
                this.throwException(token, "无法找到对应的结束的注释标记" + strBeginComment + "..." + strEndComment);
            }
            token.setPrefix(strBeginComment);
            token.setToken(stringBuilder.ToString().Substring(strBeginComment.Length, stringBuilder.Length - strEndComment.Length));
            token.setSuffix(strEndComment);
            return(token);
        }
Ejemplo n.º 2
0
        private LexToken parseString(bool isMulti, LexToken token)
        {
            char c = base.current();

            if (isMulti)
            {
                c = base.next();
            }
            char c2 = (c == '"') ? '"' : '\'';

            token.setType((c == '"') ? LexTokenTypes.STRING_QUOTED : LexTokenTypes.STRING);
            string text = "";

            base.next();
            char c3 = '\0';
            char c4 = '\0';

            while (base.current() != '\0')
            {
                if (base.current() == c2)
                {
                    if (c3 != '\\')
                    {
                        break;
                    }
                }
                char c5 = base.current();
                if (c5 == '\n')
                {
                    if (!isMulti && this.m_LexTokenizerConfig.getMultiLineStringSuffix() != '\0')
                    {
                        if (c4 == '\0' || c4 != this.m_LexTokenizerConfig.getMultiLineStringSuffix())
                        {
                            this.throwException("", "不能在字符串中包含回车!");
                        }
                        int num = text.LastIndexOf(this.m_LexTokenizerConfig.getMultiLineStringSuffix());
                        if (num >= 0)
                        {
                            text = text.Substring(0, num);
                        }
                    }
                    else if (!isMulti)
                    {
                        this.throwException("", "不能在字符串中包含回车!");
                    }
                    c4 = '\0';
                }
                text += c5;
                c3    = c5;
                if (!char.IsWhiteSpace(c5))
                {
                    c4 = c5;
                }
                base.next();
            }
            if (base.current() != c2)
            {
                this.throwException(token, "不能匹配字符串的开始标志和结束标志!");
            }
            if (isMulti)
            {
                token.setPrefix(this.m_LexTokenizerConfig.getMultiLineStringPrefix() + c + "");
            }
            else
            {
                token.setPrefix(string.Concat(c));
            }
            token.setSuffix(string.Concat(c2));
            token.setToken(text);
            base.next();
            return(token);
        }