Syntax for Lisp.re
November 7, 2018 · View on GitHub
This grammar is displayed using a syntax similar to regular expressions.
⦅and⦆"thick parenthesis" indicate grouping, to distinguish from parenthesis that are actually part of the grammar+allows one or more of the preceeding term or group*allows zero or more of the preceeding term or group?allows zero or one of the preceeding term or group
Note that this sacrifices a bit of precision in the interest of readability. For the source of truth, read the source code :D
If you're interested, take a look at the grammar definition
Structure
Forms that are valid at the top level of a file or module
| Name | Syntax |
|---|---|
| open | (open longCap) |
| def | (def Pattern Expression) |
| defn | (defn lowerIdent FnArgs Expression*) |
| def_rec | (def-rec Pattern Expression+) |
| type | (type TypeName TypeKind+) |
| module | (module capIdent Structure+) |
| module_alias | (module-alias capIdent longCap) |
| external | (external lowerIdent CoreType string+) |
| decorator_nopayload | (@decoratorName Structure) |
| decorator | (@decoratorName Structure Structure) |
| eval | Expression |
Expression
Pattern
| Name | Syntax |
|---|---|
| ident | lowerIdent |
| interval | constant..constant |
| constant | constant |
| unit | () |
| ignored | _ |
| array | [Pattern* ⦅...Pattern⦆?] |
| tuple | (, Pattern Pattern+) |
| empty_constr | longCap |
| poly | (`capIdent Pattern+) |
| empty_poly | `capIdent |
| exception | (exception Pattern) |
| constructor | (longCap Pattern+) |
| object | {PatternObjectItem+} |
| or | (| Pattern+ ) |
ModuleExpr
| Name | Syntax |
|---|---|
| structure | (str Structure*) |
| ident | longCap |
TypeName
| Name | Syntax |
|---|---|
| vbl | (lowerIdent typeVariable+) |
| plain | lowerIdent |
TypeKind
| Name | Syntax |
|---|---|
| record | {TypeObjectItem+} |
| constructors | TypeConstructor+ |
| alias | CoreType |
TypeObjectItem
| Name | Syntax |
|---|---|
| normal | :lowerIdent CoreType |
| punned | :lowerIdent |
TypeConstructor
| Name | Syntax |
|---|---|
| no_args | capIdent |
| args | (capIdent CoreType+) |
CoreType
| Name | Syntax |
|---|---|
| constr_no_args | longIdent |
| variable | typeVariable |
| constructor | (longIdent CoreType+) |
| arrow | (=> [CoreType+] CoreType) |
typeVariable
A type variable
FnCallArg
| Name | Syntax |
|---|---|
| labeled | ~lowerIdent=Expression |
| punned | ~lowerIdent |
| expr | Expression |
ThreadItem
| Name | Syntax |
|---|---|
| attribute | :longIdent |
| ident | longIdent |
| emptyconstr | longCap |
| constructor | (longCap Expression+) |
| fn_call | (Expression FnCallArg+) |
ObjectItem
| Name | Syntax |
|---|---|
| normal | :longIdent Expression |
| punned | :longIdent |
FnArgs
| Name | Syntax |
|---|---|
| single | lowerIdent |
| unit | () |
| ignored | _ |
| multiple | [FnArg+] |
FnArg
| Name | Syntax |
|---|---|
| destructured | ~lowerIdent⦅:CoreType⦆? as Pattern |
| optional | ~lowerIdent=? |
| defaulted | ~lowerIdent⦅:CoreType⦆?=Expression |
| labeled | ~lowerIdent⦅:CoreType⦆? |
| unlabeled | Pattern |
PatternObjectItem
| Name | Syntax |
|---|---|
| normal | :longIdent Pattern |
| punned | :longIdent |
longIdent
A potentially-namespaced lower-case identifier
longCap
A potentially-namespaced capital identifier
longCap_
| Name | Syntax |
|---|---|
| dot | longCap_.capIdent |
| lident | capIdent |
decoratorChar_
| Name | Syntax |
|---|---|
identchar | |
. | |
+ | |
~ |
constant
| Name | Syntax |
|---|---|
| float | float |
| int | int64 |
| string | string |
| longString | longString |
| char | char |
capIdent
A simple identifier starting with a capital letter
A…Zidentchar*
lowerIdent
A simple identifier starting with a lower-case letter
a…zidentchar*
identchar
| Name | Syntax |
|---|---|
alpha | |
0…9 | |
_ |
int64
An int constant
0…9+
float
A float constant
0…9+.0…9+
string
A string constant
"strchar*"
strchar
| Name | Syntax |
|---|---|
\any | |
any |
longString
Note: This doesn't yet support arbitrary heredoc delimiters. Just {| and |}
{|⦅any⦆*|}
char
A char constant
'charchar'
charchar
| Name | Syntax |
|---|---|
\any | |
any |
reserved
| Name | Syntax |
|---|---|
fun | |
let | |
and | |
as | |
type | |
switch | |
exception | |
external | |
of | |
module | |
rec | |
open | |
import | |
try | |
catch | |
from |
alpha
| Name | Syntax |
|---|---|
a…z | |
A…Z |
operator
An operator
reservedOps
| Name | Syntax |
|---|---|
=> | |
-> | |
->> | |
... |
opChar
| Name | Syntax |
|---|---|
! | |
$ | |
% | |
& | |
* | |
+ | |
- | |
. | |
/ | |
< | |
= | |
> | |
? | |
@ | |
^ | |
| | |
~ |