Skip to content

Bear Markup Language ver 5.0

Misaki Bear edited this page Sep 25, 2022 · 5 revisions

Overview

A typical BearML config file is as below.

[desc]
description: @
  File for chain stores.
  Contains stock data.
|

# stock for all stores
stock: $
  phones: $
    apple phone: 2
    melon phone: 10

> central store <
product list:
  - fruits
  - phones

  > phones <
  apple phone: 2
  melon phone: 10

Elements

BearML has 6 elements: root block, block, block key, key, empty, basic, list, dictionary.
Block key can contain comments.
Key can contain alias names and comments.

Root block

A typical root block is as below:

key a: value

> a block <
key: abc

Root block can be said to be the config file itself.
The key-value pairs in root block should be located above any blocks that owned by root block.
Blocks owned by the root block do not need indentation and root block do not accept any nested block.
The following configs are invalid.

key a: value

  > a block <
  key: abc
Error: BearMarkupLanguage.Interpretation.Helpers.InvalidFormatException: Line 3  Character num 1:
  > a block <
^ Invalid line.

Block

A typical block is as below:

#  comment1
 #comment2
> a block <
key a: value

  > a nested block <
  # comment
  key: abc

key b: value

Block key

  • Block key's identifiers are '>' and '<'.
  • '>' must be placed at the beginning of the line.
  • White spaces at start and end will be ignored.
  • Block key can contain any characters, but it cannot be empty or blank.
  • Keys of blocks with the same parent must be unique.
  • Special characters such as '\', '\n' should be escaped.

':' should be escaped too. The follow case will be interpreted as a key.
Key name: > a block, value: <.

> a block: <

Comments identifier is '#'.
Here are the comments for the block key above:

  comment1
comment2

Nested block

> a block <
  > a nested block <
  # comment
  key: abc

Nested blocks require indentation(include comments).
The following configs are invalid.

> a block <
  > a nested block <
# comment
  key: abc
Error: BearMarkupLanguage.Interpretation.Helpers.InvalidFormatException: Line 4  Character num 1:
  key: abc
^ Invalid line.

Key-value pair

A typical key-value pair is as below:

# a comment
[alias_a|alias_b]
a key: a value
  • Key aliases and comments are optional.
  • The order of key aliases and comments cannot be changed.

Comment

A typical comment is as below:

# a comment
  • Comment's identifier is '#'.
  • Comments are recognized as keys' comments only by placing them directly above the key or key alias.

Key alias

A typical key alias is as below:

[alias_a|alias_b]
  • Key alias's indentifiers are '[' and ']'.
  • The identifier '[' must be placed at the beginning of the line.
  • Key alias cannot be empty or blank.
  • White spaces at start and end will be ignored.
  • Key alias will shadow the key with the same name that appears later.
  • Key alias name must match the following regex.
    @?[a-zA-Z_][a-zA-Z_0-9]*.

key

A typical key is as below:

a key: a value
  • Key's identifier is ':'.
  • Key name can contain any characters, but it cannot be empty or blank.
  • Key name must be unique in block.
  • Key's first character cannot be white space.
  • White spaces at end will be ignored.
  • Special characters such as '\', '\n' should be escaped.
  • ':' and '#' should be escaped too.

Value

BearML has 4 value types: empty, basic, list, dictionary.
Every value type has two forms: compact, expand.

Empty

Typical empty type are as below:

# compact-form
a key:

# expand-form
a key: @
|
  • Empty type refer to null object.
  • Compact-form allows value to be white spaces or empty.

Basic

Typical basic type are as below:

# compact-form
a key: hello\n goodbye

# expand-form
a key: @
  hello
   goodbye
|

Compact-form

  • Compact-form value can contain any characters except empty or white spaces.
  • White spaces at start and end will be ignored.
  • Special characters such as '\', '\n' should be escaped.

Expand-form

  • Expand-form value's identifiers are '@' and '|'.
  • Expand-form values require indentation, and indentation is ignored during interpretation.
  • Expand-form value can contain any characters. Empty or White spaces will be recogonized.

Expand-form basic value require to be closed by '|'.
The following configs are invalid. The first line will be interpreted as an compact form value as '@'.

a key: @
  hello
Error: BearMarkupLanguage.Interpretation.Helpers.InvalidFormatException: Line 2  Character num 1:
  hello
^ Invalid line.

List

Typical list type are as below:

# compact-form
a key:
  [["1.1", "2.11"], {"apple":"1.15", "banana":"0.2"}]

# expand-form
a key: 
  - 
    - 1.1
    - 2.11
  - $
    apple: 1.15
    banana: 0.2

Compact-form

  • Compact-form list's nodes identifiers are '[' and ']'.
  • Compact-form list should be in one line and should have indentation.
  • Compact-form list should be placed below key line.
  • Every value in list should be surrounded by "".
  • Special characters in every basic value such as '\', '\n' should be escaped.
  • '"'should be escaped too.

Expand-form

  • Expand-form list's nodes identifier is '-'
  • Expand-form list should be placed below key line.
  • Every node should have indentation.
  • Expand-form list cannot display empty list.
    Such lists should be displayed in compact-form.

Empty(null) value is allowed.

# compact-form
a key:
  ["abc", null]

# expand-form
a key:
  - abc
  - 

Dictionary

Typical basic type are as below:

# compact-form
a key:
  {"apple":["1.1", "2.5"], "banana":["0.2"]}

# expand-form
a key: $
  apple:
    - 1.1
    - 2.5
  banana:
    - 0.2

Compact-form

  • Compact-form dictionary's nodes identifiers are '{' and '}'.
  • Compact-form dictionary should be in one line and should have indentation.
  • Compact-form dictionary should be placed below key line.
  • Every key and basic value in dictionary should be surrounded by "" and be splitted by ':'.
  • Special characters in every key and basic value such as '\', '\n' should be escaped.
  • '"'should be escaped too.

Expand-form

  • Expand-form dictionary's identifier is '$'.
  • Expand-form dictionary should be placed below key line.
  • Every node should have indentation.
  • Special characters in key such as '\', '\n' should be escaped.
  • Expand-form dictionary cannot display neither empty dictionary nor key that contains white space at start or end.
    Such dictionaries should be displayed in compact-form.

Compact-form dictionary does not require identifier '$'.
The following configs are interpreted to an unexpected result.
Key name: {"abc", value: null}.

a key: $
  {"abc": null}

Empty(null) value is allowed.

# compact-form
a key:
  {"abc": null}

# expand-form - style 1
a key: $
  abc: 

# expand-form - style 2
a key: $
  abc: @
  |