Field Description Language¶
The Field Description Language is a Domain Specific Language (DSL) that is used to
define the type and structure of field values. An FDL declaration consists of
one or more modifier entries separated by commas (,).
Syntax¶
dsl ::= modifier ("," modifier)*
modifier ::= type_modifier | form_modifier | flag | by_option
Python API¶
Users can create a sphinxnotes.render.Field from FDL and use it to parse
strings into sphinxnotes.render.Value:
>>> from sphinxnotes.render import Field
>>> Field.from_dsl('list of int').parse('1,2,3')
[1, 2, 3]
Type¶
A type modifier specifies the data type of a single (scalar) value.
Modifier |
Type |
Aliases |
Description |
|---|---|---|---|
|
|
Boolean: |
|
|
|
Integer |
|
|
|
Floating-point number |
|
|
|
String. If it looks like a Python literal (e.g., |
Examples:
DSL |
Input |
Result |
|
|
|
|
|
|
Form¶
A form modifier specifies a container type with its element type, using
<form> of <type> syntax.
Modifier |
Container |
Separator |
Description |
|---|---|---|---|
|
|
Comma-separated list |
|
|
|
Newline-separated list |
|
|
whitespace |
Whitespace-separated list |
|
|
whitespace |
Whitespace-separated set (unique values) |
Examples:
DSL |
Input |
Result |
|
|
|
|
|
|
|
|
|
Flag¶
A flag is a boolean modifier that can be either on or off.
Every flag is available as an attribute of the Field.
For example, we have a “required” flag registered, and we can access Field.required
attribute.
Modifier |
Aliases |
Default |
Description |
|---|---|---|---|
|
|
|
Field must have a value |
Examples:
int, required
By-Option¶
A by-option is a key-value modifier with the syntax <name> by <value>.
Every by-option is available as an attribute of the Field.
For example, we have a “sep” by-option registered, and we can get the separator
from Field.sep attribute.
Built-in by-options:
Modifier |
Type |
Description |
|---|---|---|
|
Custom separator for value form. Implies |
Examples:
DSL |
Input |
Result |
|
|
|
|
|
|