VZparse v1.0
VZparse - A minimal, human-readable, machine-parsable configuration format with built-in schema validation
By VZparse Contributors.
Objectives
- VZparse aims to be a minimal configuration format.
- VZparse should be easily readable by humans.
- VZparse should be easily parsed by machines.
- VZparse should support schema validation.
- VZparse should support template strings and imports.
Spec
- VZparse is case-sensitive.
- A VZparse file must be a valid UTF-8 encoded Unicode document.
- Whitespace means a space (0x20) or a tab (0x09).
- Newline means LF (0x0A) or CRLF (0x0D 0x0A).
Whitespaces and newlines are allowed to separate values and structural characters.
Comment
A hash symbol marks the rest of the line as a comment, except when inside a string.
# Comment before the object
{
foo: "value" # Inline comment
bar: "# This is not a comment"
}Control characters other than tab (U+0000 to U+0008, U+000A to U+001F, U+007F) are not permitted in comments.
Values
A VZparse value is an object, array, string, multiline string, integer, float, boolean, null, template string, or embedded query.
Array
An array structure is represented as [ ] square brackets surrounding zero or more values. Values are separated by , comma or newlines. There is no requirement that the values in an array be of the same type.
[
"red"
"yellow"
"green"
]Commas are optional. Trailing comma is allowed.
[ "red", "yellow", "green", ]Objects
An object is an ordered set of key/value pairs. An object begins with { left brace and ends with } right brace. Each key is followed by : colon and the key/value pairs are separated by , comma or newlines.
{
key: "value"
"quoted key": "value"
}Commas are optional. Trailing comma is allowed.
{
foo: "value",
bar: "value",
}Duplicate keys are not allowed within an object.
Keys
A key may be either an identifier or a quoted string.
Identifier keys may only contain A-Z a-z letters, 0-9 digits, _ underscores, and - hyphens.
Identifier keys are allowed to be composed of only digits, (for example, 1234), but are always interpreted as strings.
Quoted string keys follow the exact same rules as strings and allow you to use a much broader set of key names.
An identifier key must be non-empty, but an empty quoted string key is allowed.
String
Strings are surrounded by " quotation marks. Any Unicode character may be used except those that must be escaped: quotation mark, backslash, and the control characters other than tab (U+0000 to U+0008, U+000A to U+001F, U+007F).
"String with a \"nested\" string, \t tab, 😁 emoji, and \u{10FFFF} sequence"For convenience, some popular characters have a compact escape sequence.
| Escape | Name | Unicode |
|---|---|---|
\t | tab | U+0009 |
\n | linefeed | U+000A |
\r | carriage return | U+000D |
\" | quote | U+0022 |
\\ | backslash | U+005C |
A Unicode character may be escaped with the \u{XXXXXX} form. The hexadecimal number can be from 1 to 6 digits long. The escape codes must be valid Unicode scalar values.
All other escape sequences not listed above are reserved; if they are used, VZparse should produce an error. All strings must contain only valid UTF-8 characters.
Multiline String
Multiline Strings use the | pipe character followed by optional metadata and newline. The content continues until a new key is encountered or end of file.
description: |
This is a multiline string.
It preserves formatting.
Even indentation!
code: |python
def hello():
print("Hello, VZparse!")
return True
config: |`json`
{
"key": "value",
"nested": {
"array": [1, 2, 3]
}
}Metadata can be:
- Identifier:
|markdown,|python,|yaml - Backtick quoted:
|json, `|`sql
The multiline string preserves relative indentation and removes common leading whitespace.
Integer
Integers are whole numbers. Negative numbers are prefixed with a minus sign. Leading zeros are not allowed. Plus sign is not allowed.
{
int1: 42
int2: -100
}Arbitrary 64-bit signed integers (from −2^63 to 2^63−1) should be accepted and handled losslessly. If an integer cannot be represented losslessly, an error must be thrown.
Float
Floats should be implemented as IEEE 754 binary64 values.
A float consists of an integer part (which follows the same rules as integer values) followed by a fractional part and/or an exponent part. If both a fractional part and an exponent part are present, the fractional part must precede the exponent part.
[
# fractional
1.0
3.1415
-0.01
# exponent
5e+22
1e06
-2E-2
# both
6.626e-34
]A fractional part is a decimal point followed by one or more digits.
An exponent part is an E (upper or lower case) followed by an integer part (which follows the same rules as integer values but may include leading zeros).
The decimal point, if used, must be surrounded by at least one digit on each side.
Boolean
Booleans are true and false. Always lowercase.
[ true, false ]Null
Represents the lack of a value. An object with some key and a null value is valid and different from not having that key in the object. Always lowercase.
nullTemplate Strings
Template Strings use ${variable} syntax for variable interpolation. They are surrounded by " quotation marks like regular strings.
{
user: {
name: "Alice"
role: "admin"
}
greeting: "Hello, ${user.name}! You are a ${user.role}."
api_url: "${api.baseUrl}/users/${user.id}"
}Template strings support dot notation for nested object access.
Import System
VZparse supports importing values from other files using the import statement.
import { database, logging } from "./config/shared.vz"
app: {
name: "MyApp"
...database
...logging
}The import syntax is:
import { key1, key2 } from "file.vz"import key from "file.vz"
Spread Operator
The spread operator ... allows merging objects from imported modules or context.
import { defaults } from "./defaults.vz"
production: {
...defaults
timeout: 60
host: "prod.example.com"
}Schema Validation
VZparse supports built-in schema validation using a schema object.
schema: {
id: "int(min:1,max:1000)!"
name: "string(minLength:3,maxLength:50)!"
email: "string(format:email)!"
age: "int(min:0,max:150)?"
status: "enum(active,inactive,pending)!"
}
id: 123
name: "John Doe"
email: "[email protected]"
age: 30
status: "active"Schema types:
int(min:1,max:100)- integer with constraintsstring(minLength:3,maxLength:50)- string with length constraintsstring(format:email)- string with format validationenum(value1,value2,value3)- enumerationbool- booleanarray- arrayobject- object
Modifiers:
!- required field?- optional field
Embedded Queries
VZparse supports embedded queries for external data sources.
users: @prisma.users.findMany({
where: {
active: true
}
})The syntax is @source.query where source is the data source identifier and query is the query expression.
Filename Extension
VZparse files should use the extension .vz.
MIME Type
When transferring VZparse files over the internet, the appropriate MIME type is application/vz.
ABNF Grammar
A formal description of VZparse's syntax in ABNF format.
; VZparse ABNF Grammar
; Based on RFC 5234
; Basic character definitions
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
DIGIT = %x30-39 ; 0-9
HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
SP = %x20 ; space
HTAB = %x09 ; horizontal tab
LF = %x0A ; linefeed
CR = %x0D ; carriage return
CRLF = CR LF ; Windows line ending
NL = LF / CRLF ; newline
WS = SP / HTAB ; whitespace
; Character classes
IDENTIFIER_CHAR = ALPHA / DIGIT / "_" / "-"
STRING_CHAR = %x20-21 / %x23-5B / %x5D-10FFFF ; any char except " and \
ESCAPE_CHAR = %x5C ; backslash
; Comments
COMMENT = "#" *(WS / %x21-7E) NL
; Whitespace handling
WS_OPT = *WS
WS_REQ = 1*WS
NL_OPT = *(NL / COMMENT)
; Identifiers
IDENTIFIER = 1*IDENTIFIER_CHAR
; Strings
ESCAPE_SEQ = ESCAPE_CHAR (
"t" / ; tab
"n" / ; newline
"r" / ; carriage return
"\"" / ; quote
ESCAPE_CHAR / ; backslash
"u{" 1*6HEXDIG "}" ; unicode escape
)
STRING_CONTENT = *(STRING_CHAR / ESCAPE_SEQ)
STRING = "\"" STRING_CONTENT "\""
; Multiline strings
MULTILINE_METADATA = (
IDENTIFIER / ; |markdown
"`" 1*IDENTIFIER_CHAR "`" ; |`json`
)
MULTILINE_START = "|" [MULTILINE_METADATA] NL
MULTILINE_CONTENT = *(%x20-10FFFF / NL)
MULTILINE_STRING = MULTILINE_START MULTILINE_CONTENT
; Template strings
TEMPLATE_VAR = "${" IDENTIFIER *(DOT IDENTIFIER) "}"
TEMPLATE_CONTENT = *(STRING_CHAR / ESCAPE_SEQ / TEMPLATE_VAR)
TEMPLATE_STRING = "\"" TEMPLATE_CONTENT "\""
; Numbers
INTEGER = ["-"] 1*DIGIT
FRACTION = "." 1*DIGIT
EXPONENT = ("e" / "E") ["+" / "-"] 1*DIGIT
FLOAT = INTEGER (FRACTION [EXPONENT] / EXPONENT)
; Literals
BOOLEAN = "true" / "false"
NULL = "null"
; Arrays
ARRAY_START = "[" WS_OPT
ARRAY_END = WS_OPT "]"
ARRAY_SEP = WS_OPT "," WS_OPT
ARRAY_ITEM = VALUE
ARRAY = ARRAY_START [ARRAY_ITEM *(ARRAY_SEP ARRAY_ITEM) [ARRAY_SEP]] ARRAY_END
; Objects
OBJECT_START = "{" WS_OPT
OBJECT_END = WS_OPT "}"
OBJECT_SEP = WS_OPT "," WS_OPT
OBJECT_KEY = IDENTIFIER / STRING
OBJECT_PAIR = OBJECT_KEY WS_OPT ":" WS_OPT VALUE
OBJECT = OBJECT_START [OBJECT_PAIR *(OBJECT_SEP OBJECT_PAIR) [OBJECT_SEP]] OBJECT_END
; Import statements
IMPORT_START = "import" WS_REQ
IMPORT_KEYS = "{" WS_OPT IDENTIFIER *(WS_OPT "," WS_OPT IDENTIFIER) WS_OPT "}" / IDENTIFIER
IMPORT_FROM = WS_REQ "from" WS_REQ STRING
IMPORT = IMPORT_START IMPORT_KEYS IMPORT_FROM NL
; Spread operator
SPREAD = "..." IDENTIFIER
; Embedded queries
EMBEDDED_QUERY = "@" IDENTIFIER *(%x20-10FFFF)
; Schema definitions
SCHEMA_TYPE = (
"int" [SCHEMA_CONSTRAINTS] /
"string" [SCHEMA_CONSTRAINTS] /
"bool" /
"array" /
"object" /
"enum" SCHEMA_CONSTRAINTS
)
SCHEMA_CONSTRAINTS = "(" SCHEMA_CONSTRAINT_LIST ")"
SCHEMA_CONSTRAINT_LIST = SCHEMA_CONSTRAINT *(WS_OPT "," WS_OPT SCHEMA_CONSTRAINT)
SCHEMA_CONSTRAINT = (
"min:" INTEGER /
"max:" INTEGER /
"minLength:" INTEGER /
"maxLength:" INTEGER /
"format:" IDENTIFIER /
IDENTIFIER *(WS_OPT "," WS_OPT IDENTIFIER) ; for enum values
)
SCHEMA_MODIFIER = "!" / "?"
SCHEMA_DEFINITION = SCHEMA_TYPE SCHEMA_MODIFIER
; Values
VALUE = (
STRING /
TEMPLATE_STRING /
MULTILINE_STRING /
INTEGER /
FLOAT /
BOOLEAN /
NULL /
ARRAY /
OBJECT /
SPREAD /
EMBEDDED_QUERY /
SCHEMA_DEFINITION
)
; Root document
DOCUMENT = NL_OPT *(IMPORT / OBJECT_PAIR) NL_OPT
; Entry point
vzparse = DOCUMENT