dinoco_compiler 0.0.5

The Dinoco schema compiler for parsing, validating, and analyzing database schemas.
Documentation
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
INLINE_WHITESPACE = _{ " " | "\t" }

NEWLINE = { "\n" | "\r\n" | "\r" }
COMMENT = { "#" ~ (!NEWLINE ~ ANY)* }

model_keyword = { "model" }
enum_keyword = { "enum" }
config_keyword = { "config" }

block_open = { "{" }
block_close = { "}" }
paren_open = { "(" }
paren_close = { ")" }
array_open = { "[" }
array_close = { "]" }
decorator_prefix = { "@" }
model_decorator_prefix = { "@@" }
array_separator = { "," }
named_separator = { ":" }
config_separator = { "=" }
field_optional = { "?" }

ident = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
inner_string = @{ (!"\"" ~ ANY)* }

number_literal = @{ ASCII_DIGIT+ ~ ("." ~ ASCII_DIGIT+)? }
string_literal = ${ "\"" ~ inner_string ~ "\"" }
boolean_literal = { "true" | "false" }

function = { ident ~ paren_open ~ param? ~ paren_close }
decorator = { 
    decorator_prefix ~ ident ~ 
    (paren_open ~ INLINE_WHITESPACE* ~ ((named_param | param) ~ (array_separator ~ INLINE_WHITESPACE*  ~ (named_param | param))*)? ~ INLINE_WHITESPACE* ~ paren_close)? ~ INLINE_WHITESPACE*
}
model_decorator = ${
    INLINE_WHITESPACE* ~ model_decorator_prefix ~ ident ~
    (paren_open ~ INLINE_WHITESPACE* ~ ((named_param | param) ~ (array_separator ~ INLINE_WHITESPACE* ~ (named_param | param))*)? ~ INLINE_WHITESPACE* ~ paren_close)? ~
    INLINE_WHITESPACE* ~ COMMENT* ~ NEWLINE*
}

named_array = { array_open ~ INLINE_WHITESPACE* ~ ident ~ INLINE_WHITESPACE* ~  (array_separator ~ INLINE_WHITESPACE* ~ ident)* ~ array_close }
named_value = { named_array | ident | string_literal }
named_param = { ident ~ named_separator ~ INLINE_WHITESPACE* ~ named_value }

decorator_array = { array_open ~ INLINE_WHITESPACE* ~ ident ~ INLINE_WHITESPACE* ~ (array_separator ~ INLINE_WHITESPACE* ~ ident)* ~ INLINE_WHITESPACE* ~ array_close }
param = { function | string_literal | boolean_literal | number_literal | ident | decorator_array | COMMENT }

config_array = { array_open ~ (config_array_value ~ (array_separator ~ config_array_value?)*)? ~ array_close }
config_array_value = { string_literal | function | config_object | config_field | COMMENT }

config_object = { block_open ~ config_field* ~ block_close }
config_param = { config_array | config_object | function | string_literal | config_field } 
config_field = { ident ~ config_separator ~ config_param }

field_type = @{ ident }
// field = { ident ~ field_type ~ (array_open ~ array_close)? ~ field_optional? ~ decorator* }

field = ${ ident ~ INLINE_WHITESPACE* ~ field_type ~ (array_open ~ array_close)? ~ field_optional? ~ (INLINE_WHITESPACE* ~ decorator)* ~ COMMENT* ~ NEWLINE* }

model_block = { model_keyword ~ INLINE_WHITESPACE* ~ ident ~ INLINE_WHITESPACE* ~ block_open ~ (field | model_decorator | COMMENT)* ~ block_close }
enum_block = ${ enum_keyword ~ INLINE_WHITESPACE* ~ ident ~ INLINE_WHITESPACE* ~ block_open ~ WHITESPACE* ~ (ident | COMMENT | WHITESPACE)* ~ WHITESPACE* ~ block_close }
config_block = { config_keyword ~ block_open ~ (config_field | COMMENT)* ~ block_close }

schema = { SOI ~ (model_block | enum_block | config_block | COMMENT)* ~ EOI }