Skip to content

Instantly share code, notes, and snippets.

@andreivasiliu
Created September 3, 2019 10:55
Show Gist options
  • Save andreivasiliu/fa0ab142124eee36bb0cf71ef7d99336 to your computer and use it in GitHub Desktop.
Save andreivasiliu/fa0ab142124eee36bb0cf71ef7d99336 to your computer and use it in GitHub Desktop.
# Partial Pest variant of https://github.com/andreivasiliu/TinyRaytracerInD/blob/06063dbf20036970b3446ae97a044570035f5872/src/sceneparser/GrammarConstants.d
alpha = { 'a'..'z' | 'A'..'Z' }
digit = { '0'..'9' }
ident = { alpha ~ (alpha | digit)* }
ident_list = _{ ident ~ (" " ~ ident)* }
start = { statement+ }
statement = { command ~ "(" ~ param_list ~ ")" }
statement = { id ~ "=" ~ object }
command = { "draw" | "display" }
param_list = { object ~ ("," ~ object)* }
object = { expression | string_literal | (obj_name ~ "(" ~ param_list ~ ")") }
obj_name = { "sphere" | "plane" | "csg" | "cube" }
string_literal = { "\"" ~ ('a'..'z' | 'A'..'Z' | '0'..'9' | " ") ~ "\"" }
expression = { (expression ~ ("+" | "-"))? ~ mult_expression }
mult_expression = { (mult_expression ~ ("*" | "/" | "%"))? ~ neg_expression }
neg_expression = { "-"? ~ value }
value = { id | number_literal | color | vector | ("(" ~ expression ~ ")") }
id = { ident }
color = { "red" | "orange" | "yellow" | "green" | "blue" | "purple" | "black" | "white" }
vector = { "<" ~ expression ~ "," ~ expression ~ "," ~ expression ~ ">" }
number_literal = { digit+ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment