Re: VFP 9: Line Parsing
- From: "Olaf Doschke" <olaf.doschke@xxxxxxxxxxxxxxxx>
- Date: Thu, 23 Apr 2009 00:01:45 +0200
Another gotcha, that fortunately is no real problem:
? "&&"
This does not work, but because of that you won't need to consider source code that has && within a string literal, no matter where within the string, VFP insist on && being the start of a line end comment and therefore ? " is incomplete, the
closing " is part of the comment.
The syntax highlighter of VFP does not color this correctly! Well, you can argue that VFP does not parse&compile this correctly, but it's one less problem to care for, if && is within a string or not, the first && in a line starts a comment.
U1 U2 Result
-- -- ------
; ; syntax error on this line only
; - valid: Code (not comment) continues on next physical line.
- ; valid: Comment continues on next physical line.
- - valid: The line stands alone.
Why the result when semicolons are in both positions?
Well, VFPs parser then can't determine, if the command or the comment would continue, so it does define this as syntax error.
Regarding how to easier find these U1,U2:
RTRIM() does trim away any whitespace, so the case of ;___ at the line end, any whitespace can be taken care of easily with RTRIM(), or if you do ALINES() on the sourcecode it's even a flag of ALINES to trim the lines. U2 then is the last char, or better said: If the last char is ";" U2 is ";" otherwise the line does not end with semicolon.
So all the heavy work is finding if there is a U1 semicolon before a && comment. As said initially, && always starts a comment and we don't need to parse if it is within a string or not. So we can search if U1 is ";" by backtracing
for the first non whitespace, or again use RTRIM in conjunction with GETWORDNUM:
If lcLine is a "physical" line parsed:
if '&'+'&' $ lcLine && here you see how to still create a string like '&&'
U1 = Right(Rtrim(GetWordnum(lcLine,1,'&'+'&')),1)
else
U1 = NULL && no line end comment
endif
Or if you treat U! and U2 as booleans:
U1 = (Right(RTrim(lcLine),1)=";")
U2 = ('&'+'&' $ lcLine AND Right(RTrim(GetWordnum(lcLine,1,'&'+'&')),1)=";")
If U1 AND U2
llContinuation = .F. && because of syntax error
Else
llContinuation = U1 OR U2
Endif
Bye, Olaf.
.
- References:
- VFP 9: Line Parsing
- From: Gene Wirchenko
- VFP 9: Line Parsing
- Prev by Date: Re: VFP 9: Line Parsing
- Next by Date: Re: How to hide the task from the task bar
- Previous by thread: Re: VFP 9: Line Parsing
- Next by thread: Use mouse in comments
- Index(es):
Relevant Pages
|