void
CBTCLStyler::Scan
	(
	std::istream&			input,
	const TokenExtra&	initData
	)
{
	BeginScan(input);

	const JString& text = GetText();

	JBoolean keepGoing;
	Token token;
	JFontStyle style;
	do
		{
		token = NextToken();
		if (token.type == kEOF)
			{
			break;
			}

		// save token starts

		if (token.type == kPredefinedWord ||
			token.type == kOtherWord ||
			token.type == kVariable ||
			token.type == kString ||
			token.type == kComment)
			{
			SaveTokenStart(TokenExtra());
			}

		// handle special cases

		if (token.type == kString ||
			token.type == kUnterminatedString)
			{
			ExtendCheckRangeForString(token.range);
			}

		// set the style

		const JIndex typeIndex = token.type - kWhitespace;
		if (token.type == kWhitespace)
			{
			style = GetDefaultFont().GetStyle();
			}
		else if (token.type == kComment       ||
				 token.type == kString        ||
				 token.type == kBrace         ||
				 token.type == kSquareBracket ||
				 token.type == kParenthesis)
			{
			style = GetTypeStyle(typeIndex);
			}
		else if (token.type < kWhitespace)
			{
			style = GetTypeStyle(kError - kWhitespace);
			}
		else
			{
			style = GetStyle(typeIndex, text.GetSubstring(token.range));
			}

		keepGoing = SetStyle(token.range, style);

		if (token.type == kString)
			{
			StyleEmbeddedVariables(token);
			}
		}
		while (keepGoing);
}
示例#2
0
void
CBHTMLStyler::Scan
	(
	istream&			input,
	const TokenExtra&	initData
	)
{
	BeginScan(input, initData.lexerState);
	itsLatestTagName.Clear();

	const JString& text = GetText();

	JBoolean keepGoing;
	Token token;
	JFontStyle style;
	do
		{
		token = NextToken();
		if (token.type == kEOF)
			{
			break;
			}

		// save token starts

		if ((yy_start_stack_ptr == 0 &&
			 (token.type == kHTMLText    ||
			  token.type == kHTMLComment ||
			  token.type == kJSPComment  ||
			  (token.type == kHTMLTag &&
			   text.GetCharacter(token.range.first) == '<'))) ||
			(yy_start_stack_ptr > 0 && yy_top_state() == 0 &&
			 (token.type == kPHPID                ||
			  token.type == kPHPVariable          ||
			  token.type == kPHPReservedKeyword   ||
			  token.type == kPHPBuiltInDataType   ||
			  token.type == kPHPSingleQuoteString ||
			  token.type == kPHPDoubleQuoteString ||
			  token.type == kPHPHereDocString     ||
			  token.type == kPHPExecString        ||
			  token.type == kJavaID               ||
			  token.type == kJavaReservedKeyword  ||
			  token.type == kJavaBuiltInDataType  ||
			  token.type == kJavaString           ||
			  token.type == kJSID                 ||
			  token.type == kJSReservedKeyword    ||
			  token.type == kComment)))
			{
			TokenExtra data;
			data.lexerState = GetCurrentLexerState();
			SaveTokenStart(data);

//			const JString s = text.GetSubstring(token.range);
//			cout << yy_top_state() << ' ' << yy_start_stack_ptr << ": " << s << endl;
			}

		// handle special cases

		if (token.type == kPHPDoubleQuoteString ||
			token.type == kPHPExecString)
			{
			ExtendCheckRangeForString(token.range);
			}
		else if (token.type == kPHPStartEnd)
			{
			ExtendCheckRangeForPHPStartEnd(token.range);
			}
		else if (token.type == kJSPStartEnd)
			{
			ExtendCheckRangeForJSPStartEnd(token.range);
			}

		// set the style

		const JIndex typeIndex = token.type - kWhitespace;
		if (token.type == kWhitespace)
			{
			style = GetDefaultFontStyle();
			}
		else if ((token.type == kHTMLNamedCharacter ||
				  token.type == kHTMLInvalidNamedCharacter) &&
				 GetCurrentLexerState() != 0)
			{
			style = GetStyle(kHTMLTag - kWhitespace, itsLatestTagName);
			if (token.type == kHTMLInvalidNamedCharacter)
				{
				style.strike = !style.strike;
				}
			else
				{
				style.underlineCount++;
				}
			}
		else if (token.type == kHTMLText             ||
				 token.type == kHTMLComment          ||
				 token.type == kCDATABlock           ||
				 token.type == kMustacheCommand      ||
				 token.type == kPHPStartEnd          ||
				 token.type == kPHPSingleQuoteString ||
				 token.type == kPHPDoubleQuoteString ||
				 token.type == kPHPHereDocString     ||
				 token.type == kPHPExecString        ||
				 token.type == kJSPStartEnd          ||
				 token.type == kJSPComment           ||
				 token.type == kJavaString           ||
				 token.type == kJSString             ||
				 token.type == kJSRegexSearch        ||
				 token.type == kComment)
			{
			style = GetTypeStyle(typeIndex);
			}
		else if (token.type < kWhitespace)
			{
			style = GetTypeStyle(kError - kWhitespace);
			}
		else if (token.type == kHTMLTag)
			{
			style = GetTagStyle(token.range, typeIndex);
			}
		else if (token.type == kHTMLScript)
			{
			style = GetStyle(typeIndex, *(token.language));
			}
		else if (token.type == kHTMLNamedCharacter)
			{
			JIndexRange r = token.range;
			r.first++;
			if (text.GetCharacter(r.last) == ';')
				{
				r.last--;
				}
			style = GetStyle(typeIndex, text.GetSubstring(r));
			}
		else
			{
			if (token.type == kDocCommentHTMLTag ||
				token.type == kDocCommentSpecialTag)
				{
				if (!(token.docCommentRange).IsEmpty())
					{
					SetStyle(token.docCommentRange, GetTypeStyle(kComment - kWhitespace));
					}
				ExtendCheckRange(token.range.last+1);
				}

			style = GetStyle(typeIndex, text.GetSubstring(token.range));
			}

		keepGoing = SetStyle(token.range, style);

		if (token.type == kPHPDoubleQuoteString ||
			token.type == kPHPHereDocString     ||
			token.type == kPHPExecString)
			{
			StyleEmbeddedVariables(token);
			}
		}
		while (keepGoing);
}
void
CBCShellStyler::Scan
(
    istream&			input,
    const TokenExtra&	initData
)
{
    BeginScan(input);

    const JString& text = GetText();

    JBoolean keepGoing;
    Token token;
    JFontStyle style;
    do
    {
        token = NextToken();
        if (token.type == kEOF)
        {
            break;
        }

        // save token starts

        if (token.type == kID                ||
                token.type == kVariable          ||
                token.type == kReservedWord      ||
                token.type == kSingleQuoteString ||
                token.type == kDoubleQuoteString ||
                token.type == kExecString        ||
                token.type == kComment)
        {
            SaveTokenStart(TokenExtra());
        }

        // handle special cases

        if (token.type == kDoubleQuoteString ||
                token.type == kExecString)
        {
            ExtendCheckRangeForString(token.range);
        }

        // set the style

        const JIndex typeIndex = token.type - kWhitespace;
        if (token.type == kWhitespace)
        {
            style = GetDefaultFontStyle();
        }
        else if (token.type == kSingleQuoteString ||
                 token.type == kDoubleQuoteString ||
                 token.type == kExecString        ||
                 token.type == kComment)
        {
            style = GetTypeStyle(typeIndex);
        }
        else if (token.type < kWhitespace)
        {
            style = GetTypeStyle(kError - kWhitespace);
        }
        else if (token.type > kError)	// misc
        {
            if (!GetWordStyle(text.GetSubstring(token.range), &style))
            {
                style = GetDefaultFontStyle();
            }
        }
        else
        {
            style = GetStyle(typeIndex, text.GetSubstring(token.range));
        }

        keepGoing = SetStyle(token.range, style);

        if (token.type == kDoubleQuoteString ||
                token.type == kExecString)
        {
            StyleEmbeddedVariables(token);
        }
    }
    while (keepGoing);
}