sancarn / Extended_MapBasic

This is an Open Source project. We are developing a powerful extension for the MapBasic Window in Pitney Bowes' MapInfo. The extension will give users the ability to compile on demand from the MapBasic Window. Further extensions may include custom MapBasic functions to accomplish common tasks. This project is still very much WIP
MIT License
1 stars 0 forks source link

Ideas for the addition of custom MapBasic functions #1

Open sancarn opened 8 years ago

sancarn commented 8 years ago

It may be desired for these custom MapBasic functions to reside separate from the standard application (perhaps in a sub-folder, A_ScriptDir/Libraries/...)

Required information:

Each of these statements should be surrounded in a special string to provide easy extraction with RegEx. For example:

{
Sub say(someArg as string)
    print someArg
End Sub
}

Declares will be automatically added into the header of the file and should not be included in the code block. All Declare blocks will be removed with RegexReplace(str,"Declare.*","") [unless anyone can offer a reason as to why this is a bad idea!]

Each sub/function should be kept separate. If one requires the existence of another a comment should be added 'Requires "Name of Function or Sub". - Why? Mainly for future features. It may be nice for users to select which functions they want to use from which libraries.

It may also be nice to add functionality for custom statements. Classes and COMObjects would also be a nice feature if possible to implement in MB.


Custom Statement Idea: Set up a Regex replace to find statements and replace them with sub-routine calls:

{
{
statement: place\s+"(.*)"\s+(on|in)\s+"(.*)"
}
{
replace: call place(match1,"match2",match3)
}
}

Then define the sub-routine calls separately:

{
sub place(object as string, on_in as string, furniture as string)
    if object = "" then
        Note "An error occurred in statement place - Cannot place nothing"
    end if
    if on_in <> any("on","with") AND furniture <> "" then
        Note "An error occurred in statement place - Cannot place item"
    end if
    print object & " is now " & on_in & " " & furniture
end sub
}

This setup would convert something like this: place "this" on "that"

Into this: call place("this","on","that")

Which would call the base sub-routine function. In the end these are simply sub-routines, but they may be easier to understand in this context than as actual sub-routine.

sancarn commented 8 years ago

It might also be useful to include other transpiler options. For instance:

CONTAINS{ Start: {" End: "} } WITH CONTAINS { contained = replace(contained,"\r\n", """ & mbCrLf & """ contained = makeMultilineCommand(contained) return contained }