PDA

View Full Version : CodeTips - for complete thinBASIC (including TBAI, TBGL, TBEM)



Petr Schreiber
07-11-2009, 22:59
Hi guys,

I managed to generate CodeTips for 99% of ThinBASIC commands :D.
I did it completely by hand ... ok, just joking.

I first decompiled all the help files using HTML Help Workshop, and then ran the following script on them (warning, dirty code):


' -- HTML help 2 code tips
Uses "file", "console"

Dim Files() As String
Dim nFiles As Long

' -- Where HTML files are
Dim SearchPath As String = APP_SourcePath

' -- Filter them
nFiles = DIR_ListArray(Files, SearchPath, "*.htm", %FILE_NORMAL Or %FILE_ADDPATH)

Dim i As Long
Dim sBuffer, sSyntax, sDescription As String
Dim sCodeTips As String
Dim sLineFinal As String

PrintL nFiles, "found"
Dim found As Long
Dim fSpace As Long

For i = 1 To nFiles
' -- Load file
sBuffer = FILE_Load(Files(i))
If InStr(sBuffer, ">Syntax") = 0 Then Iterate For

' -- Extract and postprocess description
sDescription = GRAB$(sBuffer, ">Description", "Syntax<")

sDescription = Replace$(sDescription, "&nbsp;", " ")
sDescription = Replace$(sDescription, $CRLF, "|")
sDescription = BirdBracketPurge(sDescription)
sDescription = Trim$(sDescription, Any $CRLF+$SPC)
sDescription = TrimFull$(sDescription)

While InStr(sDescription, "||")
sDescription = Replace$(sDescription, "||", "|")
Wend
sDescription = Trim$(sDescription, Any " |")

' -- Extract and postprocess syntax
If InStr(sBuffer, "Returns<") Then
sSyntax = GRAB$(sBuffer, ">Syntax", "Returns<")
Else
sSyntax = GRAB$(sBuffer, ">Syntax", "Return value<")
End If

sSyntax = Replace$(sSyntax, "&nbsp;", " ")

If InStr(sSyntax, "= ") Then sSyntax = Remain$(sSyntax, "= ")
If InStr(sSyntax, " =") Then sSyntax = Remain$(sSyntax, " =")
If InStr(sSyntax, "Type") Then Iterate For
If InStr(sSyntax, "expression1") Then Iterate For

sSyntax = Replace$(sSyntax, $CRLF, "|")
sSyntax = BirdBracketPurge(sSyntax)

sSyntax = Trim$(sSyntax, Any $CRLF+$SPC)
sSyntax = TrimFull$(sSyntax)

While InStr(sSyntax, "||")
sSyntax = Replace$(sSyntax, "||", "|")
Wend
sSyntax = Trim$(sSyntax, Any " |")
' -- Silly bad syntax detection
If InStr(sSyntax, "2005") > 0 Then Iterate For
If InStr(sSyntax, "2006") > 0 Then Iterate For
If InStr(sSyntax, "2007") > 0 Then Iterate For
If InStr(sSyntax, "2008") > 0 Then Iterate For
If InStr(sSyntax, "2009") > 0 Then Iterate For

' -- Build final description
sLineFinal = sSyntax+"|"+sDescription+$CRLF

' -- Silly test if it is really what we want
If sLineFinal = "||.|"+$CRLF Then Iterate For
If InStr(sLineFinal, "( ...|... )") Then Iterate For
If sLineFinal = "FTP_(, )||.|"+$CRLF Then Iterate For
If LEFT$(sLineFinal, 1) = "|" Then Iterate For
If LEFT$(sLineFinal, 1) = "'" Then Iterate For
If LEFT$(sLineFinal, 1) = "%" Then Iterate For
If LEFT$(sLineFinal, 3) = "|||" Then Iterate For
If LEFT$(sLineFinal, 2) = "1|" Then Iterate For
If LEFT$(sLineFinal, 4) = "see(" Then Iterate For
If LEFT$(sLineFinal, 4) = "see " Then Iterate For
If LEFT$(sLineFinal, 7) = "number^" Then Iterate For
If LEFT$(sLineFinal, 6) = "for( C" Then Iterate For
If LEFT$(sLineFinal, 6) = "b Site" Then Iterate For
If LEFT$(sLineFinal, 5) = "TYPE(" Then Iterate For
If LEFT$(sLineFinal, 6) = "There(" Then Iterate For
If LEFT$(sLineFinal, 7) = "String(" Then Iterate For
If LEFT$(sLineFinal, 7) = "nStart(" Then Iterate For
If LEFT$(sLineFinal, 7) = "nStart " Then Iterate For
If LEFT$(sLineFinal,16) = "StringExpression" Then Iterate For
If LEFT$(sLineFinal, 9) = "There are" Then Iterate For

