Library to parse a specific syntax created to improve readability BRMS pronounced "Brems" stands for "Block Relation Mapping Syntax"
The BRMS Parser is a command-line tool and library designed to parse and interpret files written in the Block Relation Mapping Syntax (BRMS). It extracts and structures relationships between blocks and entities, and supports exclusions for fine-grained configuration of mappings.
- Parse BRMS files to extract:
- Blocks: Mappings between source and destination blocks.
- Entities: Mappings between source and destination entities.
- Exclusions: Explicitly excluded blocks or entities.
- Dynamic path resolution for Windows and Unix-like systems.
- Robust error handling with informative log levels (
INFO,WARN,ERROR). - Multiplatform support for Windows and Unix.
- Go 1.20+
- A valid BRMS configuration file (e.g.,
subgroups.brms).
git clone https://github.com/Caezarr-OSS/brms-parser.git
cd brms-parsergo build -o brms_parser.exe ./cmd/main.gogo build -o brms_parser ./cmd/main.go./brms_parser- Place your BRMS file in the appropriate directory (e.g.,
config/examples/). - Update the path in the
main.gofile or pass it dynamically. - Run the program:
go run ./cmd/main.go
[block_a/sub_block_1|block_b/sub_block_2]
entity_a|entity_b
entity_c|entity_d
[block_c|block_d]
sub_block_x/entity_e|sub_block_y/entity_f
Using file path: C:\path\to\config\examples\subgroups.brms
[INFO] Line 1: Parsed block 'block_a/sub_block_1|block_b/sub_block_2'
[INFO] Line 2: Parsed entity 'entity_a|entity_b'
[INFO] Line 3: Parsed entity 'entity_c|entity_d'
[INFO] Line 5: Parsed block 'block_c|block_d'
[INFO] Line 6: Parsed entity 'sub_block_x/entity_e|sub_block_y/entity_f'
Blocks:
block_a/sub_block_1 -> block_b/sub_block_2
block_c -> block_d
Entities:
entity_a -> entity_b
entity_c -> entity_d
sub_block_x/entity_e -> sub_block_y/entity_f
Exclusions:
Blocks represent mappings between source and destination block names. A block is defined in BRMS as:
[source_block:destination_block]
- Source Block: The name of the block in the source.
- Destination Block: The name of the block in the destination.
- Example:
This means
block_a/sub_block_1 -> block_b/sub_block_2block_a/sub_block_1in the source maps toblock_b/sub_block_2in the destination.
Entities are mappings within a block that specify the source and destination of individual items.
- An entity is defined under a block mapping as:
source_entity:destination_entity - Source Entity: The name of the item in the source.
- Destination Entity: The name of the item in the destination.
- Example:
This means
entity_a -> entity_bentity_ain the source maps toentity_bin the destination.
Exclusions define blocks or entities that should be ignored during processing.
- A block exclusion is defined as:
[source_block:] - An entity exclusion is defined as:
source_entity: - Example:
This means
[block_a:] entity_a:block_aandentity_awill be excluded from processing.
-
Log Levels:
INFO: Displays parsing progress and details.WARN: Highlights potential issues like excessive indentation.ERROR: Reports critical parsing failures.
-
Error Handling:
- Invalid BRMS syntax is detected and logged with line numbers.
- Missing files or inaccessible paths trigger descriptive errors.
- Keep your BRMS files well-indented for better readability
- Use comments (#) to document complex mappings
- Avoid unnecessary spaces at the beginning and end of lines
- Organize your blocks in a logical and coherent manner
- Use descriptive names for your blocks and entities
BRMS files use the .brms extension and follow a specific syntax:
- Lines starting with
#are comments - Blocks are defined between brackets
[] - Relations use the
|character as a separator (configurable viaSetSeparator) - Hierarchical paths use
/as a separator
[block_a/sub_block_1|block_b/sub_block_2]
entity_a|entity_b
entity_c|entity_d
[block_c|block_d]
sub_block_x/entity_e|sub_block_y/entity_f
You can change the default separator ("|") using the SetSeparator method:
parser := brms.NewParser("config.brms", brms.LogLevelInfo)
parser.SetSeparator("->") // Change separator to ->- Invalid Syntax: Check that your blocks are properly defined with brackets
- Invalid Characters: Avoid special characters in names
- Incorrect Indentation: Remove spaces/tabs at the beginning of lines
Error at line X: line outside of block section: The line is not in a valid blockError at line X: invalid format with multiple ':': Too many separators on one line
- The parser loads the entire file into memory
- Parsing complexity is linear O(n) where n is the number of lines
- For large files, ensure you have sufficient memory available
import "brms_parser/brms"
parser := brms.NewParser("config.brms", brms.LogLevelInfo)
parsed, err := parser.Parse()
if err != nil {
log.Fatal(err)
}# Parse with detailed logging
./brms_parser -log=info -file=config.brms
# Parse without logging
./brms_parser -log=error -file=config.brmsWe welcome contributions to improve the BRMS Parser. Feel free to submit issues or pull requests on the repository.
This project is licensed under the Apache 2.0. See the LICENSE file for details.
