This document contains the official specifications for Cadey.
Cadey has a very simple and minimal syntax:
Name | Example | Explanation |
---|---|---|
Macro | [italic this will be italic] |
A macro, calls a function with passed arguments |
List | [: this is a list] |
A list of tokens |
Escaped List | [: all [italic tokens] are escaped :] |
A list, but all inner macros and lists are escaped |
Named parameter | :keyword value or [:keyword value] |
Named parameters, valid only in Macro blocks |
- A Macro starts with a [ and ends with a ], first token in the list is the function or macro name that will be called. All other tokens will be passed as arguments. First token must only contain alphanumeric characters, underscore or dash.Example:
[italic italic text]
The above example will call a function named italic, passing the following list of parameters:[" ", "italic", " ", "text"]
Whitespace tokens such as SPACE and NEWLINE will be a part of the parameters. - A list starts with [: and ends with ]. Macros in the list will run before the list is passed to a function.Example:
[: this is a list]
The above example translates to:[" ", "this", " ", "is", " ", "a", " ", "list"]
Whitespace tokens such as SPACE and NEWLINE will be a part of the list. - A escaped list starts with [: and ends with :]. All content will be escaped and considered as text.Example:
[: a list [italic text]:]
The above translates to:[" ", "a", " ", "list", " ", "[italic text]"]
- A named parameter starts with a : and a token of alphanumeric characters, underscores or dashes immediately after the colon. This token will be the name of the parameter, and the next token will be the value. Value can be a word (alphanumeric, underscores and dashes), a macro, a list, or a escaped list.Example:
[heading :size 1 This is a heading]
The above example will call a function named heading, passing the following as parameters:heading({ size: 1 }, [" ", "This", " ", "is", " ", "a", " ", "heading"])
A list can be used as a named parameter, in this case the named parameter starts with [: then a word as the name of the parameter, then one or several values for this parameter, then a ] to mark the end of the contents for this parameter.Example:[image [:alt A random image!] https://source.unsplash.com/random ]
The above will call a function named image, passing the following as parameters:image( { alt: [" ", "A", " ", "random", " ", "image!"] }, ["https://source.unsplash.com/random"] );
- Characters like : and [] can be escaped by using \.
- Order of parameters are preserved, however, order of named parameters are not. In other words, it does not matter where the named parameter is located, or if it's in between other (un-named) parameters.
- If several named parameters with the same name are passed to a Macro, the parameter passed to the function will be an array consisting of the values of each one of them.
Cadey recognizes the following tokens at lexing level.
This table is ordered by the precedence of the lexing rules.
Token name | Regex | Example | Explanation |
---|---|---|---|
escaped | /^\\./i |
\[ | Matches escaped characters |
keyowrd | /^:[a-z0-9.-]+/i |
:keyword | Matches keywords |
colon | /^:/ |
: | Matches a single colon character |
word | /^[^\[\] \n\r\\]+/ |
word | Matches a word (No [ or ] or \ or whitespaces) |
bracketLeft | /^\\\[/ |
[ | Matches an opening bracket |
bracketRight | /^\\\]/ |
] | Matches a closing bracket |
newline | /^(\\n|\\n\\r)/ |
Matches a new line or carriage return character | |
spaces | / +/ |
Matches several space characters |
WIP.
Generated by Cadey 0.0.2. View source here.