Skip to content

Instantly share code, notes, and snippets.

@acarabott
Created March 4, 2025 16:32
Show Gist options
  • Save acarabott/6041e0a1b7fa45c7a6d61ee0c7d79f68 to your computer and use it in GitHub Desktop.
Save acarabott/6041e0a1b7fa45c7a6d61ee0c7d79f68 to your computer and use it in GitHub Desktop.
Protocol {
Item =
| Constant
| Model
| Enum
Property = ident ":" Type
Model = "model" ident "{" ListOf<Property, ";"> "}"
Constant =
| GenericConstant<ArrayType, Array>
| GenericConstant<EnumName, EnumValue>
| GenericConstant<StringType, string>
| GenericConstant<NumberType, number>
| GenericConstant<BooleanType, boolean>
GenericConstant<T, E> = "const" Property "=" E ";"
Type =
| RecordType
| ArrayType
| EnumName
| NumberType
| StringType
| BooleanType
RecordType = Type "{}"
ArrayType = Type "[]"
StringType = "string"
BooleanType = "boolean"
Array = "[" ListOf<primitive, ","> "]"
Enum = "enum" EnumName "{" ListOf<ident, ","> "};"
EnumValue = EnumName "." ident
EnumName = upper+ alnum*
NumberType =
| "i8" | "u8"
| "i16" | "u16"
| "i32" | "u32"
| "i64" | "u64"
| "f32" | "f64"
ident (an identifier)
= letter alnum*
primitive =
| number
| string
| boolean
boolean = "true" | "false"
string //TODO use string definition from es5 grammar
= "\"" alnum* "\""
number
= digit* "." digit+ -- decimal
| digit+ -- integer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment