require 'parslet' module Shift module Parser include Parslet rule(:cud_keyword) { new_keyword | all_keyword | update_keyword | delete_keyword } rule(:cud_query) { cud_keyword.as(:operation) >> space >> identifier.as(:model_name) } rule(:find_by_id_query) { find_by_id_keyword.as(:operation) >> space >> identifier.as(:model_name) >> variables.as(:item_id) } rule(:find_condition) { space? >> identifier.as(:attribute) >> space? >> query_find_operator.as(:operator) >> space? >> value_returning_expression.as(:value) >> space?} rule(:find_query) { find_keyword.as(:operation) >> space >> identifier.as(:model_name) >> space >> where_keyword >> find_condition.as(:condition) >> (space? >> comma >> space? >> find_condition.as(:condition)).repeat(0) } rule(:query) { find_query.as(:query) | find_by_id_query.as(:query) | cud_query.as(:query) } end end