ARMR Language Syntax
The structure of the ARMR language and syntax is loosely based on the YAML syntax. Users familiar with YAML and its syntax will be comfortable with programming ARMR Mod. ARMR Mods use a file
extension of .armr
. The content of the file is plain-text and can be written and viewed in any text editor.
The following is a high-level overview of what the ARMR language syntax looks like.
app("Security Rules"):
requires(version: ARMR/2.7)
http("An ARMR HTTP Rule"):
...
endhttp
marshal("An ARMR Marshal Rule"):
...
endmarshal
dns("An ARMR DNS Rule"):
...
enddns
socket("An ARMR Socket Rule"):
...
endsocket
filesystem("An ARMR FileSystem Rule"):
...
endfilesystem
sql("An ARMR SQL Rule"):
...
endsql
library("An ARMR Library Rule"):
...
endlibrary
patch("An ARMR Patch Rule"):
...
endpatch
endapp
Studying the syntax at a high-level, we can see a pattern of block declarations, where each block has an opening declaration, and an ending declaration. Blocks can also take statements, which are child
components of each block. Statements are used to describe configuration for the block.
Block
All blocks must abide by the following rules,
-
Blocks must have an opening and closing declaration.
-
The opening declaration starts with the
<block-name>
. -
Followed by a unique quoted string inside parenthesis to name the block.
-
Followed by a colon, which indicates to the ARMR engine that the block is open and should expect a closing declaration.
-
Each proceeding line after a block is opened will be a statement of that block until it is closed.
-
Each open block must be closed with the keyword
end<block-name>
.
Block Example
http("An ARMR HTTP Rule"):
...
endhttp
Statement
All statements must abide by the following rules,
-
A statement is a declaration that is not open or closed.
-
Statements do not have a colon after the parenthesis.
-
All the configuration for the statement exists within the parenthesis.
-
The configuration is made up of
key:value
pairs. -
Some
key:value
pairs may be optional. If optional, they can be omitted. -
If only one
key:value
pair is mandatory, for most cases it is not necessary to state the key, and just pass the value. Otherwise it is recommended to provide both the key and the value. -
Some values are
keywords
, and do not need to be quoted. It is only necessary to quote strings that are user defined, such as a file path or the name of a parameter in a HTTP request. -
The order of the
key:value
pairs is not strict and can be presented in any order.
Statement Example
requires(version: ARMR/2.7)
Types Of Values
Values can be any of these types,
-
keyword: an unquoted string that has a defined meaning within the ARMR language.
-
string: any sequence of characters surrounded by double quotes. eg:
"an example string"
. -
integer: an unquoted whole number without decimal point.
-
float: an unquoted number with decimal point.
-
boolean: an unquoted
true
orfalse
. The value is not case-sensitive. -
dictionary: a collection of different
key:value
types separated by commas, and encapsulated within curly brackets. e.g.{"personal data form", id: 32, name: "John"}
. -
list: a collection of values of the same type, separated by commas, and encapsulated within square brackets. e.g.
[2, 3, 32, 100]
. -
A dictionary and a list value can contain other dictionaries and lists inside them.
Comments
It is possible to include comments in an ARMR file. There are two scenarios to mention,
-
The hash symbol (also known as the pound symbol)
#
can be used throughout the entire ARMR File. This is used for commenting on a per-line basis. There is no block comment equivalent. -
When inside an
app
declaration, it is possible to use a double forward-slash//
for a single line comment or the forward-slash with star/* */
for block comments.
# This kind of comment
# can be used anywhere
# in an ARMR File.
app("Security Rules"):
requires(version: "ARMR/2.0")
// This is a line comment
// and can be used within
// an ARMR App.
http("An ARMR HTTP Rule"):
...
endhttp
/_
This is a block comment
that can be used within
an ARMR App.
_/
endapp
Escape Character
Any character is legal as part of an ARMR string value, including double-quotes, as long as they are escaped. Escaping can be achieved by using the back-slash character \
. A backslash literal should also be escaped with a backslash to distinguish it from an escape character. Not escaping backslashes \ or double quotes " could lead to unexpected behavior.
Valid | Invalid |
---|---|
"hello\\ world\"" | "hello world\" |
"hello w"rld" | |
"hello w\\"orld" |
The following ARMR Mod name is valid,
app("App name with \\ and \""):
endapp
The following ARMR Mod name is invalid,
app("App name ending slash\"):
endapp
Windows Paths
The backslashes in Windows paths should be escaped. The following Windows path is valid,
process("Protect executable in a specific directory"):
execute("C:\\Windows\\\*")
The following Windows path is invalid,
process("Protect executable in a specific directory"):
execute("C:\Windows\*")
Formatting
Blocks do not need to be separated by new line characters, meaning that the entire contents of an ARMR file could be written on a single line. However, it is strongly recommended that users do not write rules in this fashion as this will make it extremely difficult to read.
app("Security Rules"):requires(version: ARMR/2.7)endapp
Blocks, components, and keywords must be declared in lowercase as the parser is case-sensitive. The following will not be allowed to load. Notice the malformed ApP
and EnDapp
.
app("Security Rules"):
requires (version: ARMR/2.7)
endapp