[Prolint-cvs] SF.net SVN: prolint: [267] trunk/prolint/rules/dotcomment.p
Brought to you by:
johnallengreen,
jurjen
From: <ju...@us...> - 2006-03-16 21:48:14
|
Revision: 267 Author: jurjen Date: 2006-03-16 13:48:02 -0800 (Thu, 16 Mar 2006) ViewCVS: http://svn.sourceforge.net/prolint/?rev=267&view=rev Log Message: ----------- Rule "dotcomment" is faster and better with Proparse version 3. Contributed by John. Modified Paths: -------------- trunk/prolint/rules/dotcomment.p Modified: trunk/prolint/rules/dotcomment.p =================================================================== --- trunk/prolint/rules/dotcomment.p 2006-03-15 22:37:01 UTC (rev 266) +++ trunk/prolint/rules/dotcomment.p 2006-03-16 21:48:02 UTC (rev 267) @@ -3,27 +3,12 @@ by : Jurjen Dijkstra purpose : find statements that begin with a PERIOD - How it works: - example source: + These dot comments are usually a typo, and should be replaced with regular + comments. + ----------------------------------------------------------------- - MESSAGE "a". - .MESSAGE "b". + Copyright (C) 2001,2002,2006 Jurjen Dijkstra, John Green - tokenlister: - MESSAGE MESSAGE (statehead) - QSTRING "a" - PERIOD . - PERIOD . - MESSAGE MESSAGE (statehead) - QSTRING "b" - PERIOD . - - so we are looking for a PERIOD with a NextSibling if this NextSibling - is a statehead. - ----------------------------------------------------------------- - - Copyright (C) 2001,2002 Jurjen Dijkstra - This file is part of Prolint. Prolint is free software; you can redistribute it and/or @@ -49,38 +34,97 @@ DEFINE VARIABLE i AS INTEGER NO-UNDO. -/* Make it fast: there are lots of PERIOD nodes in the source. - So, unlike other rules we don't use procedure searchNode. - Just open a query, less overhead. This means we are not - going to check for _proparse_ prolint-nowarn(dotcomment) */ +IF parserGetVersion() > "3" THEN + /* + example source: + .MESSAGE "b". -ASSIGN - TheNode = parserGetHandle() - NextSibling = parserGetHandle() - numResults = parserQueryCreate(hTopnode, "dotcomment":U, "PERIOD":U). + The '.' in front of "MESSAGE" causes the entire statement to be commented. + (The comment extends to the next regular '.') + Proparse recognizes these, and turns the entire comment into a DOT_COMMENT + node. These nodes are only found in the syntax where a statement can be + found. (i.e. You can't have a dot comment in the middle of a statement.) + + */ + RUN searchNode ( + hTopnode /* "Program_root" node */ + , "InspectNode":U /* name of callback procedure */ + , "DOT_COMMENT":U /* list of statements to search, ?=all */ + ). -DO i=1 TO numResults : - IF parserQueryGetResult("dotcomment":U, i, theNode) THEN DO: +ELSE DO: - /* is there a NextSibling? */ - IF ""<>parserNodeNextSibling(theNode, NextSibling) THEN - /* there should be no whitespace following the PERIOD */ - IF NOT parserHiddenGetBefore(NextSibling) THEN - /* is this NextSibling a statement head? */ - IF parserAttrGet(NextSibling, "statehead":U) <> "" THEN - /* check if there is NO _proparse_ directive */ - IF 0=parserAttrGetI(theNode,pragma_number) THEN - RUN PublishResult (compilationunit, - parserGetNodeFilename(theNode), - parserGetNodeLine(theNode), - "PERIOD comments a statement":U, - rule_id). + /* + How it works: + example source: + + MESSAGE "a". + .MESSAGE "b". + + tokenlister: + MESSAGE MESSAGE (statehead) + QSTRING "a" + PERIOD . + PERIOD . + MESSAGE MESSAGE (statehead) + QSTRING "b" + PERIOD . + + so we are looking for a PERIOD with a NextSibling if this NextSibling + is a statehead. + */ + + /* Make it fast: there are lots of PERIOD nodes in the source. + So, unlike other rules we don't use procedure searchNode. + Just open a query, less overhead. This means we are not + going to check for _proparse_ prolint-nowarn(dotcomment) */ + + ASSIGN + TheNode = parserGetHandle() + NextSibling = parserGetHandle() + numResults = parserQueryCreate(hTopnode, "dotcomment":U, "PERIOD":U). + + DO i=1 TO numResults : + IF parserQueryGetResult("dotcomment":U, i, theNode) THEN DO: + + /* is there a NextSibling? */ + IF ""<>parserNodeNextSibling(theNode, NextSibling) THEN + /* there should be no whitespace following the PERIOD */ + IF NOT parserHiddenGetBefore(NextSibling) THEN + /* is this NextSibling a statement head? */ + IF parserAttrGet(NextSibling, "statehead":U) <> "" THEN + /* check if there is NO _proparse_ directive */ + IF 0=parserAttrGetI(theNode,pragma_number) THEN + RUN PublishResult (compilationunit, + parserGetNodeFilename(theNode), + parserGetNodeLine(theNode), + "PERIOD comments a statement":U, + rule_id). - END. + END. + END. + + parserQueryClear("dotcomment":U). + parserReleaseHandle(TheNode). + parserReleaseHandle(NextSibling). + END. -parserQueryClear("dotcomment":U). -parserReleaseHandle(TheNode). -parserReleaseHandle(NextSibling). +PROCEDURE InspectNode: + /* purpose: Simply report all DOT_COMMENT nodes. */ + DEFINE INPUT PARAMETER theNode AS INTEGER NO-UNDO. + DEFINE OUTPUT PARAMETER AbortSearch AS LOGICAL NO-UNDO INITIAL NO. + DEFINE OUTPUT PARAMETER SearchChildren AS LOGICAL NO-UNDO INITIAL NO. + RUN PublishResult ( + compilationunit + , parserGetNodeFilename(theNode) + , parserGetNodeLine(theNode) + , "PERIOD comments a statement":T + , rule_id + ). + +END PROCEDURE. + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |