[wgsl] remove Pest grammar

This commit is contained in:
Dzmitry Malyshau
2020-03-10 22:08:56 -04:00
committed by Dzmitry Malyshau
parent 93d60ce8bf
commit ee8e0699be

View File

@@ -1,189 +0,0 @@
translation_unit = _{ SOI ~ global_decl* ~ EOI }
global_decl = {
";"
| import_decl ~ ";"
| global_variable_decl ~ ";"
| global_constant_decl ~ ";"
| entry_point_decl ~ ";"
| type_alias ~ ";"
| function_decl
}
import_decl = { "import" ~ string_literal ~ "as" ~ (ident ~ "::")* ~ ident}
global_variable_decl = {
variable_decoration_list ~ variable_decl
| variable_decoration_list ~ variable_decl ~ "=" ~ const_expr
}
global_constant_decl = { "const" ~ variable_ident_decl ~ "=" ~ const_expr }
variable_decoration_list = { "[[" ~ (variable_decoration ~ ",")* ~ variable_decoration ~ "]]" }
variable_decoration = _{
"location" ~ location_decoration
| "builtin" ~ builtin_decoration
// | BUILTIN builtin_decoration
// | BINDING INT_LITERAL
// | SET INT_LITERAL
}
location_decoration = { int_literal }
builtin_decoration = {
"position"
| "vertex_idx"
}
variable_decl = { "var" ~ variable_storage_decoration? ~ variable_ident_decl }
variable_storage_decoration = _{ "<" ~ storage_class ~ ">" }
variable_ident_decl = { ident ~ ":" ~ type_decl }
type_alias = {
"type" ~ ident ~ "=" ~ type_decl
| "type" ~ ident ~ "=" ~ struct_decl
}
struct_decl = { struct_decoration_decl? ~ "struct" ~ struct_body_decl }
struct_decoration_decl = { "[[" ~ struct_decoration ~ "]]" }
struct_decoration = {
"block"
}
struct_body_decl = { "{" ~ struct_member* ~ "}" }
struct_member = { struct_member_decoration_decl? ~ variable_ident_decl ~ ";" }
struct_member_decoration_decl = { "[[" ~ (struct_member_decoration ~ ",")* ~ struct_member_decoration ~ "]]" }
struct_member_decoration = {
"offset" ~ uint_literal
}
function_decl = { function_header ~ body_stmt }
function_header = { "fn" ~ ident ~ "(" ~ param_list ~ ")" ~ "->" ~ function_type_decl }
function_type_decl = _{ "void" | type_decl }
param_list = { (variable_ident_decl ~ ",")* ~ variable_ident_decl | "" }
body_stmt = { "{" ~ statement* ~ "}" }
entry_point_decl = {
"entry_point" ~ pipeline_stage ~ ("as" ~ string_literal)? ~ "=" ~ ident
}
pipeline_stage = {
"vertex"
| "fragment"
| "compute"
}
storage_class = {
"in"
| "out"
| "uniform"
// | WORKGROUP
// | UNIFORM_CONSTANT
| "storage_buffer"
// | IMAGE
| "private"
| "function"
}
const_literal = {
bool_literal
| float_literal
| int_literal
| uint_literal
}
const_expr = {
const_literal
| type_decl ~ "(" ~ (const_expr ~ ",")? ~ const_expr ~ ")"
}
type_pointer_kind = { "ptr" }
type_array_kind = { "array" }
type_vec_kind = { "vec2" | "vec3" | "vec4" }
type_mat_kind = { "mat2x2" | "mat3x3" | "mat4x4" }
type_decl = {
scalar_type
| type_vec_kind ~ "<" ~ type_decl ~ ">"
| type_pointer_kind ~ "<" ~ storage_class ~ "," ~ type_decl ~ ">"
| type_array_kind ~ "<" ~ type_decl ~ "," ~ uint_literal ~ ">"
| type_array_kind ~ "<" ~ type_decl ~ ">"
| type_mat_kind ~ "<" ~ type_decl ~ ">"
| ident
}
scalar_type = {
"bool"
| "f32"
| "i32"
| "u32"
}
return_statement = { "return" ~ logical_or_expression? }
assignment_statement = { ident ~ "=" ~ logical_or_expression }
statement = {
";"
| return_statement ~ ";"
// | if_stmt
// | unless_stmt
// | regardless_stmt
// | switch_stmt
// | loop_stmt
| variable_statement ~ ";"
// | break_stmt ~ ";"
// | continue_stmt ~ ";"
// | KILL ~ ";"
// | NOP ~ ";"
| assignment_statement ~ ";"
}
variable_statement = _{
variable_decl ~ "=" ~ logical_or_expression
| "const" ~ variable_ident_decl ~ "=" ~ logical_or_expression
| variable_decl
}
primary_expression = _{
typed_expression
| const_expr
| paren_rhs_stmt
| ident
}
unary_expression = _{
primary_expression
}
multiplicative_expression = { unary_expression ~ ("*" ~ unary_expression)* }
additive_expression = { multiplicative_expression ~ ("+" ~ multiplicative_expression)* }
shift_expression = _{
additive_expression
}
relational_expression = _{
shift_expression
}
equality_expression = { relational_expression ~ ("==" ~ relational_expression)* }
and_expression = { equality_expression ~ ("&" ~ equality_expression)* }
exclusive_or_expression = { and_expression ~ ("^" ~ and_expression)* }
inclusive_or_expression = { exclusive_or_expression ~ ("|" ~ exclusive_or_expression)* }
logical_and_expression = { inclusive_or_expression ~ ("&&" ~ inclusive_or_expression)* }
logical_or_expression = { logical_and_expression ~ ("||" ~ logical_and_expression)* }
paren_rhs_stmt = _{ "(" ~ logical_or_expression ~ ")" }
typed_expression = { type_decl ~ "(" ~ argument_expression_list ~ ")" }
argument_expression_list = _{ (logical_or_expression ~ ",")* ~ logical_or_expression }
ident = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
int_literal = @{ ("-"? ~ "0x" ~ ASCII_HEX_DIGIT+) | "0" | ("-"? ~ ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*) }
uint_literal = @{ ("0x" ~ ASCII_HEX_DIGIT+) | "0" | (ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*) }
float_literal = @{ "-"? ~ ASCII_DIGIT+ ~ ("." ~ ASCII_DIGIT*)? }
bool_literal = @{ "true" | "false" }
string_literal = @{ "\"" ~ ( "\"\"" | (!"\"" ~ ANY) )* ~ "\"" }
WHITESPACE = _{ " " | "\t" | NEWLINE }
COMMENT = _{ "#" ~ (!NEWLINE ~ ANY)* }