[Gambas-devel] 2. still now the best LineAnalyze (you should compile after)
Benoit Minisini
gambas at ...1...
Sun Aug 22 17:33:41 CEST 2004
On Friday 20 August 2004 03:57, Charlie Reinl wrote:
> Salut,
>
> based on gambas-0.97
> like I said yesterday :
> better then yesterday, but not as good like tomorrow he will be.
> Hope you are carefully use that, i don't want crash your code.
>
> But I need code lines where it dosn't compile or has spaces on wrong
> places.
>
> What I need:
> Guy who makes a copy from app/gambas then they start gambas opening that
> copy and choosing FEditor.Class file.
> Up from PUBLIC SUB edtEditor_Cursor() they select and replace it with my
> PUBLIC SUB edtEditor_Cursor() and all the follwed lines.
> Then press F5, a new gambas IDE will start, open a gambas project from you
> (better is a copy from) and choose a class or a module file to opening.
> Start from the first line and press the UP Button till you reache the end
> of the file.
> Press F5.
> If an Error raise, please send my that line where the error occure.
> And have a look to the other lines if there are no well formatet lines.
> If you think a line is not well formated , send me that line.
>
> And then open the next Class or module file and do the same.
> I need examples to finish the LineAnalyze.
> Thanks
>
> Amicalement
> Charlie
>
> PS that code is based on gambas-0.97 (not gambas-0.97a)
>
> '----------------------------------------------------------
> PUBLIC SUB edtEditor_Cursor()
> DIM sModifLine AS String
> IF edtEditor.Line <> $iLastLine THEN
> ' changings charlie
> IF Left(Trim(edtEditor.Lines[$iLastLine]), 1) <> "'" AND
> Trim(edtEditor.Lines[$iLastLine]) <> "" THEN
> sModifLine = LineAnalyze(edtEditor.Lines[$iLastLine],
> $iLastLine) IF sModifLine <> edtEditor.Lines[$iLastLine] THEN
> edtEditor.Lines[$iLastLine] = sModifLine
> edtEditor.Refresh
> ENDIF
> ENDIF
> ' end changings charlie
> $iLastLine = edtEditor.Line
> HideCompletion
> HideSignature
> IF IsModified() THEN Scan = NULL
> ELSE IF $bCheckSignature OR frmSignature.Visible THEN
> $bCheckSignature = FALSE
> CheckSignature
> ENDIF
> DrawTitle
> ' TRY PRINT Editor.Analyze(Editor.Lines[Editor.Line]).Join(",")
> END
> PUBLIC SUB edtEditor_LostFocus()
> DIM sModifLine AS String
> IF Left(Trim(edtEditor.Lines[$iLastLine]), 1) <> "'" AND
> Trim(edtEditor.Lines[$iLastLine]) <> "" THEN
> sModifLine = LineAnalyze(edtEditor.Lines[$iLastLine], $iLastLine)
> IF sModifLine <> edtEditor.Lines[$iLastLine] THEN
> edtEditor.Lines[$iLastLine] = sModifLine
> edtEditor.Refresh
> ENDIF
> ENDIF
> END
> PRIVATE FUNCTION LineAnalyze(sLine AS String,iLine AS Integer) AS String
> DIM nI AS Integer
> DIM nJ AS Integer
> DIM sOut AS String
> DIM sPart AS String[]
> DIM iPart AS Integer[]
> DIM aSPart AS Object
> DIM sLeftBlanks AS String
> DIM sBlank AS String
> IF IsProc(Trim(sLine)) THEN RETURN sLine
> IF Upper(Trim(sLine)) = "END" THEN RETURN sLine
> ' looking for leading Blanks
> sLeftBlanks = String$(Len(sLine) - Len(LTrim(sLine)), " ")
> ' analysing Line
> edtEditor.Analyze(sLine)
> ' reading Symbols
> sPart = GambasEditor.Symbols
> ' reading Types
> iPart = GambasEditor.Types
> sBlank = " "
> ' set the sBlank
> FOR nI = 0 TO sPart.Count - 1
> ' if legth Operator > 1 exepte some
> IF iPart[nI] = 4 AND Len(sPart[nI]) > 1 THEN
> SELECT CASE sPart[nI]
> CASE "<>"
> CASE "<="
> CASE ">="
> CASE "&/"
> CASE ELSE
> sPart[nI] = Left(sPart[nI], 1) & " " & Mid(sPart[nI],
> 2) sOut = sOut & " " & sPart[nI]
> FOR nJ = ni + 1 TO sPart.Count - 1
> sOut = sOut & " " & sPart[nJ]
> NEXT
> edtEditor.Lines[iLine] = sLeftBlanks & Trim(sOut)
> RETURN LineAnalyze(edtEditor.Lines[iLine], iLine)
> END SELECT
> ENDIF
> SELECT CASE sPart[nI]
> CASE "."
> sBlank = ""
> IF nI > 0 THEN
> IF iPart[nI - 1] <> 5 AND iPart[nI - 1] <> 2 THEN '
> Symbol and Keyword
> sBlank = " "
> ENDIF
> ENDIF
> CASE "("
> sBlank = ""
> IF nI > 0 THEN
> IF iPart[nI - 1] <> 3 AND iPart[nI - 1] <> 5 THEN '
> Function and Symbol
> sBlank = " "
> ENDIF
> ENDIF
> CASE ")", "[", "]"
> sBlank = ""
> CASE ELSE
> IF nI > 0 THEN
> SELECT CASE sPart[nI - 1]
> CASE ".", "(", "["
> sBlank = ""
> CASE ELSE
> sBlank = " "
> END SELECT
> ELSE
> sBlank = " "
> ENDIF
> END SELECT
> SELECT CASE iPart[nI]
> CASE 5 ' Symbol
> ' here you can look up if this Symbol is written as declaret
> sOut = sOut & sBlank & sPart[nI]
> CASE 6 ' Number
> IF nI > 0 THEN
> SELECT CASE iPart[nI - 1]
> CASE 5 ' Symbol
> sOut = sOut & sBlank & Left(sPart[nI], 1) & " " &
> Mid(sPart[nI], 2)
> CASE ELSE
> sOut = sOut & sBlank & sPart[nI]
> END SELECT
> ELSE
> sOut = sOut & sBlank & sPart[nI]
> ENDIF
> CASE ELSE
> sOut = sOut & sBlank & sPart[nI]
> END SELECT
> PRINT sPart[nI], iPart[nI], GetColorsName(iPart[nI])
> NEXT
> sOut = sLeftBlanks & Trim(sOut)
> RETURN sOut
> END
> FUNCTION GetColorsName(iType AS Integer) AS String
> DIM sOut AS String
> SELECT CASE iType
> CASE edtEditor.Colors.Background
> sOut = "Background"
> CASE edtEditor.Colors.Breakpoint
> sOut = "Breakpoint"
> CASE edtEditor.Colors.Comment
> sOut = "Comment"
> CASE edtEditor.Colors.Current
> sOut = "Current"
> CASE edtEditor.Colors.DataType
> sOut = "DataType"
> CASE edtEditor.Colors.Function
> sOut = "Function"
> CASE edtEditor.Colors.Keyword
> sOut = "Keyword"
> CASE edtEditor.Colors.Normal
> sOut = "Normal"
> CASE edtEditor.Colors.Number
> sOut = "Number"
> CASE edtEditor.Colors.Operator
> sOut = "Operator"
> CASE edtEditor.Colors.String
> sOut = "String"
> CASE edtEditor.Colors.Symbol
> sOut = "Symbol"
> CASE ELSE
> sOut = "??"
> END SELECT
> RETURN sOut
> END
>
>
Hi, Charlie.
I read your last code, and I find it very complicated!
I think you could do simpler by implementing the following rules:
* Each keyword has a space before and a space after, except ME and LAST.
* The operators ( ) [ ] . has no space before, and no space after.
* The operators , ; : has no space before and one space after.
* The operator # has one space before and no space after.
* Each other operator has a space before and a space after.
* The other elements has no space before and no space after, except if the
last element is not a operator. Then you should add a space.
* No more than one space between two elements.
All the rules except the last one can be implemented in a big test into the
loop that enumerates each element of the analyzed string.
By catenating the rewritten line with a function that checks the last rule,
the code will become small and clear, and many tests will be avoided.
If you don't see how to do that, tell me.
Regards,
--
Benoit Minisini
mailto:gambas at ...1...
More information about the Devel
mailing list