sCodeTips += sLineFinal
PrintL "--", Files(i)
Incr found

Next

Dim LinesOfClips() As String
Parse(sCodeTips, LinesOfClips, $CRLF)

Array Sort LinesOfClips

sCodeTips = Join$(LinesOfClips, $CRLF)
PrintL "END OF PROCESSING"
' -- Put it to clipboard
ClipBoard_SetText(sCodeTips)

WaitKey

' -- Removes anything bird brackets ( purging text from HTML tags )
Function BirdBracketPurge(sString As String) As String
Dim i As Long
Dim char, result As String
Dim inBracket As Long

For i = 1 To Len(sString)
char = Mid$(sString, i, 1)
If char = "<" Then Incr inBracket

If inBracket = 0 Then result += char

If char = ">" Then Decr inBracket
Next
Return result
End Function


To use it, just copy the contents of attached file to thinBasic_Codetips_Usr.ini


Petr

Michael Hartlef
08-11-2009, 10:07
Thanks Petr :eusaclap:

ErosOlmi
08-11-2009, 10:08
oh Petr, this is of great help.
Thank you so much. I will use this for next release so it will be in official Codetip file and not user file.

I just need a favour: do not put double || between data. I ask that because I'm writing a new CodeTip dedicated control that will adjust itself height/width based on data it will find. Using double || will in some way break the rule. See image.

Ciao and thanks again.
Eros

Petr Schreiber
08-11-2009, 10:23
Hi,

you are right. I changed the script and the attachement too.

One thing - the "|" character is sometimes used in syntax, like here:


DO [{WHILE | UNTIL} NumericExpression]

which makes the line end on odd places. This occurs in just a few cases, but maybe different caracter could be used.

The new look is very nice!

Petr Schreiber
08-11-2009, 10:33
Eros,

it seems some postprocessing takes place.
The CodeTip for ASC is:


ASC(StringExpression [, position])|Return the ASCII code (0 to 255) of the specified character in a string.


... but displayed is something damaged, see attached screenshot.


Petr

Petr Schreiber
08-11-2009, 10:40
One more idea - separating syntax with description using "|" is simple, but could be little bit clumsy. Maybe some tag structure could be used, allowing multiline example (maybe you already have it solved). So I propose something like:

<syntax>COMMAND(something)</syntax><descr>Description:<BR>It is easy</descr>
<BR> would be replacement for "|". I know the files will grow up, but they will be more maintainable I think.

What do you think?

ErosOlmi
08-11-2009, 10:44
Because you have ASC both in
thinBasic_Codetips.ini
thinBasic_Codetips_Usr.ini
files. Just put your great work into thinBasic_Codetips.ini and leave thinBasic_Codetips_Usr.ini empty.

I will use your great file for thinBasic_Codetips.ini in future so use it.

Regarding char | to be used as separator, we can think about something else.
Anything to suggest?

ErosOlmi
08-11-2009, 10:46
We were posting at the same time.

Your tag help seems great and much less confusing.
Can you please produce a file with your idea and I will try to us it.

Petr Schreiber
08-11-2009, 10:58
Of course,

file attached :)

ErosOlmi
08-11-2009, 11:04
Great Petr.
I will check right now how to change thinAir in order to use this syntax.

As a general rule, I would say that

<syntax>...</syntax><description>...</description>
is the minimum to be found in file.
Than I will check if additional tags are present and us them like (for example)

<syntax>...</syntax><description>...</description><example>...</example>

Thanks again
Eros

Petr Schreiber
08-11-2009, 11:11
That would be great, thanks!

ReneMiner
25-10-2012, 23:07
I know that code-tips is in experimental state, but there's a few things:

if I type TBLIB_method(... at the parenthesis the code-tip appears in code-window,
if I activate now any other window that lays behind the code-window (maybe this browser-window right now) the code-tip does not disappear and stays in front of my browser now.
I would not mind to have the code-tips content (optional) displayed in the bottom-status-bar of thinAir instead of covering my code or other windows.