module Canql

grammar EBaseRecords
  rule action_or_ebr
    and_keyword? action_and_ebr / all_or_none_actions / actions / e_base_records / processing_date
  end

  rule action_and_ebr
    actions and_keyword e_base_records processing_date? processing_registry?
  end

  rule e_base_records
    unprocessed_keyword types:batch_types? processing_registry? records_keyword <Nodes::EBaseRecordsNode>
  end

  rule batch_types
    space allowed_types word_break <Nodes::BatchTypesNode>
  end

  rule allowed_types
    batch_type types:more_types* <Nodes::AllowedTypesNode>
  end

  rule more_types
    ','? space? ('or' space)? batch_type <Nodes::MoreTypesNode>
  end

  rule processing_date
    space processing_date_keyword fuzzy_date <Nodes::ProcessingDateNode>
  end

  rule processing_date_keyword
    'dated' ' for processing'?
  end

  rule with_keyword
    space 'with' word_break
  end

  rule actions
    action_type action_keyword action_provider? <Nodes::ActionsNode>
  end

  rule action_provider
    space 'at' space provider:(action_provider_code / action_provider_name)
  end

  rule action_type
    space accepted_action word_break
  end

  rule accepted_action
    'coding_clinic' / 'coding_group' / 'complete' / 'qa' / 'reg_group' /
    'scr_checked' / 'scr_check' / 'search' / 'technical'
  end

  rule all_or_none_actions
    all_or_none_action_type action_keyword <Nodes::AllOrNoneActionsNode>
  end

  rule all_or_none_action_type
    space all_or_none_action word_break
  end

  rule all_or_none_action
    'no outstanding' / 'an outstanding'
  end

  rule action_keyword
    space 'action' 's'? word_break
  end

  rule action_provider_code
    provider_code <Nodes::ActionProviderCodeNode>
  end

  rule action_provider_name
    provider_name <Nodes::ActionProviderNameNode>
  end

  rule unprocessed_keyword
    space 'unprocessed' word_break
  end

  rule records_keyword
    space 'records' word_break
  end

  rule and_keyword
    space 'and' word_break
  end
end

end