示例#1
0
JFontStyle
CBHTMLStyler::GetTagStyle
	(
	const JIndexRange&	tokenRange,
	const JIndex		typeIndex
	)
{
	const JString& text = GetText();

	JFontStyle style;
	JArray<JIndexRange> matchList;
	if (tagNamePattern.MatchWithin(text, tokenRange, &matchList))
		{
		itsLatestTagName = text.GetSubstring(matchList.GetElement(2));
		itsLatestTagName.ToLower();

		JString openTag;
		if (itsLatestTagName.GetFirstCharacter() == '/' &&
			itsLatestTagName.GetLength() > 1)
			{
			openTag = itsLatestTagName.GetSubstring(2, itsLatestTagName.GetLength());
			}

		JBoolean found = GetWordStyle(itsLatestTagName, &style);
		if (!found && !openTag.IsEmpty())
			{
			found = GetWordStyle(openTag, &style);
			}

		if (!found)
			{
			found = GetXMLStyle(itsLatestTagName, &style);
			}

		if (!found && !openTag.IsEmpty())
			{
			found = GetXMLStyle(openTag, &style);
			}

		if (!found)
			{
			style = GetTypeStyle(typeIndex);
			}
		}
	else if (text.GetCharacter(tokenRange.first) == '<')
		{
		itsLatestTagName.Clear();
		style = GetTypeStyle(typeIndex);
		}
	else
		{
		style = GetStyle(typeIndex, itsLatestTagName);
		}

	return style;
}
示例#2
0
JBoolean
CBHTMLStyler::GetXMLStyle
	(
	const JString&	tagName,
	JFontStyle*		style
	)
{
	JIndex i;
	if (!tagName.LocateLastSubstring(":", &i))
		{
		return kJFalse;
		}

	// tag name takes priority over XML namespaces

	JString s;
	if (i < tagName.GetLength())
		{
		s = tagName.GetSubstring(i+1, tagName.GetLength());
		if (GetWordStyle(s, style))
			{
			itsLatestTagName = s;
			return kJTrue;
			}
		}

	do
		{
		s = tagName.GetSubstring(1, i);
		if (GetWordStyle(s, style))
			{
			itsLatestTagName = s;
			return kJTrue;
			}

		i--;	// skip past the one we found
		}
		while (itsLatestTagName.LocatePrevSubstring(":", &i));

	return kJFalse;
}
JFontStyle
CBStylerBase::GetStyle
	(
	const JIndex	typeIndex,
	const JString&	word
	)
{
	JFontStyle style;
	if (!GetWordStyle(word, &style))
		{
		style = GetTypeStyle(typeIndex);
		}

	return style;
}
示例#4
0
CBHTMLStyler::CBHTMLStyler()
	:
	CBStylerBase(kCurrentTypeListVersion, kTypeCount, kTypeNames,
				 kEditDialogTitle, kCBHTMLStyleID, kCBPHPFT),
	CBHTMLScanner()
{
	JFontStyle blankStyle;
	for (JIndex i=1; i<=kTypeCount; i++)
		{
		SetTypeStyle(i, blankStyle);
		}

	JColormap* colormap = GetColormap();

	SetTypeStyle(kHTMLTag            - kWhitespace, JFontStyle(colormap->GetBlueColor()));
	SetTypeStyle(kHTMLScript         - kWhitespace, JFontStyle(colormap->GetDarkRedColor()));
	SetTypeStyle(kHTMLNamedCharacter - kWhitespace, JFontStyle(kJFalse, kJFalse, 1, kJFalse));
	SetTypeStyle(kHTMLComment        - kWhitespace, JFontStyle(colormap->GetGrayColor(50)));
	SetTypeStyle(kError              - kWhitespace, JFontStyle(colormap->GetRedColor()));

	InitMustacheTypeStyles();
	InitPHPTypeStyles();
	InitJSPTypeStyles();
	InitJavaScriptTypeStyles();

	const JColorIndex red = colormap->GetRedColor();
	for (JIndex i=0; i<kUnusedJavaKeywordCount; i++)
		{
		SetWordStyle(kUnusedJavaKeyword[i], JFontStyle(red));
		}
	for (JIndex i=0; i<kUnusedJSKeywordCount; i++)
		{
		SetWordStyle(kUnusedJSKeyword[i], JFontStyle(red));
		}

	JPrefObject::ReadPrefs();

	JFontStyle style;
	if (GetWordStyle("?php", &style))
		{
		RemoveWordStyle("?php");
		}
}
void
CBPythonStyler::Scan
	(
	istream&			input,
	const TokenExtra&	initData
	)
{
	BeginScan(input);

	const JString& text = GetText();

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

		// save token starts

		if (token.type == kID              ||
			token.type == kReservedKeyword ||
			token.type == kString          ||
			token.type == kComment)
			{
			SaveTokenStart(TokenExtra());
			}

		// set the style

		const JIndex typeIndex = token.type - kWhitespace;
		if (token.type == kWhitespace)
			{
			style = GetDefaultFontStyle();
			}
		else if (token.type == kComment ||
				 token.type == kString)
			{
			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));
			}
		}
		while (SetStyle(token.range, style));
}
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);
}