Documentation
Everything you need to know about Mad Sam Notation.
Getting Started
Install the MSN CLI globally:
npm install -g @madsn/cliOr add the parser to your project:
npm install @madsn/parserCompile an MSN file to JSON:
msn compile config.msn
msn compile config.msn -o config.jsonBasic Syntax
MSN uses dashes to indicate hierarchy depth. One dash - means top level, two dashes -- for the next level, and so on.
Key-value pairs:
- name: my-app
- version: 1.0.0
- private: trueCompiles to:
{
"name": "my-app",
"version": "1.0.0",
"private": true
}Nesting
Increase the number of dashes to nest objects:
- server
-- host: localhost
-- port: 3000
-- ssl
--- enabled: true
--- key: /path/to/key.pemCompiles to:
{
"server": {
"host": "localhost",
"port": 3000,
"ssl": {
"enabled": true,
"key": "/path/to/key.pem"
}
}
}There is no limit to nesting depth. Just keep adding dashes.
Arrays
Use an asterisk * to create array items:
- colors
-- * red
-- * green
-- * blueCompiles to:
{
"colors": ["red", "green", "blue"]
}Array objects — items in arrays that have properties:
- users
-- *
--- name: Alice
--- role: admin
-- *
--- name: Bob
--- role: userCompiles to:
{
"users": [
{ "name": "Alice", "role": "admin" },
{ "name": "Bob", "role": "user" }
]
}Multiline Values
Use | for literal multiline (preserves newlines) and > for folded multiline (joins with spaces):
Literal block (|):
- description: |
This is line one.
This is line two.
This is line three.Produces: "This is line one.\nThis is line two.\nThis is line three."
Folded block (>):
- description: >
This is a long paragraph
that will be joined into
a single line with spaces.Produces: "This is a long paragraph that will be joined into a single line with spaces."
Type Inference
MSN automatically infers types from values:
|-------|------|-------------|
Wrap a numeric value in quotes to force it to be a string: "3000".
CLI Reference
Commands:
|---------|-------------|
Flags:
|------|-------------|
API Reference
Quick start:
import { compile, compileToString } from '@madsn/parser';
// Get a JavaScript object
const obj = compile(`
- name: my-app
- port: 3000
`);
// Get formatted JSON string
const json = compileToString(`
- name: my-app
- port: 3000
`, 2);Classes:
- Lexer — Tokenizes MSN source into a token stream
- Parser — Builds an AST from tokens
- Compiler — Converts AST to JSON
Validator:
import { validate } from '@madsn/validator';
const errors = validate(source);Formatter:
import { format } from '@madsn/formatter';
const formatted = format(source);
Comments
Lines starting with
#are comments and are ignored during compilation: