Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
RegExp question
Message
De
08/02/2017 18:14:58
 
 
À
08/02/2017 15:43:25
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01647702
Message ID:
01647735
Vues:
79
J'aime (1)
>Excelent. and with little more doctoring I added the Function too. plus including the name that follows.
>
>
>clear
>TEXT TO cText NOSHOW TEXTMERGE
>DEFINE CLASS test
>	PROCEDURE init
>		IF ATC("DEFINE CLASS",x)>0
>		*
>		ENDIF 
>		IF ATC("PROCEDURE",x)>0
>		*
>		ENDIF 
>		PROTECTED PROCEDURE something
>		ENDPROC 
>		HIDDEN PROCEDURE more_sss
>		ENDPROC 
>		FUNCTION me(xx)
>		ENDFUNC 
>	ENDPROC
>ENDDEFINE 
>ENDTEXT
>
>RegExp = NEWOBJECT( "_RegExp", "RegExp.vcx" )
>cpat = "^\s*(((hidd(e(n)?)?)|(prot(e(c(t(e(d)?)?)?)?)?))\s+)?((func(t(i(o(n)?)?)?)?)|(proc(e(d(u(r(e)?)?)?)?)?))\s*\w+"
>? cpat
>n=  RegExp.execute( ctext, cpat, .F., .T.)
>? n
>FOR i=1 TO n
>	?
>*	?? RegExp.Matches[i,1]
>	?? RegExp.Matches[i,2]
>*	?? substr(ctext, regexp.matches(i,1), 20)
>NEXT 
>
Three notes on this, the first concerning what I previously suggested, the others regarding your changes.

Whenever there is a reference to white space, that is, to "\s", change to "[ \t]": we don't want to have newline characters affecting the matches (otherwise, the pattern will add preceding blank to the matches, and accept broken statements as valid).

Then, after the PROCEDURE or FUNCTION keyword, we need at least a white space character, so it should be "+" instead of "*" (if not, PROCEDUREinit will match the pattern).

Finally, checking the name with "\w+" will fail to correctly interpret contained objects' methods. For instance
DEFINE CLASS test AS Form

  ADD OBJECT aButton AS CommandButton

  PROCEDURE aButton.Click
...
will match "PROCEDURE aButton", and I think you would like to match "PROCEDURE aButton.Click" (if I'm not mistaken).

So, a revised pattern could be
m.RegExp.pattern = "^[ \t]*(((hidd(e(n)?)?)|(prot(e(c(t(e(d)?)?)?)?)?))[ \t]+)?((func(t(i(o(n)?)?)?)?)|(proc(e(d(u(r(e)?)?)?)?)?))[ \t]+(\w+(\.\w+)?)"
----------------------------------
António Tavares Lopes
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform