heber.bas

[<<<] [>>>]

This BASIC program is an external preprocessor for ScriptBasic. This demonstrates how simple to write an external preprocessor, as it can even be done in BASIC itself.

This small program converts HTML Embedded BASIC (heb) into pure BASIC. HEB is something like PHP or Microsoft ASP BASIC, where the BASIC code is put between HTML code. This small preprocessor converts the heb file taking all HTML that is outside of the BASIC code and putting it into print statements, and all BASIC code that is inside HTML code putting outside.

This is a sample implementation and has significant shortages. In case the BASIC program inside some string has <% or >% (which is not likely though possible) the preprocessor crates false code.

The souce code of the file `heber.bas' is:

while  len(InputText) > 0
  StringPosition = InStr(InputText,"<%")
  if not IsDefined(StringPosition) then goto Finished
  AppendString = Mid@$(InputText,1,StringPosition-1)
  InputText = Mid@$(InputText,StringPosition+2)
  if len(AppendString) > 0 Then
    AppendString = Replace(AppendString,"\\","\\\\")
    AppendString = Replace(AppendString,"\"","\\\"")
    OutputText = OutputText & "print \"\"\"" & AppendString & "\"\"\"\n"
  end if
  StringPosition = InStr(InputText,"%>")
  if not IsDefined(StringPosition) then error(1)
  AppendString = Mid@$(InputText,1,StringPosition-1)
  InputText = Mid@$(InputText,StringPosition+2)
  if len(AppendString) > 0 then
    if Mid@$(AppendString,1,1) = "=" then
      AppendString = "print " & Mid@$(AppendString,2)
    end if
    OutputText = OutputText & AppendString & "\n"
  end if
wend
if len(InputText) > 0 then
  InputText = Replace(InputText,"\"","\\\"")
  OutputText = OutputText & "print \"\"\"" & InputText & "\"\"\"\n"
end if


[<<<] [>>>]