/// Visibility visibility_public = { "public" } visibility_private = { "private" } visibility = { visibility_public | visibility_private } /// Types ty_u32 = {"u32"} ty_field = {"fe"} ty_bool = {"bool"} ty_basic = { ty_u32 | ty_field | ty_bool } ty_struct = { variable } ty_array = {ty_basic ~ ("[" ~ value ~ "]")+ } ty = { ty_array | ty_basic | ty_struct } /// Values value_number = @{ "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* } value_u32 = { value_number ~ ty_u32? } value_field = { value_number ~ ty_field } value_boolean = { "true" | "false" } value = { value_field | value_boolean | value_u32 } /// Variables protected_name = { visibility | "return" } variable = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* } /// Arrays inline_array_inner = _{(expression_term ~ ("," ~ NEWLINE* ~ expression_term)*)?} expression_array_inline = { "[" ~ NEWLINE* ~ inline_array_inner ~ NEWLINE* ~ "]"} expression_array_initializer = { "[" ~ expression_term ~ ";" ~ value ~ "]" } /// Structs inline_struct_member = { variable ~ ":" ~ expression_term } inline_struct_member_list = _{(inline_struct_member ~ ("," ~ NEWLINE* ~ inline_struct_member)*)? ~ ","? } expression_inline_struct = { variable ~ "{" ~ NEWLINE* ~ inline_struct_member_list ~ NEWLINE* ~ "}" } /// Expressions expression_primitive = { value | variable } expression_term = { expression_inline_struct | expression_primitive | expression_array_inline | expression_array_initializer } /// Functions parameter = { variable ~ ":" ~ visibility? ~ ty } function_name = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* } /// Section header = { "[" ~ function_name ~ "]" } assignment = { parameter ~ "=" ~ expression_term } section = { header ~ NEWLINE+ ~ assignment* ~ NEWLINE* } /// Utilities COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!NEWLINE ~ ANY)*) } WHITESPACE = _{ " " | "\t" ~ (NEWLINE)* } /// Program File file = { SOI ~ NEWLINE* ~ section* ~ NEWLINE* ~ EOI }