[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.technology.imp] Re: How to get LPG to treat comments as terminals

Ed Willink wrote:

Instead it may be better to use an enhanced Token to which a partial-line single-line-comment is attached as a suffix and to which other paragraph and full-line single-line-comments are attached as prefixes. The Tokens then parse normally but persist the comments for those activities that require them.

Actually there's no need to do anything. Leave comments out of the grammar, they can always be recovered later by a special purpose comment, newline, whitespace analyzer.

The comments for 'currentToken' are those between 'previousToken'.end
and 'currentToken'.start and/or between 'currentToken'.end
and 'nextToken'.start. Working in this way will allow you to use
syntactic context to decide how much of A,B,C,D,E in

	int a;   // A
	// B
	/*  C */
	/**
         * D
         */
        // E
	int e;

belongs to int a, and how much to int e; It also gives
you more scope for inserting tabs for refactoring and other issues.

	Regards

		Ed Willink