Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Syntax Color Comment Blocks Inside Comment(How Do I Syntax Color Comment Blocks Inside Comment)
Syntax Color Comment Blocks Inside Comment [message #1019365] Fri, 15 March 2013 14:49 Go to next message
Patrick Vane is currently offline Patrick VaneFriend
Messages: 6
Registered: February 2013
Junior Member
I am making a plugin voor UnrealScript and I found out that in UnrealScript you can have comment blocks inside comment blocks.
In other words, the amount of

*/


have to match the

/* and /**


in order to close a block.


Example:

    /**
        inside comment block
        /*
            also inside comment block
        */
        still inside comment block
    */
    outside comment blocks



My question is, how do you do this with Eclipse?

I am currently using this, but it doesn't work (it ignores comment block openings when inside a comment block, so the first comment block ending will end every comment block):

    import java.util.ArrayList;
    import org.eclipse.jface.text.rules.EndOfLineRule;
    import org.eclipse.jface.text.rules.ICharacterScanner;
    import org.eclipse.jface.text.rules.IPredicateRule;
    import org.eclipse.jface.text.rules.IToken;
    import org.eclipse.jface.text.rules.IWordDetector;
    import org.eclipse.jface.text.rules.MultiLineRule;
    import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
    import org.eclipse.jface.text.rules.SingleLineRule;
    import org.eclipse.jface.text.rules.Token;
    import org.eclipse.jface.text.rules.WordRule;
    import com.patrick_vane.unrealscript.editor.constants.TagConstant;


    public class PartitionScanner extends RuleBasedPartitionScanner
    {
        private IToken commentLine  = new Token( TagConstant.COMMENT_LINE );
        private IToken commentBlock = new Token( TagConstant.COMMENT_BLOCK );
        private IToken docsBlock    = new Token( TagConstant.DOCS );
        private IToken string       = new Token( TagConstant.STRING );

        public int commentBlockCount = 0;


        public PartitionScanner()
        {
            ArrayList<IPredicateRule> rules = new ArrayList<IPredicateRule>();

            rules.add( new EndOfLineRule("//", commentLine) );

            rules.add( new SingleLineRule("\"", "\"", string, '\\') );
            rules.add( new SingleLineRule("'", "'", string, '\\') );

            rules.add( new EmptyCommentRule(commentBlock) );

            rules.add( new MultiLineRule("/**", "*/", docsBlock, (char)0, true) );
            rules.add( new MultiLineRule("/*", "*/", commentBlock, (char)0, true) );

            setPredicateRules( rules.toArray(new IPredicateRule[0]) );
        }


        private static class EmptyCommentRule extends WordRule implements IPredicateRule
        {
            private IToken successToken;

            public EmptyCommentRule( IToken successToken )
            {
                super
                (
                    new IWordDetector()
                    {
                        @Override
                        public boolean isWordStart( char c )
                        {
                            return (c == '/');
                        }
                        @Override
                        public boolean isWordPart( char c )
                        {
                            return ((c == '*') || (c == '/'));
                        }
                    }
                );
                this.successToken = successToken;
                addWord( "/**/", successToken );
            }

            @Override
            public IToken evaluate( ICharacterScanner scanner, boolean resume )
            {
                return super.evaluate( scanner );
            }

            @Override
            public IToken getSuccessToken()
            {
                return successToken;
            }
        }
    }
Re: Syntax Color Comment Blocks Inside Comment [message #1021841 is a reply to message #1019365] Wed, 20 March 2013 19:22 Go to previous message
Patrick Vane is currently offline Patrick VaneFriend
Messages: 6
Registered: February 2013
Junior Member
Are these forums dead or something?
Previous Topic:How execute actions after content assist selection
Next Topic:Feature version qualifiers and Git
Goto Forum:
  


Current Time: Thu Apr 25 09:17:49 GMT 2024

Powered by FUDForum. Page generated in 0.03242 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top