# -*- coding: utf-8 -*- #
# frozen_string_literal: true

require_relative "../task_helper"

SQF_KEYWORDS_FILE = "./lib/rouge/lexers/sqf/keywords.rb"

namespace :builtins do
  task :sqf do
    SQFBuiltins.process(SQF_KEYWORDS_FILE)
  end
end

class SQFBuiltins < BuiltinsGenerator
  SQF_SYNTAX_URI = "https://raw.githubusercontent.com/intercept/intercept/master/src/client/headers/client/sqf_assignments.hpp"

  def fetch
    URI.open(SQF_SYNTAX_URI) { |f| f.read }
  end

  def parse
    @input.scrub.scan(/(?<=\(").+?(?=")/).sort.uniq
  end

  def generate
    yield "# -*- coding: utf-8 -*- #"
    yield "# frozen_string_literal: true"
    yield ""
    yield "# DO NOT EDIT"
    yield "# This file is automatically generated by `rake builtins:sqf`."
    yield "# See tasks/builtins/sqf.rake for more info."
    yield ""
    yield "module Rouge"
    yield "  module Lexers"
    yield "    class SQF"
    yield "      COMMANDS = Set.new #{@keywords.inspect}"
    yield "    end"
    yield "  end"
    yield "end"
  end
end
