MOX Coding and Programing Language Syntax Documentation
The MOX coding and programming language pays heritage to BASIC, but has been crafted for the specific type of work and environment that is demanded of Moxie.Build.
Notable Aspects of the MOX Language
Some of the following items may catch developers experienced in other languages off guard; trust us, they are good for you :)
- Due to the database focused nature of MOX, the word field is used instead of variable in all documentation and commands
- Field names, parameter names, method names, function names, etc. must start with a letter
- There are no data types. Internally, everything is stored as a string
- & is used for text concatenation, while + is used only for math addition
- The majority of text functions and features are case insensitive
- ( ) are reserved for solving sub-expressions, or causing a parameter to be solved. A list of parameters in a call is not wrapped in ( )
- Parameters are not solved by default, and all parameters are passed by-value. Functions can return multiple values
- All source code is stored in database Procedures. A Procedure can contain Private Methods, Functions and Macros. A Procedure can call other Procedures of the type Public Method, and it can Include other Procedures of the type Include
- Moxie.Build is object oriented under the hood. The MOX language however, is procedural
- DB Field Names must contain dots to indicate the leading Table Name. Non DB Field names may contain dots to help with context
- Private Method/Function/Macro names should contain dots to help specify context
Lines of Code
In the following rules, a line of code is one executable item as viewed by the compiler. A line of text refers to one line in a text editor.
- A new line of text is a new line of code
- : is used to start a new line of code on the same line of text
- _ is used at the end of a line of text to continue the line of code on the next line of text
- Extra white-space is ignored
Example:
If Req.IsPost : And List.Edit : List.Edit.Proc Job.Edit, "", ""
If condition (Req.IsPost) And (List.Edit) are True, execute the Method (List.Edit.Proc), which has three parameters (Job.Edit, "", "")
Comments
- ' start of a single line comment. May be used after other code on the same line
- Rem ' start of a single line comment, may not be used after other code on the same line
- Is intended to be used with EndRem to form an indented block of executable code, together indicating the scope of the comment
Parameters
- ( ) are used around parameter names for the Method/Function/Macro definition
- ( ) are not used when a Method/Function/Statement is called, each parameter is comma-with-space separated
- ( ) are used when a Macro is referenced, each parameter is comma-with-space separated
- Parameters are not solved by default, wrap a parameter value in ( ) to have it solved
- Parameters are always passed by-value, not by-reference/pointer
- Example Method Call:
- Demo.CallMe MyName, MyNumber
- Example Function Call with multiple input parameters and multiple return values:
- MyName, MyNumber = Demo.DB.GetMe MyAlias, MyVal
- Lists of Field names are space separated
- Some Work Query command parameters can accept a source of either a Work Query Field name or a text literal.
Text literals in these cases are prefixed with a backtick ` character. See Using the Backtick ` for more information
Procedures
All executable code in Moxie.Build is stored in Procedures, each with a unique name, in the Database Tables. There are many different types of Procedures, each with a specific purpose, and are described in detail on the Types of Procedures page.
Memory Scope
Memory scopes in Moxie.Build are called Queries. Each Query may contain zero or more Fields, and one or more Records; similar to a table structure. There is always at least one Record, even if that Record only contains blank Fields. It is valid to conceptually think of a Query as an object; under the hood it is. A Procedure may use up to 64 queries per instance at a time. One of these Queries will be set as the current Top Query, and one of these Queries will be set as the current Work Query.
To better visualize what your memory scope looks like, you can use the ListQueries command followed by the HtmlTable command to display a list of all queries and their respective fields.
To help understand memory usage: The $MaxMem builtin value returns the current maximum memory usage of the process so far and more details can be loaded using the LoadMemUsage command. If the LogMOX Moxie.cfg option is set, the increase in $MaxMem during compilation and running is logged. When using the TRON command, the current value of $MaxMem is shown on each line. Note that in a multi-threaded system like Moxie.Build, the MaxMem value is shared by all threads, and multiple threads running at the same time can all contribute to any growth in MaxMem. When troubleshooting excessive memory usage, always test offline with a single user.
Procedures
All Procedures (other than Includes) start with two queries, named Input and Output. What these Queries contain at the start of a Procedure is described in further detail on the page for each Procedure Type.
Private Methods & Functions
Within a Procedure, each Private Method/Function starts two Queries, named Me.Input and Me.Output.
Me.Input
- Me.Input contains the parameters for the Method/Function (if any)
- When a Method/Function exits, the Me.Input Query is deleted
Me.Output
- Me.Output is initially blank for Methods/Functions
- When a Method exits, the Me.Output Query continues to exist by its fully qualified name of MethodName.Output and is usable until manually deleted
- When a Function exits, the Me.Output Query is used by Moxie.Build to pass the return value(s) to the caller and is then deleted
Top Query & Work Query
The Top Query and Work Query are how you select which Query objects are referenced line by line. This context saves typing the name of an object in front of every line of code.
Some examples to illustrate:
- Instead of typing
obj.Field1 = obj.Field2 + obj.Field3
we simply type Field1 = Field2 + Field3
- Instead of typing
oWork.LoadTable("Example")
we simply type LoadTable "Example"
Usage:
- The Top Query is responsible for program flow control, and single-record logic and output. It is the equivalent of local scope variables in other languages
- The Input Query is set by default as the Top Query when a Procedure starts
- The Me.Input Query is by default set as the Top Query when a Private Method/Function starts
- The Work Query is responsible for database operations, and is focused on multi-record logic and output. It is the equivalent of a two-dimensional array or object
- The Output Query is set by default as the Work Query when a Procedure starts
- The Me.Output Query is by default set as the Work Query when a Private Method/Function starts
Text Operators
- = Assignment of a value, field, or expression. An expression should not be wrapped in ( ) itself but may use ( ) for sub-expressions
- =@ Assignment of result of expression stored in a field
- | Assign a piped field or an expression from the Work Query. The value from the first Record in the Query is used
- | "QueryName" | Assign a piped field or an expression from a specifically named Query
See also the [Pull] and Pull commands to copy multiple fields
- " Start and end of text literal
- "" Embedded double quote within a text literal
- "` Start of text literal for a Work Query command parameter that accepts a field name or a text literal
e.g. "`My Name". See Using the Backtick ` for more information
- ` Field name prefix for a Top Query Field that contains a text literal when used with a Work Query command parameter that accepts either a field name or a text literal.
e.g. `FirstName. See Using the Backtick ` for more information
- & Text concatenation
- && Text concatenation with an added space between the items
- &= Concatenation of assignment
- &&= Concatenation of assignment with an added space between the items
- ? Pick first value: Space separated field list and the first field with any value will be assigned
- Within If and Select Conditions
- = Equals (case insensitive)
- === Equals (case sensitive)
- <> Does not equal (case insensitive)
- !== Does not equal (case sensitive)
- < Alpha less than (case insensitive)
- > Alpha greater than (case insensitive)
- <= Alpha less than or equal to (case insensitive)
- => Alpha greater than or equal to (case insensitive)
- _=_ Contains text literal (case insensitive)
- _===_ Contains text literal (case sensitive)
- _=*_ Contains at least one matching character (case sensitive, ANSI)
- _<>_ Does not contain text literal (case insensitive)
- _!==_ Does not contain text literal (case sensitive)
- _<>*_ Does not contain at least one matching character (case sensitive, ANSI)
Math Operators
- = Assignment of a value, field, or an expression. An expression should not be wrapped in ( ) itself, but may use ( ) for sub-expressions
- =@ Assignment of result of expression stored in a field
- += Addition of assignment
- + Addition
- - Subtraction
- * Multiplication
- / Floating point division
- \ Integer division without rounding
- ^ Exponent
- mod Modulus (remainder)
- Within If and Select Conditions
- == Numeric equals
- <<>> Does not numerically equal
- << Numeric less than
- >> Numeric greater than
- <<== Numeric less than or equal to
- ==>> Numeric greater than or equal to
All math inputs are cleaned up using the following rules:
- If the input contains a | character, the | character and everything after it is discarded
- Only the characters of -.0123456789 are kept, all other characters are discarded
First Record Only Operators
In most use cases, the Top Query will only have one record in it. However, in atypical use cases with more than one record in the Top Query the assignments using any of the above Operators will assign the value to all records. If required for logic or optimization, the assignment may be limited to the first record only by instead using one of the following operators: ==, +==, &==, ==@, and ||
Operator Precedence
- ( ) are the only operators that affect precedence, causing the sub-expression to be solved. All other operators are executed from left to right
- Text expressions may include math sub-expressions wrapped in ( )
- Math expressions may not include text sub-expressions.
Global Glyphicons & PNG Icons
In any output to the end user, regardless of source, and including text literals within MOX code, you can make use of the Template system's Glyphicons shorthand. The available Glyphicons are those of Bootstrap V3. Note the Bootstrap documentation calls for a space between a Glyphicon and any text.
Instead of using the full bootstrap HTML with class of:
<span class='glyphicon glyphicon-search' aria-hidden='true'></span>
Just use the following instead:
<? i search ?>
Also, PNG icons can be referenced using the following syntax:
<? ii Folder/FileName ?>
Which will be expanded into the following HTML:
<img class='FileIcon' src='/Icon/Folder/FileName.png' />
The value provided for FileName may not be larger than 64 bytes, and valid characters in the file name are limited to the following:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/-_.
The class of FileIcon is not defined anywhere by default, it is just there in case you need it. Moxie.Build does not come with any icons in the /Public/Icon folder; it is up to you to provide you own. Note that most PNG icon libraries that can be sourced will include different sized icons in different folders, therefore, selecting the icon of the size you want is part of the provided FileName.
Builtin Values
The following Text and Numeric Values are built into the language and may be used anywhere a Top Query Field may otherwise be used. When used by self as a value for a Work Query Parameter, they will need to be solved with ( ). Note that builtin text and number values all start with a leading $ or %, in contrast to builtin Top Query Functions that all end with a trailing $ or %
Request Query
The following values are built into the Request Query, and may be pulled into other queries to be utilized. It is not recommended to work with these values in the Request Query itself.
- Head. All HTTP Headers start with this prefix
- Cookie. All HTTP Cookies start with this prefix
- Req.Addr IP Address of client
- Req.Accept HTTP Accept header value
- Req.AccJson Accept is set to JSON only
- Req.Body HTTP Post Body, up to Cfg RAMRecvSize
- Req.Boundary HTTP Post Body Boundary
- Req.Category If page is a Category, the Alias of
- Req.ClientRecv Bytes Received by Server so far
- Req.ClientSent Bytes Send by Server so far
- Req.Completed Connections Closed by Server so far
- Req.CurPage Current Page File usage
- Req.CurWork Current Working Set size
- Req.Current Current Connections Open on Server
- Req.Country Country of IP per Cfg CountryInfo
- Req.Details Raw copy of HTTP Headers
- Req.FileName Name of file from /Recv
- Req.FileSize Size of file in /Recv
- Req.HasFile Is true if file data in /Recv
- Req.Hits Number of Requests to Server so far
- Req.Host Request Host Header value
- Req.IsCmdMox Set if running .mox file via cmd
- Req.IsDelete Set if Request mode set to Delete
- Req.IsGet Set if Request mode set to Get
- Req.IsJson Set if Content-Type is application/json
- Req.IsPost Set if Request mode set to Post
- Req.IsPut Set if Request mode set to Put
- Req.Lang Current client Language
- Req.Mode Request mode, such as Get or Post
- Req.PageFaults Number of Page Faults so far
- Req.Path Request path, no parameter, no leading /
- Req.Path1 First path level, parsed by /
- Req.Path2 to Req.Path7 Additional levels
- Req.PathBase Path without params, but preserves /Admin Report/Action params, and will always end with ? or &
- Req.PathWithParams Full URL, with leading /
- Req.PeakPage Highest Page File usage so far
- Req.PeakWork Highest Working Set size so far
- Req.Peek Highest Current Connections count so far
- Req.Port Server side completion port number
- Req.Post If page is a Post, the Alias of
- Req.Protocol Request protocol, such as http or https
- Req.RelayHttpsHost Cfg RelayHttpsHost
- Req.ServerAddr IP Address Server is listening on
- Req.ServerHttpPort HTTP Port Server
- Req.ServerHttpsPort HTTPS Port Server
- Req.Type Set to Content-Type
- Req.Unique Unique cookie value per visitor
|
Text Values
- $B ASCII 6 (internal flag for DB Backfill fields)
- $Br HTML line break < br/ > (no spaces)
- $Cr ASCII 13 (carriage return)
- $CrLf ASCII 13, 10 (carriage return, line feed)
- $CTID Moxie spec. time ordered unique id
- $CUID Moxie spec. unique id
- $DQ ASCII 34 (double quote)
- $Day Day of the month, 2 digits
- $DayOfWeek Sunday, Monday, etc.
- $Delimiters ASCII 0 to 7 (4 and 5 are user defined)
- $F ASCII 1 (internal DB field delimiter)
- $Greg Day as a Gregorian number
- $Gt ASCII 62 (greater than)
- $GUID Microsoft spec. unique id
- $I ASCII 2 (item separated in field data or #Attr list)
- $JNull ASCII 3 (Used to indicate a Null value instead of a blank string in MOX for JSON)
- $Lf ASCII 10 (line feed)
- $Lt ASCII 60 (less than)
- $MaxMem Maximum Memory of Process
- $Month Month of the year, 2 digits
- $NbSp HTML non-breaking space
- $Now YYYY-MM-DD HH:MM:SS
- Display data created date and time in the above format.
- $NowFile YYYY-MM-DD-HHMMSS
- $NowX YYYY-MM-DD HH:MM:SS.sss
- Display existing data modified date and time in the above format.
- $NowXFile YYYY-MM-DD-HHMMSSsss
- $Null ASCII 0 (null)
- $QCQ ASCII 34, 44, 24 (dq comma dq)
- $R ASCII 0 (internal DB record delimiter)
- $RootPath Full disk path to DBStore folder
- $SQ ASCII 39 (single quote)
- $SessionGroupTypes $I separated list
- $SessionID Unique session id for logged in user
- $SessionIsBad Contains reason session isn't good
- $SessionName FirstName && LastName
- $SessionTable eg. MemTab.Person
- $SessionUser Alias of user in $SessionTable
- $Spc ASCII 32 (space)
- $Tab ASCII 9 (tab)
- $Time HH:MM:SS
- $Timer CPU Counter, accurate to 0.001s
- $Today YYYY-MM-DD
- $ValidAlias Characters valid for a DB Record Alias
- $ValidDBField Characters valid for a DB Field Name
- $ValidTable Characters valid for a DB Table Name
- $Version Currently-running version of Moxie.Build
- $WhiteSpace ASCII 32, 13, 10, 9 (space, crlf, tab)
- $Year YYYY
- $XmlHead Shorthand for XML header string, UTF-8
|
Numeric Values
- %Greg Today as a Gregorian number
- %MaxMem Maximum Memory of Process
- %Month Month of the year, 2 digits
- %NDay Day of the month, 2 digits
- %NDayOfWeek Day of the week, Sunday = 1
- %Now YYYYMMDDHHMMSS
- %NowX YYYYMMDDHHMMSSss
- %Pi 3.14159265358979323
- %Time HHMMSS
- %Timer CPU Counter, accurate to 0.001s
- %Today YYYYMMDD
- %Year YYYY
|
Some Work Query command parameters can accept a source of either a Work Query Field name or a text literal. Text literals in these cases are prefixed with a backtick ` character.
Read more...