Skip to content

Vyasa Grammar

This document describes the formal grammar of the Vyasa language. It serves as the authoritative reference for parser implementation and tooling.

The grammar is specified using Extended Backus-Naur Form (EBNF).

/* Basic Character Sets */
Digit ::= [0-9]
Alpha ::= [a-zA-Z]
Alphanumeric ::= Alpha | Digit
/* Identifiers */
/* Used for command names, attribute keys */
Identifier ::= Alpha ( Alphanumeric | "_" | "-" )*
/* Values */
/* Used for command arguments, unquoted attribute values */
ValueString ::= ( Alphanumeric | "_" | "." | ":" | "-" | "/" )+
Document ::= Node*
Node ::= Comment
| Command
| SegmentBreak
| Text
/* Comments */
Comment ::= LineComment | BlockComment
LineComment ::= "`" (" " | "\t") [^\n]*
BlockComment ::= "`[" .*? "]"
/* Commands */
Command ::= "`" Identifier
(Space Argument)?
Space? Delimiter?
Space? Attributes?
Space? Children?
Argument ::= ValueString
Delimiter ::= ";" Identifier
/* Attributes */
Attributes ::= "{" AttributeMap "}"
AttributeMap ::= (Pair (","? Space? Pair)*)? ","?
Pair ::= Identifier Space? "=" Space? Value
Value ::= QuotedString | NestedValue | ValueString
QuotedString ::= '"' ( [^"\\] | "\\" . )* '"'
NestedValue ::= "{" [^}]* "}"
/* Children Block */
Children ::= "[" Node* Terminator? "]"
Terminator ::= "]" Identifier /* Must match the Delimiter Identifier */
/* Structural Elements */
SegmentBreak ::= "|"
/* Text */
Text ::= ( [^`|\[\]\\] | EscapedChar )+
EscapedChar ::= "\\" .

Vyasa reserves the characters `, |, [, ], \, {, } for syntax.

  • Escaping: Any character can be treated as literal text by prefixing it with a backslash \.

    • Example: \` becomes a literal backtick.
    • Example: \| becomes a literal pipe.
  • Robustness: The parser attempts to be robust. If a special character (like ` or ]) is encountered in a context where it does not form a valid command or structure, it is treated as literal text.

    • Example: `( parses as a literal backtick followed by (.
    • Note: A backtick followed by a space or tab is parsed as a Comment.
    • Example: ` This is a comment
`preface { title="Foreword" } [
This is the preface text.
]
`chapter 1 { title="Obsfervation" }
`div;mybox [
Content inside the box.
]mybox
`set entities {
krishna={ type="person", bio="The Supreme Personality of Godhead" }
}