grammar KoiReferenceParser rule block statement+ end rule statement space? ( hash_assignment / assignment / if / unless / function_call ) ';'? space? end rule nil "nil" end rule true "true" end rule false "false" end rule integer ('+' / '-')? [0-9]+ end rule float ('+' / '-')? [0-9]+ '.' [0-9]+ end rule string '"' ([^"\\] / "\\" . )* '"' end rule identifier '$'? [a-zA-Z] [a-zA-Z0-9_]* end rule hash_assignment identifier hash_accessor_list space? assignment_operator space? ( hash / function_definition / expression ) end rule assignment identifier space? assignment_operator space? ( hash / function_definition / expression ) end ################## # Flow control rule if 'if(' space? expression space? ')' space block space? 'end' space? end rule unless 'unless(' space? expression space? ')' space block space? 'end' space? end ################## # Functions rule function_call identifier space? '(' space? expression? space? ','? expression? space? ')' end rule function_definition 'function(' space? identifier space? ')' block space? 'end' end ################## # Whitespace rule space [\s]+ end ################## # Hashes rule hash_accessor_list hash_accessor+ end rule hash_accessor '[' expression ']' end rule hash '{' key_value_list? '}' end rule key_value_list key_value+ end rule key_value space? expression space? '=>' space? expression space? ','? end rule key space? expression space? end rule value space? expression space? end ################## # Expressions rule expression space? (hash_access / comparative / additive) end rule hash_access identifier hash_accessor_list end rule comparative additive space? (equality_operator / inequality_operator / greater_than_operator / less_than_operator) space? additive end rule additive multitive space? additive_operator space? additive / multitive end rule additive_operator addition_operator / subtraction_operator end rule multitive primary space? multitive_operator space? multitive / primary end rule multitive_operator multiplication_operator / division_operator end rule primary function_call / nil / false / true / identifier / float / integer / string / '(' space? expression space? ')' end ################## # Operators rule assignment_operator '=' end rule addition_operator '+' end rule subtraction_operator '-' end rule multiplication_operator '*' end rule division_operator '/' end rule equality_operator '==' end rule inequality_operator '!=' end rule greater_than_operator '>' end rule less_than_operator '<' end end