[Gambas-devel] LineAnalyze
Charlie Reinl
Karl.Reinl at ...16...
Tue Aug 24 22:26:15 CEST 2004
Salut Benoit,
I changed with your hints and what I worked out the code of LineAnalyze.
Now he is more compackt so it runs faster.
And I include ProcLines also.
But I have 3 problems:
1. operaters returned could be like ')=' and are not splitted off
FFind.class line 137
IF cvwFindList.Moveto(hForm.path)=FALSE THEN
gives
IF cvwFindList.Moveto(hForm.path )= FALSE THEN
the editor.Analyze out put is
IF 2 Keyword
cvwFindList 5 Symbol
. 4 Operator
Moveto 5 Symbol
( 4 Operator
hForm 5 Symbol
. 4 Operator
path 5 Symbol
)= 4 Operator
FALSE 2 Keyword
THEN 2 Keyword
2. Numbers could returned like '1+2' and are not splitted off
i=1+2
gives
i = 1+2
the editor.Analyze out put is
i 5 Symbol
= 4 Operator
1+2 6 Number
3. when i separate signe and number -1 to - 1
FDebug.class line 3
PRIVATE CONST STATE_LAST AS Integer = -1
gives
PRIVATE CONST STATE_LAST AS Integer = - 1
and that line changed like that I can't compile
Type mismatch at line 3 in FDebug.class
After passing every line by LineAnalyze gambas (the IDE) compiled well,
but I ditn't try to test the IDE if it also works.
Amicalement
Charlie
Here the code:
PUBLIC SUB edtEditor_Cursor()
IF edtEditor.Line <> $iLastLine THEN
' changings charlie
preLineAnalyze()
' 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()
preLineAnalyze()
END
PUBLIC SUB preLineAnalyze()
DIM sModifLine AS String
DIM iRet AS Integer
IF NOT bmyMsgBox THEN
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
sModifLine = LineAnalyze(edtEditor.Lines[$iLastLine],
$iLastLine, TRUE)
bmyMsgBox = TRUE
DO WHILE TRUE
IF iRet > 0 THEN
iRet = message.Question("Line : " & $iLastLine & "\n
Org : ->" & edtEditor.Lines[$iLastLine] & "<-\nNew : ->" & sModifLine &
"<-\n", "Change to 'New' line", "Keep the 'Org' line")
ELSE
iRet = message.Question("Line : " & $iLastLine & "\n
Org : ->" & edtEditor.Lines[$iLastLine] & "<-\nNew : ->" & sModifLine &
"<-\n", "Change to 'New' line", "Keep the 'Org' line", "Add line to report")
ENDIF
IF iRet = 1 THEN
edtEditor.Lines[$iLastLine] = sModifLine
edtEditor.Refresh
BREAK
ELSE IF iRet = 2 THEN
BREAK
ELSE IF iRet = 3 THEN
writeReport(sModifLine)
ENDIF
LOOP
bmyMsgBox = FALSE
ENDIF
ENDIF
ENDIF
END
'--------------------------------------------
PRIVATE FUNCTION LineAnalyze(sLine AS String,iLine AS Integer, OPTIONAL
bPrintChanges AS Boolean = FALSE) 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
' 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
FOR nI = 0 TO sPart.Count - 1
SELECT CASE iPart[nI]
CASE 2 ' Keyword
IF sPart[nI] = "LINE" OR sPart[nI] = "LAST" OR sPart[nI] =
"ME" THEN
sPart[nI] = " " & sPart[nI]
ELSE
sPart[nI] = " " & sPart[nI] & " "
ENDIF
CASE 4 ' Operator
SELECT CASE sPart[nI]
CASE "#"
sPart[nI] = " " & sPart[nI]
CASE "(", ")", "[", "]", "."
' nothing to do
CASE ",", ";", ":"
sPart[nI] = sPart[nI] & " "
CASE ELSE
sPart[nI] = " " & sPart[nI] & " "
END SELECT
CASE 5 ' Symbol
' here you can look up if this Symbol is written as declaret
CASE 6 ' Number
IF Left(sPart[nI], 1) = "+" OR Left(sPart[nI], 1) = "-" THEN
sPart[nI] = Left(sPart[nI], 1) & " " & Mid(sPart[nI], 2)
ENDIF
CASE 8 'Comment
IF Mid(sPart[nI], 2, 1) <> " " THEN
sPart[nI] = " ' " & Mid(sPart[nI], 2)
ELSE
sPart[nI] = " " & sPart[nI]
ENDIF
END SELECT
IF bPrintChanges THEN PRINT sPart[nI], iPart[nI],
GetColorsName(iPart[nI])
' last contition
IF sPart.Count > 1 THEN
IF nI = sPart.Count - 1 THEN
IF iPart[nI] <> 4 AND iPart[nI] <> 5 THEN
IF Right(sPart[nI - 1], 1) <> " " AND Left(sPart[nI], 1) <> " "
THEN
sPart[nI] = " " & sPart[nI]
ENDIF
ENDIF
ENDIF
ENDIF
' first contition
IF nI = 0 THEN
sOut = sPart[nI]
ELSE
IF Right(sPart[nI - 1], 1) = " " AND Left(sPart[nI], 1) = " " THEN
sOut = RTrim(sOut) & sPart[nI]
ELSE IF sPart[nI - 1] = ", " AND sPart[nI] = ", " THEN
sOut = sOut & sPart[nI]
ELSE IF Right(sPart[nI - 1], 1) = " " AND (Left(sPart[nI], 1) =
"," OR Left(sPart[nI], 1) = ")" OR Left(sPart[nI], 1) = "]") THEN
sOut = RTrim(sOut) & sPart[nI]
ELSE IF (Right(sPart[nI - 1], 1) = "(" OR Right(sPart[nI - 1], 1)
= "[" OR Right(sPart[nI - 1], 1) = "#") AND Left(sPart[nI], 1) = " " THEN
sOut = sOut & LTrim(sPart[nI])
ELSE
sOut = sOut & sPart[nI]
ENDIF
ENDIF
NEXT
IF bPrintChanges THEN PRINT " ----------------------------------------"
sOut = sLeftBlanks & Trim(sOut)
RETURN sOut
END
'--------------------------------------------
PUBLIC SUB writeReport(sLine AS String )
DIM sRep AS File
OPEN "/tmp/LineAnalyzeReport.log" FOR APPEND AS sRep
PRINT # sRep, "File :" & File .Name(Path)
PRINT # sRep, "Line : " & $iLastLine
PRINT # sRep, "Org : ->" & edtEditor.Lines[$iLastLine] & "<-"
PRINT # sRep, "New : ->" & sLine & "<-"
PRINT # sRep, "-----------------------------------------------------------"
CLOSE # sRep
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
More information about the Devel
mailing list